コード例 #1
0
ファイル: UI.cs プロジェクト: Shavits/C-Sharp-Ex2
        public static bool PlayMultiplayer(Board io_Board)
        {
            BoardPrinter(io_Board);
            bool gameTied     = false;
            bool continueGame = true;

            while (!gameTied)
            {
                Console.WriteLine($"It is now {Move.GetTurn()} turn");
                Move cur_move = GetPlayerMove(out continueGame);
                if (!continueGame)
                {
                    break;
                }

                while (!io_Board.UpdateBoard(cur_move))
                {
                    Console.WriteLine("Ilegal Move, please enter a new move");
                    cur_move = GetPlayerMove(out continueGame);
                    if (!continueGame)
                    {
                        break;
                    }
                }

                BoardPrinter(io_Board);
                if (io_Board.CheckLose())
                {
                    Move.eTurn winner = Move.eTurn.X;
                    if (Move.GetTurn() == Move.eTurn.X)
                    {
                        winner = Move.eTurn.O;
                    }

                    Console.WriteLine($"You lost! {winner} Wins!");
                    break;
                }

                gameTied = io_Board.CheckTie();
                Program.TurnNum++;
            }

            if (gameTied)
            {
                Console.WriteLine("The game is tied, nobody wins");
            }

            if (continueGame)
            {
                continueGame = CheckForNewGame();
            }

            return(continueGame);
        }
コード例 #2
0
        private bool CheckSeriesLose(Move.eTurn[] i_Series)
        {
            bool gameLost = true;

            Move.eTurn firstEntry = i_Series[0];

            if (firstEntry == Move.eTurn.EMPTY)
            {
                gameLost = false;
            }

            foreach (Move.eTurn entry in i_Series)
            {
                if (!entry.Equals(firstEntry))
                {
                    gameLost = false;
                }
            }

            return(gameLost);
        }
コード例 #3
0
        public bool CheckLose()
        {
            bool gameLost = false;

            // CheckRows
            for (int i = 0; i < m_BoardSize; i++)
            {
                Move.eTurn[] row = new Move.eTurn[m_BoardSize];

                for (int j = 0; j < m_BoardSize; j++)
                {
                    row[j] = m_BoardMatrix[i, j];
                }

                if (CheckSeriesLose(row))
                {
                    gameLost = true;
                }
            }

            // CheckCols
            for (int i = 0; i < m_BoardSize; i++)
            {
                Move.eTurn[] col = new Move.eTurn[m_BoardSize];

                for (int j = 0; j < m_BoardSize; j++)
                {
                    col[j] = m_BoardMatrix[j, i];
                }

                if (CheckSeriesLose(col))
                {
                    gameLost = true;
                }
            }

            // CheckDiag
            Move.eTurn[] diag1 = new Move.eTurn[m_BoardSize];

            for (int i = 0; i < m_BoardSize; i++)
            {
                diag1[i] = m_BoardMatrix[i, i];
            }

            if (CheckSeriesLose(diag1))
            {
                gameLost = true;
            }

            Move.eTurn[] diag2 = new Move.eTurn[m_BoardSize];
            for (int i = 0; i < m_BoardSize; i++)
            {
                diag2[i] = m_BoardMatrix[i, m_BoardSize - i - 1];
            }

            if (CheckSeriesLose(diag2))
            {
                gameLost = true;
            }

            return(gameLost);
        }