Example #1
0
 public GameBoardForm(int i_size, bool i_isComputerPlayer)
 {
     this.Text = k_GameTitle;
     this.FormBorderStyle = FormBorderStyle.Fixed3D;
     this.StartPosition = FormStartPosition.CenterScreen;
     this.MinimizeBox = true;
     this.MaximizeBox = true;
     m_NumOfRowsAndCol = i_size;
     m_Buttons = new CellButton[i_size, i_size];
     m_IsComputerPlayer = i_isComputerPlayer;
     m_GameLogic = new GameLogic(m_NumOfRowsAndCol, m_IsComputerPlayer);
     initializeBoard();
     UpDateGameBoard();
 }
Example #2
0
        private void CheckIfGameFinished()
        {
            bool isEndOfGame = !m_GameLogic.CurrentPlayer.HasMoves() && !m_GameLogic.OpponentPlayer.HasMoves();
            if (isEndOfGame)
            {
                string gameOverMessage = null;
                bool isCurrentPlayerBlack = m_GameLogic.CurrentPlayer.CurrentColor == eButtonColor.Black;
                m_GameLogic.CurrentPlayer.CountMySymbol(m_GameLogic.GameBoard);
                m_GameLogic.OpponentPlayer.CountMySymbol(m_GameLogic.GameBoard);

                if(m_GameLogic.CurrentPlayer.Score > m_GameLogic.OpponentPlayer.Score)
                {
                    if (isCurrentPlayerBlack)
                    {
                        s_NumOfBlackPlayerWins++;
                    }
                    else
                    {
                        s_NumOfWhitePlayerWins++;
                    }

                    gameOverMessage = string.Format("{0} won!!! ({1}/{2}) ({3}/{4}) {5}{6}", m_GameLogic.CurrentPlayer.Name, m_GameLogic.CurrentPlayer.Score, m_GameLogic.OpponentPlayer.Score, s_NumOfWhitePlayerWins, s_NumOfBlackPlayerWins, Environment.NewLine, k_AnotherRound);
                }

                if (m_GameLogic.CurrentPlayer.Score < m_GameLogic.OpponentPlayer.Score)
                {
                    if (isCurrentPlayerBlack)
                    {
                        s_NumOfWhitePlayerWins++;
                    }
                    else
                    {
                        s_NumOfBlackPlayerWins++;
                    }

                    gameOverMessage = string.Format("{0} won!!! ({1}/{2}) ({3}/{4}) {5}{6}", m_GameLogic.OpponentPlayer.Name, m_GameLogic.OpponentPlayer.Score, m_GameLogic.CurrentPlayer.Score, s_NumOfWhitePlayerWins, s_NumOfBlackPlayerWins, Environment.NewLine, k_AnotherRound);
                }

                if (m_GameLogic.CurrentPlayer.Score == m_GameLogic.OpponentPlayer.Score)
                {
                    gameOverMessage = string.Format("Teko!!! ({0}/{1}) ({3}/{4}) {5}{6}", m_GameLogic.OpponentPlayer.Score, m_GameLogic.CurrentPlayer.Score, s_NumOfWhitePlayerWins, s_NumOfBlackPlayerWins, Environment.NewLine, k_AnotherRound);
                }

                if (MessageBox.Show(gameOverMessage, "Othello", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    m_GameLogic = new GameLogic(m_NumOfRowsAndCol, m_IsComputerPlayer);
                    UpDateGameBoard();
                }
                else
                {
                    this.Close();
                }
            }
        }