Beispiel #1
0
        private void Menu_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Up)
            {
                if (PM2.GetY() == 303)
                {
                    PM2.SetY(503);
                }
                else
                {
                    PM2.SetY(PM2.GetY() - 50);
                }
            }

            if (e.KeyCode == Keys.Down)
            {
                if (PM2.GetY() == 503)
                {
                    PM2.SetY(303);
                }
                else
                {
                    PM2.SetY(PM2.GetY() + 50);
                }
            }

            if (e.KeyCode == Keys.Enter)
            {
                if (PM2.GetY() == 303)
                {
                    Animation.Stop();
                    Visible = false;
                    GameForm gf = new GameForm();
                    gf.ShowDialog();
                    gf.Close();
                    Animation.Start();
                    Visible = true;
                    TopMost = true;
                    Focus();
                }

                if (PM2.GetY() == 353)
                {
                    MenuState = 2;
                    Animation.Stop();
                    grfx.DrawImage(Properties.Resources.MenuHelp, -10, 0, Width, Height - 50);
                }

                if (PM2.GetY() == 403)
                {
                    MenuState = 2;
                    Animation.Stop();
                    HighScore hs = new HighScore();
                    hs.ShowDialog();
                    hs.Close();
                    Animation.Start();
                }

                if (PM2.GetY() == 453)
                {
                    MenuState = 2;
                    Animation.Stop();
                    grfx.DrawImage(Properties.Resources.MenuAbout, -10, 0, Width, Height - 50);
                }

                if (PM2.GetY() == 503)
                {
                    Application.Exit();
                }
            }
            if (e.KeyCode == Keys.Escape)
            {
                if (MenuState == 1)
                {
                    Application.Exit();
                }
                else
                {
                    Animation.Start();
                    MenuState = 1;
                    grfx.DrawImage(Properties.Resources.Menu, -10, 0, Width, Height - 50);
                }
            }
        }
Beispiel #2
0
        private void PacmanTimer_Tick(object sender, EventArgs e)
        {
            HighScore    hs;
            DialogResult dr;

            if (!Dead)
            {
                if (PacmanPicState == 1)
                {
                    Pman.SetImage(Properties.Resources.Pacman2);
                    PacmanPicState = 2;
                }
                else
                {
                    Pman.SetImage(Properties.Resources.Pacman1);
                    PacmanPicState = 1;
                }

                Pman.RotatePacman();
                Pman.MovePacman(maze.GetMaze());
                if (maze.GameWin())
                {
                    Pman.SetScore(Pman.GetTries() * 200);
                    PacmanTimer.Stop();
                    GhostTimer.Stop();
                    hs = new HighScore(Pman);
                    hs.ShowDialog();
                    hs.Close();

                    dr = MessageBox.Show("Do you want to play again?",
                                         "Game Over",
                                         MessageBoxButtons.YesNo,
                                         MessageBoxIcon.Question);
                    if (dr == DialogResult.Yes)
                    {
                        StartGame();
                    }
                    else
                    {
                        DrawingTimer.Stop();
                        Close();
                    }
                }
            }
            else
            {
                if (i < 10)
                {
                    Pman.ResetDeathAnimationFrames();
                    Pman.SetImage(Pman.GetAnimation()[i]);
                    Pman.RotatePacman();
                    i++;
                }
                else
                {
                    i = 0;
                    Pman.SetImage(Properties.Resources.Pacman1);
                    ResetLocations();
                    PacmanTimer.Stop();
                    Dead = false;
                }
            }

            if (Pman.GetTries() != 0 || Dead)
            {
                return;
            }
            hs = new HighScore(Pman);
            hs.ShowDialog();
            hs.Close();

            dr = MessageBox.Show("Do you want to play again?",
                                 "Game Over",
                                 MessageBoxButtons.YesNo,
                                 MessageBoxIcon.Question);
            if (dr == DialogResult.Yes)
            {
                StartGame();
            }
            else
            {
                DrawingTimer.Stop();
                Close();
            }
        }