public bool timer1()
        {
            try
            {
                hero.MoveBullets(width, height);
                if (hero.Kills >= 4)
                {
                    hasBoss = true;
                }
                // foreach (Bullet b in hero.Bullets)
                for (int i = 0; i < hero.Bullets.Count; i++)
                {
                    //foreach (Zombie z in zombies)
                    for (int j = 0; j < zombies.Count; j++)
                    {
                        if (hero.Bullets[i].isHit(zombies[j].Position))
                        {
                            zombies[j].Alive      = false;
                            hero.Bullets[i].Alive = false;
                            hero.Kills++;
                        }
                    }

                    if (hasBoss)
                    {
                        if (hero.Bullets[i].isHit(boss.Position))
                        {
                            boss.Health          -= 20;
                            hero.Bullets[i].Alive = false;
                        }

                        if (boss.Health <= 0)
                        {
                            hasBoss = false;

                            return(true);
                        }
                    }
                }

                for (int i = zombies.Count - 1; i >= 0; i--)
                {
                    if (!zombies[i].Alive)
                    {
                        zombies.RemoveAt(i);
                    }
                }
            }
            catch (Exception exc)
            {
                return(false);
            }
            return(false);
        }
Beispiel #2
0
        private void Timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                kiro.MoveBullets(width, height);
                if (kiro.Kills >= 1)
                {
                    hasBoss = true;
                }
                foreach (Bullet b in kiro.Bullets)
                {
                    foreach (Zombie z in zombies)
                    {
                        if (b.isHit(z.Position))
                        {
                            z.Alive = false;
                            b.Alive = false;
                            kiro.Kills++;
                        }
                    }

                    if (hasBoss)
                    {
                        if (b.isHit(boss.Position))
                        {
                            boss.Health -= 20;
                            b.Alive      = false;
                            Invalidate(true);
                        }

                        if (boss.Health <= 0)
                        {
                            hasBoss = false;

                            endgame();
                            Invalidate(true);
                        }
                    }
                }

                for (int i = zombies.Count - 1; i >= 0; i--)
                {
                    if (!zombies[i].Alive)
                    {
                        zombies.RemoveAt(i);
                    }
                }
            }
            catch (Exception exc)
            {
            }
            Invalidate(true);
        }
Beispiel #3
0
        public bool timer1(ref bool won)
        {
            foreach (var item in BossBullets)
            {
                item.Move(Width, Height);
            }
            hero.MoveBullets(Width, Height);

            if (hero.Kills >= 15)
            {
                hasBoss = true;
            }
            foreach (Bullet b in ZombieBullets)
            {
                b.Move(Width, Height);
            }

            foreach (Bullet b in hero.Bullets)
            {
                foreach (Zombie z in zombies)
                {
                    if (b.isHit(z.Position))
                    {
                        z.Alive = false;
                        b.Alive = false;
                        hero.Kills++;
                    }
                }
                if (hasBoss)
                {
                    if (b.isHit(boss.Position))
                    {
                        boss.Health -= 20;
                        b.Alive      = false;
                    }

                    if (boss.Health <= 0)
                    {
                        hasBoss = false;
                        won     = true;
                        return(false);
                    }
                }
            }
            foreach (Bullet b in ZombieBullets)
            {
                if (b.isHit(hero.Position))
                {
                    hero.Health -= 10;
                    if (hero.Health <= 0)
                    {
                        hero.Image = Properties.Resources.dead;
                        return(true);
                    }
                    b.Alive = false;
                }
            }

            foreach (Bullet b in BossBullets)
            {
                if (b.isHit(hero.Position))
                {
                    hero.Health -= 20;
                    if (hero.Health <= 0)
                    {
                        hero.Image = Properties.Resources.dead;
                        return(true);
                    }
                    b.Alive = false;
                }
            }

            for (int i = ZombieBullets.Count - 1; i >= 0; i--)
            {
                if (!ZombieBullets[i].Alive)
                {
                    ZombieBullets.RemoveAt(i);
                }
            }
            for (int i = BossBullets.Count - 1; i >= 0; i--)
            {
                if (!BossBullets[i].Alive)
                {
                    BossBullets.RemoveAt(i);
                }
            }
            for (int i = zombies.Count - 1; i >= 0; i--)
            {
                if (!zombies[i].Alive)
                {
                    zombies.RemoveAt(i);
                }
            }
            return(false);
        }