Exemplo n.º 1
0
        public void Simulate(Stopwatch sw, int processingTime)
        {
            for (int i = 0; i < rand.Next(0, 3); i++)
            {
                Ash.Pos = Ash.Pos.Move(Util.ToRadians(rand.Next(0, 360)), rand.Next(0, 1000));
                SimulateTurn();

                if (!Humans.Any() || !Zombies.Any() || sw.ElapsedMilliseconds >= processingTime)
                {
                    return;
                }
            }

            var targetZ = Zombies[rand.Next(0, Zombies.Length - 1)];

            while (Humans.Any() && Zombies.Any() && sw.ElapsedMilliseconds < processingTime)
            {
                if (!Zombies.Any(z => z.Id == targetZ.Id))
                {
                    targetZ = Zombies[rand.Next(0, Zombies.Length - 1)];
                }
                int distance = Ash.Pos.DistanceTo(targetZ.NextPos);
                distance = distance > 3000 ? 1000 : rand.Next(distance - 2000, 1000);

                Ash.Pos = Ash.Pos.MoveToward(targetZ.NextPos, distance);
                SimulateTurn();
            }
        }
Exemplo n.º 2
0
        public void Simulate(Stopwatch sw, int processingTime)
        {
            var targetZ = Zombies[rand.Next(0, Zombies.Length - 1)];

            while (Humans.Any() && Zombies.Any() && sw.ElapsedMilliseconds < processingTime)
            {
                if (!Zombies.Any(z => z.Id == targetZ.Id))
                {
                    targetZ = Zombies[rand.Next(0, Zombies.Length - 1)];
                }
                int distance = Ash.Pos.DistanceTo(targetZ.NextPos);
                distance = distance > 3000 ? 1000 : rand.Next(distance - 2000, 1000);

                var angle = Util.ToDegrees(Util.AngleBetween(Ash.Pos, targetZ.NextPos));
                angle  += rand.Next(-10, 10);
                Ash.Pos = Ash.Pos.Move(Util.ToRadians(angle), distance);
                SimulateTurn();
            }
        }