Esempio n. 1
0
        private void MainForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                return;
            }
            if (!model.IsGameOver())
            {
                switch (e.KeyCode)
                {
                case Keys.Up:
                    SoundPlay();
                    model.Up();
                    break;

                case Keys.Down:
                    SoundPlay();
                    model.Down();
                    break;

                case Keys.Left:
                    SoundPlay();
                    model.Left();
                    break;

                case Keys.Right:
                    SoundPlay();
                    model.Right();
                    break;

                default:
                    break;
                }
                UpdateButtons();
            }
            else
            {
                timer1.Stop();

                MessageBox.Show("Game over...");

                InputForm input = new InputForm();
                input.score = Model.score.ToString();
                input.ShowDialog();
            }
        }
Esempio n. 2
0
        public bool IsGameOver()
        {
            if (isGameOver)
            {
                var message = MessageBox.Show("Вы проиграли" + "со счетом: " + value + ". \nХотите сохранить результат?", "Сообщение",
                                              MessageBoxButtons.YesNo);
                if (message == DialogResult.Yes)
                {
                    var inputForm = new InputForm();
                    inputForm.score = value.ToString();
                    inputForm.ShowDialog();
                }

                return(isGameOver);
            }
            else
            {
                for (int x = 1; x < mapSize + 1; x++)
                {
                    for (int y = 1; y < mapSize + 1; y++)
                    {
                        if (nums[x, y] == 0)
                        {
                            return(false);
                        }
                    }
                }

                for (int x = 1; x < mapSize + 1; x++)
                {
                    for (int y = 1; y < mapSize + 1; y++)
                    {
                        if (nums[x, y] == nums[x + 1, y] || nums[x, y] == nums[x, y + 1])
                        {
                            return(false);
                        }
                    }
                }
            }
            isGameOver = true;
            return(isGameOver);
        }