Пример #1
0
        private void computerChooseDifferentTiles()
        {
            const bool k_EnableButtons = true;

            ComputerTimer.Stop();
            MemoryBoard.MakeRevealed(FirstChoiceButton.Row, FirstChoiceButton.Col, SecondChoiceButton.Row, SecondChoiceButton.Col);
            TileButtonMatrix[FirstChoiceButton.Row, FirstChoiceButton.Col].Image       = null;
            TileButtonMatrix[SecondChoiceButton.Row, SecondChoiceButton.Col].Image     = null;
            TileButtonMatrix[FirstChoiceButton.Row, FirstChoiceButton.Col].BackColor   = BackColor;
            TileButtonMatrix[SecondChoiceButton.Row, SecondChoiceButton.Col].BackColor = BackColor;
            Turn = !Turn;
            SetCurrentPlayerName();
            enableDisableButtonsComputerTurn(k_EnableButtons);
        }
Пример #2
0
        private void IsGameWon()
        {
            MessageBoxButtons button     = MessageBoxButtons.YesNo;
            string            winnerName = string.Empty;
            string            loserName  = string.Empty;
            string            endGameMsg = string.Empty;

            if (MemoryBoard.IsGameWon())
            {
                ComputerTimer.Stop();

                if (ScorePlayer1 > ScorePlayer2)
                {
                    winnerName = Player1Name.Text.Substring(0, Player1NameLength);
                    loserName  = Player2Name.Text.Substring(0, Player2NameLength);
                    endGameMsg = string.Format("congratulations {0} you won the game with {1} pairs! {2}{3} with {4} pairs, Don't worry, maybe next time", winnerName, ScorePlayer1, Environment.NewLine, loserName, ScorePlayer2);
                }
                else if (ScorePlayer2 > ScorePlayer1)
                {
                    winnerName = Player2Name.Text.Substring(0, Player2NameLength);
                    loserName  = Player1Name.Text.Substring(0, Player1NameLength);
                    endGameMsg = string.Format("Congratulations!! {0} you won the game with {1} pairs! {2}{3} with {4} pairs, Don't worry, maybe next time", winnerName, ScorePlayer2, Environment.NewLine, loserName, ScorePlayer1);
                }
                else
                {
                    endGameMsg = string.Format("Its a tie!! {0}both of you got {1} pairs!", Environment.NewLine, ScorePlayer1);
                }

                endGameMsg = string.Format("{0}{1}Do you want to start another game?", endGameMsg, Environment.NewLine);

                DialogResult result = MessageBox.Show(endGameMsg, "Memory Game", button);

                if (result == DialogResult.Yes)
                {
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    DialogResult = DialogResult.No;
                }

                Close();
            }
        }
Пример #3
0
 private void Game_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (!saved && !isFinished)
     {
         if (MessageBox.Show("Do you want to leave the game?", "Leave Game",
                             MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
         {
             e.Cancel = true;
             return;
         }
     }
     state          = new State();
     state.Computer = computer;
     state.Player   = player;
     state.Score    = score;
     state.Turn     = Turn;
     state.Mute     = MuteClicked;
     ComputerTimer.Stop();
     ShootTimer.Stop();
 }