static void Main(string[] args) { board b = new board(); player human = new player(); player comp = new player(false); Console.WriteLine("************************* "); Console.WriteLine(" Welcome to my Tic-Tac-Toe!"); Console.WriteLine("*************************"); Console.WriteLine("Please enter the column and then row of your move(Example : A1,B2,C3)"); b.printBoard(); while (true) { //human player move ; while (true) { string move = human.getPlayerMove(b.getBoard()); if (b.isMoveValid(move) == true) { if (b.submitMove(move, 'X')) { b.printBoard(); break; } Console.WriteLine("The space entered is already taken."); } else { Console.WriteLine("Invalid Input: Please enter the column and row of your move (Example: A1)."); } } if (b.isWinner('X')) { Console.WriteLine("You win !!"); break; } else if (b.isTie()) { Console.WriteLine("Gome Over ,Draw"); break; } //computer move Console.Write("Player Move (O): "); while (true) { string move = comp.getPlayerMove(b.getBoard()); if (b.isMoveValid(move)) { if (b.submitMove(move, 'O')) { Console.WriteLine("{0}", move.ToString()); b.printBoard(); break; } } } if (b.isWinner('O')) { Console.WriteLine("You Lose!!"); break; } } }
public string getHumanMove() { board check = new board(); start: Console.Write("Player move (" + this.marker + ") : "); this.currentMove = Console.ReadLine(); Console.WriteLine(""); if (check.isMoveValid(this.currentMove)) { return this.currentMove; } else { Console.WriteLine("Invalid Input: Please enter the column and row of your move (Example: A1)."); goto start; } }