Ejemplo n.º 1
0
        public void ShowScene()
        {
            brush1.Color = Color.Black;
            DBgrfx.FillRectangle(brush1, new Rectangle(0, 0, this.Width, this.Height));

            maze.DrawMaze(DBgrfx);

            RGhost.DrawItem(DBgrfx);
            YGhost.DrawItem(DBgrfx);
            BGhost.DrawItem(DBgrfx);
            PGhost.DrawItem(DBgrfx);
            Pman.DrawItem(DBgrfx);

            DBgrfx.DrawString("Score:" + Pman.GetScore(), text, new SolidBrush(Color.White), 0, 650);
            DBgrfx.DrawString("Ammo:" + Pman.GetAmmo(), text, new SolidBrush(Color.White), 500, 650);
            DBgrfx.DrawString("Tries:" + Pman.GetTries(), text, new SolidBrush(Color.White), 265, 650);

            if (ShootOnce)
            {
                bullet.DrawItem(DBgrfx);
            }
            try
            {
                grfx.DrawImage(BackBuffer, 0, 0);
            }
            catch
            {
                DrawingTimer.Stop();
            }
        }
Ejemplo n.º 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            BackBuffer = new Bitmap(ClientSize.Width, ClientSize.Height);
            DBgrfx     = Graphics.FromImage(BackBuffer);
            brush1     = new SolidBrush(Color.Black);

            grfx = CreateGraphics();

            Pman   = new Pacman(280, 480, Properties.Resources.Pacman1);
            RGhost = new RedGhost(280, 280, Properties.Resources.RedGhost);
            BGhost = new BlueGhost(300, 300, Properties.Resources.BlueGhost);
            YGhost = new YellowGhost(280, 300, Properties.Resources.YellowGhost);
            PGhost = new PinkGhost(260, 300, Properties.Resources.PinkGhost);
            PinkGhostAppearTimer = 20;

            block  = new Block(0, 0);
            bullet = new Bullet(0, 0, Properties.Resources.Bullet);

            maze = new Maze();

            DrawingTimer.Start();
        }
Ejemplo n.º 3
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();
            }
        }