Example #1
0
        public GameInfo SwitchNext()
        {
            Players newPlayers = players.SwitchNext();

            return(new GameInfo(newPlayers, this.isActiveGame));
        }
Example #2
0
        public void AddPlayers()
        {
            Players players = new Players();

            players.ShowDialog();
        }
Example #3
0
 public GameInfo(Players players, Boolean isActiveGame)
 {
     this.players      = players;
     this.isActiveGame = isActiveGame;
 }
Example #4
0
        /// Method that start the game.

        public void Play()
        {
            // change colors
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.White;
            Console.Clear();
            //call method that show the welcome
            Welcome();

            // call method that take name of playes
            TakePlayerNames();

            // Loop excute until the game is finished
            BoardItem?winnerBoardItem;

            while (!board.GameFinished(out winnerBoardItem))
            {
                Console.Clear();
                //call method that show welcome screen
                Welcome();
                //call method that show the board.
                ShowBoard();
                ShowPositions();
                Console.SetCursorPosition(0, 8);

                //take player to play
                Players activePlayer = PlayerToPlay();
                Console.WriteLine("");
                Console.ForegroundColor = activePlayer.Color;
                Console.WriteLine("Player of the time: {0}", activePlayer.Name);

                while (true)
                {
                    // ask about the move.
                    Console.Write("\nEnter the move: ");
                    string play = Console.ReadLine();

                    try
                    {
                        // execute the move
                        RunMove(play, activePlayer);
                        break;
                    }
                    catch (PlayException e)
                    {
                        Console.WriteLine("Error: {0}", e.Message);
                    }
                }
            }

            Console.Clear();

            // call the method that show how the board finished.
            ShowBoard();

            Console.WriteLine("The game is over!\n");

            Players winnerPlayer = null;

            if (winnerBoardItem != null)
            {
                // if winnerBoardItem different of null, someone win
                if (players[0].BoardItem == winnerBoardItem)
                {
                    // player 1 win.
                    winnerPlayer = players[0];
                }
                else
                {
                    // player 2 win.
                    winnerPlayer = players[1];
                }

                Console.WriteLine("The winner is the player {0}! Congratulations!", winnerPlayer.Name);
            }
            else
            {
                // if winnerBoardItem equals null, nobody win.
                Console.WriteLine("There was not a winner this time!");
            }
            Console.ReadLine();
        }