Ejemplo n.º 1
0
        private void MovePlayesMisales(Tank player)
        {
            // enemy fires move
            List<Fire> misalesFire = new List<Fire>();
            foreach (Fire misale in this.playerMisals)
            {
                if (!collision.HaveShotCollision(misale, player, this.enemys))
                {
                    misale.Move();
                    this.render.Misale(misale);   //draw missile
                    misalesFire.Add(misale);
                }
                else
                {
                    misale.Move();
                    // if have collision delete missile from Console
                    try
                    {
                        this.render.DeleteMisale(misale);
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                        // missile i out of map don't delete it
                    }

                    for (int i = 0; i < this.enemys.Count; i++)
                    {
                        if (this.enemys[i].IsHited)
                        {
                            this.enemys[i].DecreaseLives();
                            this.enemys[i].IsHited = false;
                            this.render.Tank(this.enemys[i]);

                            if (this.enemys[i].Lives <= 0)
                            {
                                Console.Beep(5500, 40);
                                this.score += this.enemys[i].Score;
                                this.enemys[i].SetDefitedCordinates();
                                render.DeleteTank(this.enemys[i]);
                                this.enemys.Remove(this.enemys[i]);
                            }
                        }
                    }

                    int eagleRow = this.level.GetLength(0) - 1;
                    int eagleCol = (this.level.GetLength(1) - 1) / 2;

                    // if there is no eagle set player live = 0 and this will make game over
                    if (this.level[eagleRow, eagleCol] == null)
                    {
                        while (player.Lives > 0)
                        {
                            player.DecreaseLives();
                        }

                        return;
                    }
                }
            }

            this.playerMisals = misalesFire;
        }
Ejemplo n.º 2
0
        private void MoveEnemyMisales(Tank player)
        {
            // enemy fires move
            List<Fire> misales = new List<Fire>();
            foreach (Fire misale in this.enemyMisals)
            {
                if (!collision.HaveShotCollision(misale, player, this.enemys))
                {
                    misale.Move();
                    this.render.Misale(misale);
                    misales.Add(misale);

                    for (int i = 0; i < this.enemys.Count; i++)
                    {
                        if (this.collision.DoesItCollideFire(new Element(ElementType.Braket, enemys[i].CurrentRow, enemys[i].CurrentCol),
                                                                            misale.CurrentRow, misale.CurrentCol))
                        {
                            this.render.Tank(enemys[i]);
                        }
                    }
                }
                else if (player.IsHited)
                {
                    // if have collision delete missile from Console
                    misale.Move();
                    try
                    {
                        this.render.DeleteMisale(misale);
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                        // missile is out of map don't delete it
                    }

                    Console.Beep(280, 200);
                    Console.Beep(480, 200);
                    Console.Beep(680, 100);
                    player.DecreaseLives();
                    player.IsHited = false;

                    player.SetDefitedCordinates();
                    this.render.DeleteTank(player);

                    if (player.Lives > 0)
                    {
                        player.MakeStartPosition();
                        render.Tank(player);
                    }
                }
                else
                {
                    misale.Move();
                    // if have collision delete misale from Console
                    try
                    {
                        this.render.DeleteMisale(misale);
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                        // missale i out of map donot delete it
                    }

                    int eagleRow = this.level.GetLength(0) - 1;
                    int eagleCol = (this.level.GetLength(1) - 1) / 2;

                    // if there is no eagle set player live = 0 and this will make game over
                    if (this.level[eagleRow, eagleCol] == null)
                    {
                        while (player.Lives > 0)
                        {
                            player.DecreaseLives();
                        }

                        return;
                    }
                }
            }

            this.enemyMisals = misales;
        }