示例#1
0
        private void Animation_Tick(object sender, EventArgs e)
        {
            _dBgrfx.DrawImage(Properties.Resources.Menu, -10, 0, Width, Height - 50);

            PM1.SetX(PM1.GetX() + 15);
            RG.SetX(RG.GetX() + 15);
            BG.SetX(BG.GetX() + 15);
            YG.SetX(YG.GetX() + 15);
            PG.SetX(PG.GetX() + 15);

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

            if (PM1.GetX() > Width)
            {
                PM1.SetX(0);
            }
            if (RG.GetX() > Width)
            {
                RG.SetX(0);
            }
            if (BG.GetX() > Width)
            {
                BG.SetX(0);
            }
            if (YG.GetX() > Width)
            {
                YG.SetX(0);
            }
            if (PG.GetX() > Width)
            {
                PG.SetX(0);
            }

            PM1.DrawItem(_dBgrfx);
            PM2.DrawItem(_dBgrfx);
            RG.DrawItem(_dBgrfx);
            BG.DrawItem(_dBgrfx);
            YG.DrawItem(_dBgrfx);
            PG.DrawItem(_dBgrfx);

            grfx.DrawImage(_backBuffer, 0, 0);
        }
示例#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();
            }
        }