Exemplo n.º 1
0
        public void Play()
        {
            while (gameStatus == GameStatus.playing)
            {
                Thread.Sleep(speedGame);

                projectile.Run();
                packman.Run();
                // run for hunter
                ((Hunter)tanks[0]).Run(packman.X, packman.Y);

                for (int i = 1; i < tanks.Count; i++)
                {
                    tanks[i].Run();
                }

                //burning tank

                foreach (FireTank ft in fireTank)
                {
                    ft.Burn();
                }

                for (int i = 1; i < tanks.Count; i++)
                {
                    if (Math.Abs(tanks[i].X - projectile.X) < 11 && Math.Abs(tanks[i].Y - projectile.Y) < 11)
                    {
                        fireTank.Add(new FireTank(tanks[i].X, tanks[i].Y));
                        tanks.RemoveAt(i);
                        projectile.DefaultSettings();
                    }
                }


                //tank+tank
                for (int i = 0; i < tanks.Count - 1; i++)
                {
                    for (int j = i + 1; j < tanks.Count; j++)
                    {
                        if (
                            (Math.Abs(tanks[i].X - tanks[j].X) <= 20 && (tanks[i].Y == tanks[j].Y))
                            ||
                            (Math.Abs(tanks[i].Y - tanks[j].Y) <= 20 && (tanks[i].X == tanks[j].X))
                            ||
                            (Math.Abs(tanks[i].X - tanks[j].X) <= 20) && (Math.Abs(tanks[i].Y - tanks[j].Y) <= 20)
                            )
                        {
                            if (i == 0)
                            {
                                ((Hunter)tanks[i]).TurnAround();
                            }
                            else
                            {
                                tanks[i].TurnAround();
                            }
                            tanks[j].TurnAround();
                        }
                    }
                }
                // packman+tank
                for (int i = 0; i < tanks.Count; i++)
                {
                    if (
                        (Math.Abs(tanks[i].X - packman.X) <= 20 && (tanks[i].Y == packman.Y))
                        ||
                        (Math.Abs(tanks[i].Y - packman.Y) <= 20 && (tanks[i].X == packman.X))
                        ||
                        (Math.Abs(tanks[i].X - packman.X) <= 20) && (Math.Abs(tanks[i].Y - packman.Y) <= 20)
                        )
                    {
                        gameStatus = GameStatus.loser;
                    }
                }

                if (changeStreep != null)
                {
                    changeStreep();
                }

                //packman+apple
                for (int i = 0; i < apples.Count; i++)
                {
                    if (Math.Abs(packman.X - apples[i].X) < 4 && Math.Abs(packman.Y - apples[i].Y) < 4)
                    {
                        apples[i] = new Apple(0 + collectedApples * 20, 260);
                        collectedApples++;
                    }
                }

                if (collectedApples > 4)
                {
                    gameStatus = GameStatus.winner;
                }

                if (changeStreep != null)
                {
                    changeStreep();
                }
            }
        }