Пример #1
0
 internal override void Destroy()
 {
     base.Destroy();
     if (this.GetType() == typeof(Player))
     {
         GameTable.OnGameOver();
     }
 }
Пример #2
0
 internal override void Destroy()
 {
     Timer.Stop();
     GameTable.RemoveItem(this);
 }
Пример #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++;
        }