Beispiel #1
0
 public static void endGame()
 {
     ComputerTimer.abort();
     GameObject.Find("end of game message").GetComponent <SpriteRenderer>().enabled = false;
     GameObject.Find("turn indicator").GetComponent <SpriteRenderer>().enabled      = false;
     GameObject.Find("chess manager").GetComponent <ChessDisplayManager>().enabled  = false;
 }
Beispiel #2
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);
        }
Beispiel #3
0
        private void PicTimer_Tick(object i_Sender, EventArgs i_E)
        {
            PicTimer.Stop();

            bool enableButtons = true;

            enableDisableButtonsPvPTurn(enableButtons);
            FirstChoiceButton.Image      = null;
            SecondChoiceButton.Image     = null;
            FirstChoiceButton.BackColor  = BackColor;
            SecondChoiceButton.BackColor = BackColor;

            if (IsPvP == true && Turn == true)
            {
                enableDisableButtonsComputerTurn(!enableButtons);
                ComputerTimer.Start();
            }
        }
Beispiel #4
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();
            }
        }
Beispiel #5
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();
 }
Beispiel #6
0
 private void btnStart_Click(object sender, EventArgs e)
 {
     player.DisableCells(dgvPlayer);
     player.ShowShips(dgvPlayer);
     ComputerTimer.Start();
     System.Media.SoundPlayer song = new System.Media.SoundPlayer(Properties.Resources.start);
     song.Play();
     if (MuteClicked)
     {
         song.Stop();
     }
     else
     {
         song.Play();
     }
     GameStarted         = true;
     dgvComputer.Enabled = true;
     label1.Hide();
     btnStart.Visible     = false;
     btnRandomize.Visible = false;
     btnNewGame.Visible   = true;
 }
Beispiel #7
0
        private void ComputerTimer_Tick(object sender, EventArgs e)
        {
            label2.Text   = Turn ? "Your turn" : "Bot's turn";
            lblScore.Text = score.ToString();
            if (score < 0)
            {
                lblScore.ForeColor = Color.Red;
            }
            else if (score > 0)
            {
                lblScore.ForeColor = Color.Green;
            }
            if (!Turn)
            {
                dgvComputer.Enabled = false;
                ShootTimer.Start();
            }
            if (Turn)
            {
                dgvComputer.Enabled = true;
                ShootTimer.Stop();
            }

            if (computer.Won())
            {
                isFinished = true;

                ComputerTimer.Interval = 999999999;
                ShootTimer.Interval    = 999999999;
                ShootTimer.Stop();

                ShootTimer.Enabled    = false;
                ComputerTimer.Enabled = false;
                dgvComputer.Enabled   = false;
                ShootTimer.Enabled    = false;


                if (score > 0)
                {
                    View.InputScore form = new View.InputScore();
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        saveFile(form.winnerName, score);
                    }
                }

                ComputerTimer.Dispose();
            }
            if (player.Won())
            {
                isFinished             = true;
                ComputerTimer.Enabled  = false;
                dgvComputer.Enabled    = false;
                ComputerTimer.Interval = 999999999;
                ShootTimer.Interval    = 999999999;
                ShootTimer.Stop();
                dgvComputer.Enabled = false;
                ShootTimer.Dispose();
                ComputerTimer.Dispose();
                computer.ShowEndShips(dgvComputer);

                if (MessageBox.Show("YOU LOST! Do you want to play a new game?", "LOST", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    newGame();
                }
            }
        }