//The method runs the multi-player game
        private static void multiPlayer(ref char[,] io_multiGameBoard, ref PlayerDetails io_p1, ref PlayerDetails io_p2)
        {
            m_NumOfTurns = 0;

            Console.WriteLine("\n{0} begins, follow the orders in every level\n" +
                              "to quit at any point press 'Q', " +
                              "press 'Enter to start the game!'\n", io_p1.m_Name);
            Console.ReadKey();
            Screen.Clear();

            m_GameRunning = true;

            while (m_GameRunning && m_NumOfTurns != io_multiGameBoard.Length)
            {
                drawTable(io_multiGameBoard); //draws the table
                m_GameRunning = playerInput(m_Symbols[m_NumOfTurns % 2], io_multiGameBoard,
                                            (m_NumOfTurns % 2 == 0) ? io_p1 : io_p2);

                if (!m_GameRunning)
                {
                    Screen.Clear();
                    Console.WriteLine("You left the game, see you soon");
                    return;
                }
                bool isPlayerLost = TicTacToeLogic.checkforStraight(io_multiGameBoard, m_Symbols[m_NumOfTurns % 2], m_NumOfTurns);

                //if player lost
                if (isPlayerLost)
                {
                    string winner = TicTacToeLogic.findWinner(ref io_p1, ref io_p2, m_Symbols[m_NumOfTurns % 2]);

                    Screen.Clear();
                    drawTable(io_multiGameBoard);
                    Console.WriteLine("\n" +
                                      "==========================\n" +
                                      "   {0} won the game\n" +
                                      "==========================", winner);
                    break;
                }

                m_NumOfTurns++;
                if (m_NumOfTurns == io_multiGameBoard.Length)
                {
                    Screen.Clear();
                    drawTable(io_multiGameBoard);
                    Console.WriteLine("\n" +
                                      "==========================\n" +
                                      "      You got draw!!\n" +
                                      "==========================");
                    break;
                }

                Screen.Clear();
            }

            displayMatchesResult(io_p1, io_p2);
        }
Beispiel #2
0
        //The method runs the single-player game
        private static void singlePlayer(ref char[,] io_singleGameBoard, ref PlayerDetails human, ref PlayerDetails comp)
        {
            m_NumOfTurns  = 0;
            m_GameRunning = true;
            Console.WriteLine("\nYou Begin, follow the orders in every level\n" +
                              "to quit at any point press 'Q', " +
                              "press 'Enter to start the game!'\n");
            Console.ReadKey();
            Screen.Clear();

            while (m_GameRunning && m_NumOfTurns != io_singleGameBoard.Length)
            {
                drawTable(io_singleGameBoard); //draws the table

                if (m_Symbols[m_NumOfTurns % 2] == human.m_PlayerSymbol)
                {
                    m_GameRunning = playerInput(human.m_PlayerSymbol, io_singleGameBoard, human);
                    if (!m_GameRunning)
                    {
                        Screen.Clear();
                        //TODO Change to call for method - chooseOption
                        Console.WriteLine("You left the game, see you soon");
                        return;
                    }
                }
                else if (m_Symbols[m_NumOfTurns % 2] == comp.m_PlayerSymbol)
                {
                    TicTacToeLogic.computerMove(ref io_singleGameBoard, comp);
                }

                bool isPlayerLost =
                    TicTacToeLogic.checkforStraight(io_singleGameBoard, m_Symbols[m_NumOfTurns % 2], m_NumOfTurns);
                if (isPlayerLost)
                {
                    TicTacToeLogic.findWinner(ref human, ref comp, m_Symbols[m_NumOfTurns % 2]);
                    m_GameRunning = false;
                    continue;
                }

                m_NumOfTurns++;
                Screen.Clear();
            }

            Screen.Clear();
            drawTable(io_singleGameBoard);
            displayResults(human, comp);
        }