예제 #1
0
        public void MakeTurn()
        {
            foreach (var creature in Alive.Where(c => c != Player))
            {
                creature.MakeAutoTurn();
            }

            foreach (var projectile in _projectiles)
            {
                projectile.Move();
                var projectileRect = projectile.ToRectangle();
                foreach (var creature in Alive.Where(creature => projectile.Side != creature.Side &&
                                                     Geometry.CheckRectangleIntersection(projectileRect, creature.ToRectangle())))
                {
                    creature.TakeDamage(projectile.Damage);
                    projectile.Collide();
                    break;
                }

                foreach (var dummy in Walls.Where(wall => Geometry.CheckRectangleIntersection(wall.ToRectangle(), projectileRect)))
                {
                    projectile.Collide();
                }
            }

            _projectiles.RemoveWhere(p => p.Live <= 0);
            _aliveCreatures.RemoveWhere(c => !c.IsAlive);
            Player.MakeTurn(PlayersTurn);
            PlayersTurn = Turn.None;
        }
예제 #2
0
        /// <summary>
        /// Tries to return the first available proxy from the list.
        /// </summary>
        /// <param name="evenBusy">Whether to include proxies that are being used by other bots</param>
        /// <param name="maxUses">The maximum uses of a proxy, after which it will be banned (0 for infinite)</param>
        /// <param name="neverBan">Whether a proxy can ever be banned</param>
        /// <returns>The first available proxy respecting the conditions or null</returns>
        public CProxy GetProxy(bool evenBusy, int maxUses, bool neverBan = false)
        {
            while (Locked)
            {
                Thread.Sleep(10);
            }

            CProxy proxy;

            Locked = true;
            if (evenBusy)
            {
                if (maxUses == 0)
                {
                    proxy = Alive.FirstOrDefault();
                }
                else
                {
                    proxy = Alive.Where(p => p.Uses < maxUses).FirstOrDefault();
                }
            }
            else
            {
                if (maxUses == 0)
                {
                    proxy = Available.FirstOrDefault();
                }
                else
                {
                    proxy = Available.Where(p => p.Uses < maxUses).FirstOrDefault();
                }
            }

            if (proxy != null)
            {
                if (maxUses > 0 && proxy.Uses > maxUses && !neverBan)
                {
                    proxy.Status = Status.BANNED;
                    Locked       = false;
                    return(null);
                }
                else
                {
                    proxy.Status = Status.BUSY;
                    proxy.Hooked++;
                }
            }
            Locked = false;
            return(proxy);
        }