//Checks if the Top Row contains public Boolean CheckTopRow(BoardGame board) { if (board.GetPositionState(1) == board.GetPositionState(2) && board.GetPositionState(1) == board.GetPositionState(3)) { return(true); } return(false); }
//Checks if the Right Column contains three down public Boolean CheckRightColumn(BoardGame board) { if (board.GetPositionState(3) == board.GetPositionState(6) && board.GetPositionState(3) == board.GetPositionState(9)) { return(true); } return(false); }
//Checks if the Right to Left Diagonal contains three across public Boolean CheckRtLDiagonal(BoardGame board) { if (board.GetPositionState(3) == board.GetPositionState(5) && board.GetPositionState(3) == board.GetPositionState(7)) { return(true); } return(false); }
//Checks if the Middle Column contains three down public Boolean CheckMiddleColumn(BoardGame board) { if (board.GetPositionState(2) == board.GetPositionState(5) && board.GetPositionState(2) == board.GetPositionState(8)) { return(true); } return(false); }
//Checks if the Left Column contains three down public Boolean CheckLeftColumn(BoardGame board) { if (board.GetPositionState(1) == board.GetPositionState(4) && board.GetPositionState(1) == board.GetPositionState(7)) { return(true); } return(false); }
//Checks if the Bottom row contains three across public Boolean CheckBottomRow(BoardGame board) { if (board.GetPositionState(7) == board.GetPositionState(8) && board.GetPositionState(7) == board.GetPositionState(9)) { return(true); } return(false); }
//Checks if the Middle row contains three across public Boolean CheckMiddleRow(BoardGame board) { if (board.GetPositionState(4) == board.GetPositionState(5) && board.GetPositionState(4) == board.GetPositionState(6)) { return(true); } return(false); }
public void EnterInput() { while (validInput != true) { input = Console.ReadLine(); validInput = Int32.TryParse(input, out position); // if true then it will be be send as position if ((position < 1) || (position > 9) || (theBoard.GetPositionState(position) != CurrentStateOnBoard.Empty)) { Console.WriteLine("Invalid, Re-enter move"); input = Console.ReadLine(); validInput = Int32.TryParse(input, out position); } } // reset validInput back to false or else it will never ask user for input again validInput = false; }
public void DisplayCurrentBoard() { // Get all characters to be displayed on Board char[] spaceOnBoard = new char[9]; for (int i = 1; i <= 9; i++) { char currentPos = IntToChar(i); //in line if (true) then a : else b -- Logic spaceOnBoard[i - 1] = (board.GetPositionState(i) == CurrentStateOnBoard.Empty) ? currentPos : GetSpace(board.GetPositionState(i)); } // Display then to screen Console.WriteLine($"{spaceOnBoard[0]} | {spaceOnBoard[1]} | {spaceOnBoard[2]}"); Console.WriteLine("__ __ __"); Console.WriteLine($"{spaceOnBoard[3]} | {spaceOnBoard[4]} | {spaceOnBoard[5]}"); Console.WriteLine("__ __ __"); Console.WriteLine($"{spaceOnBoard[6]} | {spaceOnBoard[7]} | {spaceOnBoard[8]}"); }
// Contains the logic to check who won the game public CurrentStateOnBoard CheckForWinner(int position, BoardGame board) { switch (position) { case 1: if (CheckTopRow(board) || CheckLeftColumn(board) || CheckLtRDiagonal(board)) { return(board.GetPositionState(1)); } break; case 2: if (CheckTopRow(board) || CheckMiddleColumn(board)) { return(board.GetPositionState(2)); } break; case 3: if (CheckTopRow(board) || CheckRightColumn(board) || CheckRtLDiagonal(board)) { return(board.GetPositionState(3)); } break; case 4: if (CheckMiddleRow(board) || CheckLeftColumn(board)) { return(board.GetPositionState(4)); } break; case 5: if (CheckMiddleRow(board) || CheckMiddleColumn(board) || CheckLtRDiagonal(board) || CheckRtLDiagonal(board)) { return(board.GetPositionState(5)); } break; case 6: if (CheckMiddleRow(board) || CheckRightColumn(board)) { return(board.GetPositionState(6)); } break; case 7: if (CheckBottomRow(board) || CheckLeftColumn(board) || CheckRtLDiagonal(board)) { return(board.GetPositionState(7)); } break; case 8: if (CheckBottomRow(board) || CheckMiddleColumn(board)) { return(board.GetPositionState(8)); } break; case 9: if (CheckBottomRow(board) || CheckRightColumn(board) || CheckLtRDiagonal(board)) { return(board.GetPositionState(9)); } break; default: return(CurrentStateOnBoard.Empty); } return(CurrentStateOnBoard.Empty); }