From b028b86f5242686697b998df702d17d25e629b25 Mon Sep 17 00:00:00 2001 From: Jbanksalpha <78812718+Jbanksalpha@users.noreply.github.com> Date: Fri, 5 Mar 2021 17:10:33 -0500 Subject: [PATCH] finished and tested tic tac toe --- .../zipcodewilmington/tictactoe/Board.java | 65 +++++++++++++++++-- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/src/main/java/rocks/zipcodewilmington/tictactoe/Board.java b/src/main/java/rocks/zipcodewilmington/tictactoe/Board.java index f56452f..f5ae9e7 100644 --- a/src/main/java/rocks/zipcodewilmington/tictactoe/Board.java +++ b/src/main/java/rocks/zipcodewilmington/tictactoe/Board.java @@ -3,24 +3,81 @@ /** * @author leon on 6/22/18. */ + + public class Board { + + Character[][] playerChoice; public Board(Character[][] matrix) { + playerChoice = matrix; + } public Boolean isInFavorOfX() { - return null; + if (playerChoice[0][0]== 'X' && playerChoice[0][1] == 'X' && playerChoice[0][2] == 'X'){ + return true; + } else if (playerChoice[1][0] == 'X' && playerChoice[1][1] == 'X' && playerChoice[1][2] == 'X') { + return true; + } else if (playerChoice[2][0] == 'X' && playerChoice[2][1] == 'X' && playerChoice[2][2] == 'X') { + return true; + } else if (playerChoice[0][0] == 'X' && playerChoice[1][0] == 'X' && playerChoice[2][0] == 'X') { + return true; + } else if (playerChoice[0][1] == 'X' && playerChoice[1][1] == 'X' && playerChoice[2][1] == 'X') { + return true; + } else if (playerChoice[0][2] == 'X' && playerChoice[1][2] == 'X' && playerChoice[2][2] == 'X') { + return true; + } else if (playerChoice[0][0] == 'X' && playerChoice[1][1] == 'X' && playerChoice[2][2] == 'X') { + return true; + } else if (playerChoice[0][2] == 'X' && playerChoice[1][1] == 'X' && playerChoice[2][0] == 'X'){ + return true; + } else { + return false; + } + + + } public Boolean isInFavorOfO() { - return null; + if (playerChoice[0][0] == 'O' && playerChoice[0][1] == 'O' && playerChoice[0][2] == 'O') { + return true; + } else if (playerChoice[1][0] == 'O' && playerChoice[1][1] == 'O' && playerChoice[1][2] == 'O') { + return true; + } else if (playerChoice[2][0] == 'O' && playerChoice[2][1] == 'O' && playerChoice[2][2] == 'O') { + return true; + } else if (playerChoice[0][0] == 'O' && playerChoice[1][0] == 'O' && playerChoice[2][0] == 'O') { + return true; + } else if (playerChoice[0][1] == 'O' && playerChoice[1][1] == 'O' && playerChoice[2][1] == 'O') { + return true; + } else if (playerChoice[0][2] == 'O' && playerChoice[1][2] == 'O' && playerChoice[2][2] == 'O') { + return true; + } else if (playerChoice[0][0] == 'O' && playerChoice[1][1] == 'O' && playerChoice[2][2] == 'O') { + return true; + } else if (playerChoice[0][2] == 'O' && playerChoice[1][1] == 'O' && playerChoice[2][0] == 'O'){ + return true; + } else { + return false; + } + + } public Boolean isTie() { - return null; + if (isInFavorOfO() == isInFavorOfX()) { + return true; + } else { + return false; + } } public String getWinner() { - return null; + if (this.isInFavorOfO()) { + return "O"; + } else if (this.isInFavorOfX()) { + return "X"; + }else { + return ""; + } } }