public void Play()
        {
            string Q = "y";

            DisplayWelcome();
            DisplayGrid();
            do
            {
                current  = FIRST;
                theBoard = new TicTacToeLogic();
                theBoard.Reset();

                Player player1 = new Player();
                Player player2 = new Player();

                thePlayers[FIRST]  = player1;
                thePlayers[SECOND] = player2;

                //removed extra code here for the players. No longer needed.

                while (IsPlaying())
                {
                    DisplayBoardGrid();
                    thePlayers[current].MakeMove(ref theBoard);
                    NextPlayer();
                }

                DisplayBoardGrid();
                AnnounceWinner();

                Q = PlayAgain();
                if (Q != "y")
                {
                    break;
                }
            } while (true);

            Console.Clear();
            Console.WriteLine("\n\n\nThanks for playing!!");
            Console.WriteLine("\n\nPress enter to exit");
            Console.ReadLine();
        }
        public override void MakeMove(ref TicTacToeLogic aBoard)
        {
            //Uncomment the below to randomize the list of numbers
            Random r    = new Random();
            int    i    = r.Next(8);
            int    move = 0;

            //Comment out the below when randomizing the list of numbers
            //int i = 0;

            int[] nums = { 4, 0, 2, 6, 8, 1, 3, 5, 7 };  //the list of numbers

            do
            {
                //move is set to the first number of the list, then incremented at each pass
                move = nums[i];
                ++i;
            } while (!aBoard.IsLegalMove(move));
            aBoard.ReceiveMove(GetPiece(), move);
        }
Exemple #3
0
        public override void MakeMove(ref TicTacToeLogic aBoard)
        {
            int         move;
            TicTacToeUI theGame = new TicTacToeUI();

            do
            {
                theGame.AskMove(GetPiece());
                string X = Convert.ToString(Console.ReadLine());
                if (X == "")
                {
                    move = Convert.ToInt32("9");
                }
                else
                {
                    move = Convert.ToInt32(int.Parse(X));
                }
            } while (!aBoard.IsLegalMove(move));

            aBoard.ReceiveMove(GetPiece(), move);
        }