Exemple #1
0
        public void InitReferee(int playerCount)
        {
            Random random = new Random();

            units       = new List <Unit>();
            looters     = new List <Looter>();
            tankers     = new List <Tanker>();
            deadTankers = new List <Tanker>();
            wrecks      = new List <Wreck>();
            players     = new List <Player>();

            // Create players
            for (int i = 0; i < playerCount; ++i)
            {
                Player player = new Player(i);
                players.Add(player);
            }

            // Create Looters
            foreach (Player player in players)
            {
                for (int i = 0; i < LOOTER_COUNT; ++i)
                {
                    Looter looter = CreateLooter(i, player, 0, 0);
                    player.Looters[i] = looter;
                    units.Add(looter);
                    looters.Add(looter);
                }
            }

            // Random spawns for Looters
            bool finished = false;

            while (!finished)
            {
                finished = true;

                for (int i = 0; i < LOOTER_COUNT && finished; ++i)
                {
                    double distance = random.NextDouble() * (MAP_RADIUS - LOOTER_RADIUS);
                    double angle    = random.NextDouble();

                    foreach (Player player in players)
                    {
                        double looterAngle = (player.Index + angle) * (Math.PI * 2.0 / ((double)playerCount));
                        double cos         = Math.Cos(looterAngle);
                        double sin         = Math.Sin(looterAngle);

                        Looter looter = player.Looters[i];
                        looter.Move(cos * distance, sin * distance);

                        // If the Looter touch A Looter, Reset everyone and try again
                        if (units.Any(u => u != looter && looter.Distance(u) <= looter.Radius + u.Radius))
                        {
                            finished = false;
                            looters.ForEach(l => l.Move(0.0, 0.0));
                            break;
                        }
                    }
                }
            }

            Adjust();
        }