Esempio n. 1
0
        /// <summary>
        /// Used by the Soldier to find a nearyby Chupacabra.
        /// </summary>
        /// <param name="mapObj"></param>
        /// <param name="range"></param>
        /// <returns>The position of the chupacabra</returns>
        internal static Point GetClosestAggressiveAnimalInRange(Point mapObjPos, int range)
        {
            Point nearbyEnemyPos = null;
            int   bestRange      = range;

            for (int i = 0; i < Map.Height; i++)
            {
                for (int j = 0; j < Map.Width; j++)
                {
                    Point p = new Point(i, j);
                    if (mapObjPos.DistanceFrom(p) < bestRange)
                    {
                        foreach (MapObject mo in Map.GetCellAt(i, j).MapObjects)
                        {
                            if (mo.GetType().IsSubclassOf(typeof(AggressiveAnimal)))
                            {
                                AggressiveAnimal chu = (AggressiveAnimal)mo;
                                if (!chu.Dead)
                                {
                                    bestRange      = mapObjPos.DistanceFrom(p);
                                    nearbyEnemyPos = p;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            return(nearbyEnemyPos);
        }
Esempio n. 2
0
        /// <summary>
        /// Updates the whole scene.
        /// This method should be called every loop.
        /// </summary>
        public static void Update()
        {
            bool thereArePlayerUnits = false;
            bool thereAreEnemies     = false;

            ResetActiveVisiblitiesToExplored();

            List <MapObject> updatingMapObjectList = new List <MapObject>();

            foreach (Cell cell in Map.Cells)
            {
                updatingMapObjectList.AddRange(cell.MapObjects);
            }
            foreach (MapObject mapObj in updatingMapObjectList)
            {
                mapObj.Update();
                bool  found;
                Point pos = GetMapObjectPosition(mapObj, out found);
                if (found)
                {
                    if (mapObj.GetType().IsSubclassOf(typeof(PlayerControlled)))
                    {
                        PlayerControlled unit = (PlayerControlled)mapObj;
                        SetVisibilitiesToActiveInRange(pos, unit.SightRange);
                        thereArePlayerUnits = true;
                    }
                    if (mapObj.GetType().IsSubclassOf(typeof(AggressiveAnimal)))
                    {
                        AggressiveAnimal ani = (AggressiveAnimal)mapObj;
                        if (!ani.Dead)
                        {
                            thereAreEnemies = true;
                        }
                    }
                }
            }
            if (!thereAreEnemies && State != GameState.PostVictory)
            {
                State = GameState.Victory;
            }
            if (!thereArePlayerUnits)
            {
                State = GameState.Defeat;
            }
        }
Esempio n. 3
0
        private void Hit(Point pos)
        {
            bool hit = false;

            foreach (MapObject mo in Engine.Map.GetCellAt(pos).MapObjects)
            {
                if (mo.GetType().IsSubclassOf(typeof(AggressiveAnimal)))
                {
                    AggressiveAnimal a = (AggressiveAnimal)mo;
                    a.TakeDamage(Damage);
                    hit = true;
                }
            }
            if (hit)
            {
                Engine.DestroyMapObject(this, pos);
            }
        }