static void Main(string[] args) { TicTacToeGame game = new TicTacToeGame(); while (!game.IsGameOver()) { Console.Write("Enter a cell number: "); int cell = int.Parse(Console.ReadLine()); game.Move(cell); } Console.Read(); }
static int Main(string[] args) { if (args.Length != 2) { // Print help Console.WriteLine("Program: <ai/<name>> <ai/<name>>"); return(1); } Console.WriteLine("Tic Tac Toe"); Player <TicTacToeToken> playerOne = GetPlayer(args[0], TicTacToeToken.X); Player <TicTacToeToken> playerTwo = GetPlayer(args[1], TicTacToeToken.O); TicTacToeGame game = new TicTacToeGame(playerOne, playerTwo); Player <TicTacToeToken> winningPlayer; do { Move <TicTacToeToken> nextMove; do { nextMove = game.CurrentPlayer.GetNextMove(game); }while (!game.TryMove(nextMove)); Console.WriteLine($"Round #{game.RoundNumber}"); Console.WriteLine(game.ToString()); Console.WriteLine(); }while (!game.IsGameOver(out winningPlayer)); if (winningPlayer != null) { Console.Write("Winner: "); Console.WriteLine(winningPlayer.ToString()); } else { Console.WriteLine("Draw!"); } return(0); }
static void Main(string[] args) { using (var context = new TicTacToeContext(ConfigurationService.ConnectionString)) { Providers.ServiceProvider = new TicTacToeServiceProvider(context); int numberOfTimes; Console.WriteLine("Number of times"); string strNumberOfTimes = Console.ReadLine(); int.TryParse(strNumberOfTimes, out numberOfTimes); Console.WriteLine("Player 1"); IPlayer player1 = TranslateStringToPlayer(Console.ReadLine(), 0); Console.WriteLine("Player 2"); IPlayer player2 = TranslateStringToPlayer(Console.ReadLine(), 1); IPlayer winner; for (int i = 0; i < numberOfTimes; i++) { IGame game = new TicTacToeGame(player1, player2); while (!game.IsGameOver()) { game.NextPlayer(); game.Move(); } // foreach (var item in game.Moves) // { // Console.WriteLine(item); // } GameHelper.PrintMoves(game.Moves); Console.WriteLine($"Winner number: {game.Winner?.PlayerNumber}"); winner = game.Winner; foreach (IPlayer player in game.Players) { player.AfterGameFinished(game); } } } }
// Gets each players move applies it to the game board private void ProcessPlayerMoves() { while (!game.IsGameOver()) { for (int i = 0; i < players.Count; i++) { Player p = players[i]; TicTacToeMove playerMove = GetMoveForPlayer(p); game.MakeMove(new TicTacToeMove(playerMove.Position, p.PlayerPiece)); // update the graphics this.ticTacToePanel.Invalidate(); if (IsGameOver()) { ShowEndOfGameMessage(players[i]); FinishGame(); } } } }