示例#1
0
        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (field.Visibility == Visibility.Visible)
            {
                switch (e.Key)
                {
                case (Key.Up):
                    if (game.MovingUp())
                    {
                        game.New();
                    }
                    UpdateField(game);
                    break;

                case (Key.Down):
                    if (game.MovingDown())
                    {
                        game.New();
                    }
                    UpdateField(game);
                    break;


                case (Key.Left):
                    if (game.MovingLeft())
                    {
                        game.New();
                    }
                    UpdateField(game);
                    break;

                case (Key.Right):
                    if (game.MovingRight())
                    {
                        game.New();
                    }
                    UpdateField(game);
                    break;
                }
                if (game.HeIsAlreadyDead())
                {
                    MessageBox.Show("You lose! :c\nTry Again??", "OMG, hi, my name is rreshrr...", MessageBoxButton.OK);
                    Retry();
                }
                if (!won)
                {
                    if (game.HeIsAlreadyWon())
                    {
                        if (MessageBox.Show("You win!!\nContinue?", "Congratulations!", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                        {
                            won = true;
                        }
                        else
                        {
                            Retry();
                        }
                    }
                }
            }
        }