Esempio n. 1
0
        /// <summary>Prompts a human player to be Xs or Os.</summary>
        /// <param name="a"></param>
        private void ChooseSides(CircularList a)
        {
            char c;

            do
            {
                Console.Write("Do you want to start as Xs or Os? ");
                c = Char.ToLower(Convert.ToChar(Console.ReadLine()));
            } while (c != 'x' && c != 'o');

            if (c == 'o')
            {
                Human hum = new Human(Piece.PieceValue.O);
                hum.MoveMethod = new Player.ChooseMove(Game.PromptForMove);
                Computer comp = new Computer(Piece.PieceValue.X);
                // insert into the player's list
                a.Add(hum);
                a.Add(comp);
            }
            else
            {
                Computer comp = new Computer(Piece.PieceValue.O);
                Human    hum  = new Human(Piece.PieceValue.X);
                hum.MoveMethod = new Player.ChooseMove(Game.PromptForMove);
                // insert into the player's list
                a.Add(comp);
                a.Add(hum);
            }
        }
Esempio n. 2
0
        /// <summary>Initializes the players array.</summary>
        /// <param name="a"></param>
        private void InitPlayers(CircularList a)
        {
            byte n = 0;

            do
            {
                Console.Write("How many human players [0|1|2]? ");
                n = Convert.ToByte(Console.ReadLine());
            } while (n < 0 || n > 2);

            switch (n)
            {
            case 1:
                this.ChooseSides(a);
                break;

            case 2:
                // create human players
                Human human1 = new Human(Piece.PieceValue.O);
                human1.MoveMethod = new Player.ChooseMove(Game.PromptForMove);
                Human human2 = new Human(Piece.PieceValue.X);
                human2.MoveMethod = new Player.ChooseMove(Game.PromptForMove);

                // insert into the player's list
                a.Add(human1);
                a.Add(human2);
                break;

            case 0:
            default:
                // create computer players
                Computer comp1 = new Computer(Piece.PieceValue.O);
                Computer comp2 = new Computer(Piece.PieceValue.X);
                // set their skill level
                // insert into the player's list
                a.Add(comp1);
                a.Add(comp2);
                break;
            }
        }