Пример #1
0
        internal override void Destroy()
        {
            GhostTimer.Stop();
            if (BulletDodgeReactionTimer != null)
            {
                BulletDodgeReactionTimer.Stop();
            }

            base.Destroy();
        }
Пример #2
0
 private void DrawingTimer_Tick(object sender, EventArgs e)
 {
     ShowScene();
     if (Dead ||
         ((((!RGhost.CaughtPacman(Pman)) && (!YGhost.CaughtPacman(Pman))) && (!BGhost.CaughtPacman(Pman))) &&
          (!PGhost.CaughtPacman(Pman))))
     {
         return;
     }
     Dead = true;
     Pman.ReduceTries();
     GhostTimer.Stop();
     PinkGhostAppearTimer = 25;
 }
Пример #3
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            GhostTimer.Interval = new TimeSpan(0, 0, 0, 0, new Random().Next(0, 2000));

            if (TickCount >= 3)
            {
                TickCount = 0;

                if (Direction == Direction.Left)
                {
                    Bullet <Player, Ghost> ghostBullet = new Bullet <Player, Ghost>(this, (int)(this.Coordinates.X - 1), (int)(this.Coordinates.Y), GameTable, this.Direction);
                }
                else if (Direction == Direction.Right)
                {
                    Bullet <Player, Ghost> ghostBullet = new Bullet <Player, Ghost>(this, (int)(this.Coordinates.X + 1), (int)(this.Coordinates.Y), GameTable, this.Direction);
                }
                else if (Direction == Direction.Up)
                {
                    Bullet <Player, Ghost> ghostBullet = new Bullet <Player, Ghost>(this, (int)(this.Coordinates.X), (int)(this.Coordinates.Y - 1), GameTable, this.Direction);
                }
                else if (Direction == Direction.Down)
                {
                    Bullet <Player, Ghost> ghostBullet = new Bullet <Player, Ghost>(this, (int)(this.Coordinates.X), (int)(this.Coordinates.Y + 1), GameTable, this.Direction);
                }
            }

            Bullet <Ghost, Player> BulletToDodge = null;


            //only if the ghost is not trying to dodge the bullet
            if (IsBulletCollisionTrajectory(this.Coordinates, out BulletToDodge) == false)
            {
                //Find the player and follow him
                if (Player.Coordinates.X > this.Coordinates.X)
                {
                    var newCoord = new Point(this.Coordinates.X + 1, this.Coordinates.Y);
                    if (!IsBulletCollisionTrajectory(newCoord))
                    {
                        this.Direction = Direction.Right;
                        UiContainer.RenderTransform = new RotateTransform(90);
                        this.Coordinates            = newCoord;
                    }
                }
                else if (Player.Coordinates.X < this.Coordinates.X)
                {
                    var newCoord = new Point(this.Coordinates.X - 1, this.Coordinates.Y);
                    if (!IsBulletCollisionTrajectory(newCoord))
                    {
                        this.Direction = Direction.Left;
                        UiContainer.RenderTransform = new RotateTransform(-90);
                        this.Coordinates            = newCoord;
                    }
                }

                if (Player.Coordinates.Y > this.Coordinates.Y)
                {
                    var newCoord = new Point(this.Coordinates.X, this.Coordinates.Y + 1);
                    if (!IsBulletCollisionTrajectory(newCoord))
                    {
                        this.Direction = Direction.Down;
                        UiContainer.RenderTransform = new RotateTransform(180);
                        this.Coordinates            = newCoord;
                    }
                }
                else if (Player.Coordinates.Y < this.Coordinates.Y)
                {
                    var newCoord = new Point(this.Coordinates.X, this.Coordinates.Y - 1);
                    if (!IsBulletCollisionTrajectory(newCoord))
                    {
                        this.Direction = Direction.Up;
                        UiContainer.RenderTransform = new RotateTransform(0);
                        this.Coordinates            = newCoord;
                    }
                }
                if (this.Coordinates.X == Player.Coordinates.X && this.Coordinates.Y == Player.Coordinates.Y)
                {
                    GhostTimer.Stop();
                    GameTable.OnGameOver();
                }
            }
            else
            {
                TryDodgeBullet(BulletToDodge);
            }


            AdjustCoordinatesToFitIntoTable();
            TickCount++;
        }
Пример #4
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();
            }
        }