Exemplo n.º 1
0
        public void commandplayer(gameboard board)
        {
            int row;
            int column;

            int turn = 0;

            do
            {
                do
                {
                    Console.Write("{0} Enter your number(1 to 7):- ", p1name);
                    int temp = 0;
                    int.TryParse(Console.ReadLine(), out temp);
                    command1 = temp;
                    row      = (sign(command1, board.Board));
                }while (row < 0);                       // This means we need to return a positive number​
                column = Convert.ToInt32(command1) - 1; // We need to use the index number not the column number

                // Since we left the loop, that means we found the available row...
                board.Board[row, column] = 1; // And we will assign the sign of player 1
                board.myboardfunction();

                if (winner(1, row, column, board.Board))
                {
                    break;
                }

                turn++;

                do
                {
                    Console.Write("{0} Enter your number(1 to 7):- ", p2name);
                    command2 = Convert.ToInt32(Console.ReadLine());
                    row      = (sign(command2, board.Board));
                }while (row < 0);
                column = Convert.ToInt32(command2) - 1; // Get column given by player 2.

                board.Board[row, column] = 2;
                board.myboardfunction();

                if (winner(2, row, column, board.Board))
                {
                    break;
                }

                turn++;
            }while (turn < 42); //This loop will return until we call break;

            if (turn >= 42)
            {
                //game is draw
                Console.WriteLine("Game draw.");
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            string command;

            do
            {
                game mygame = new game();
                mygame.Welcome();
                mygame.PlayersInformationFunction();
                Console.WriteLine();

                gameboard myboard = new gameboard();
                myboard.myboardfunction();

                //
                mygame.commandplayer(myboard);

                Console.WriteLine("You want to play again ?('Y')");
                command = Console.ReadLine();
            } while (command == "Y" || command == "y");
        }