public void Reinitialize()
        {
            if ((level = ScreenManager.SharedManager.GetCurrentGameScreen().level) == null)
                throw new WTFException("We are currently not inside a GameScreen and cannot create an AIManager, or the level has not been initiated yet. Stop trying to get the AIManager before creating the level!");
            if ((map = level.levelMap) == null)
                throw new WTFException("The current map has not been initialized yet. Stop trying to get the AIManager before finishing building the level.");

            //Create the PriorityQueue
            enemiesToPath = new PriorityQueue<int, Enemy>();

            currentPursuit = new HashSet<Enemy>();
            isPursuitActive = false;
        }
        /// <summary>
        /// Constructor for the AIManager class
        /// </summary>
        private AIManager()
        {
            //If an AIManager doesn't exist, create one.
            if (sharedManager == null)
                sharedManager = this;
            //If one does exist, something went so horribly, horribly wrong, that a "Well That Failed" exception may not truly convey the severity of what just happened.
            else
                throw new WTFException("An instance of AIManager already exists. This should never happen. If it does, congrats you just called a private method outside of the class it exists in.");

            //Get our level, map, and graph, otherwise throw exceptions because we're doing something wrong
            if ((level = ScreenManager.SharedManager.GetCurrentGameScreen().level) == null)
                throw new WTFException("We are currently not inside a GameScreen and cannot create an AIManager, or the level has not been initiated yet. Stop trying to get the AIManager before creating the level!");
            if((map = level.levelMap) == null)
                throw new WTFException("The current map has not been initialized yet. Stop trying to get the AIManager before finishing building the level.");

            //Create the PriorityQueue
            enemiesToPath = new PriorityQueue<int, Enemy>();

            currentPursuit = new HashSet<Enemy>();
            isPursuitActive = false;

            rand = new Random();
        }
Beispiel #3
0
        List<Weapon> weapons; // a list to hold all of the weapons for the level

        #endregion Fields

        #region Constructors

        // constructor
        public Level(string mapFile)
        {
            // initializes things
            this.mapFile = mapFile;
            basicEnemies = new List<Enemy>();
            walls = new List<Wall>();
            weapons = new List<Weapon>();
            coins = new List<Coin>();
            doors = new List<Door>();
            keys = new List<Key>();
            disguises = new List<Disguise>();
            floorSwitchers = new List<FloorSwitcher>();
            font = ScreenManager.SharedManager.Content.Load<SpriteFont>("Arial");

            graphics = ScreenManager.SharedManager.gDevice;
            spriteBatch = ScreenManager.SharedManager.sBatch;

            levelMap = new Map(mapFile, new int[11] { 1, 1, 1, 1, 1, int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue, 0, 0 });

            roomGraph = new RoomGraph();
            foreach (var groupname in levelMap.ObjectGroups.Keys) // goes through each layer in the map file
            {
                int currentFloor = int.Parse(groupname[5].ToString()) - 1; // gets the floor number of the map layer.

                if (groupname.Substring(6, 8) == "Entities") // the layer contains GameObjects
                {
                    foreach (var entity in levelMap.ObjectGroups[groupname]) // goes through each entity and creates a GameObject if possible.
                    {
                        if (entity.Type == "Enemy") // adds an enemy to the basicEnemies list.
                        {
                            string sDir = entity.Properties.Find(x => x.Item1 == "startDirection").Item2;
                            int dir =  (sDir != null) ? int.Parse(sDir) : 3;
                            basicEnemies.Add(EntityGenerator.GenerateEnemy(new Vector3(entity.X, entity.Y, currentFloor), entity.Properties, dir));
                        }
                        else if (entity.Type == "Player") // creates the player.
                        {
                            player = EntityGenerator.GeneratePlayer(new Vector3(entity.X, entity.Y, currentFloor), 5, 400);
                        }
                        else if (entity.Type == "Wall") // adds a wall to the walls list.
                        {
                            walls.Add(EntityGenerator.GenerateWall(new Vector3(entity.X, entity.Y, currentFloor), entity.Width, entity.Height));
                        }
                        else if (entity.Type == "LockedDoor") // adds a door to the doors list.
                        {
                            doors.Add(EntityGenerator.GenerateDoor(new Vector3(entity.X, entity.Y, currentFloor), doors.Count));
                        }
                        else if (entity.Type == "Key") // adds a key to the keys list.
                        {
                            keys.Add(EntityGenerator.GenerateKey(new Vector3(entity.X, entity.Y, currentFloor), keys.Count));
                        }
                        else if (entity.Type == "Weapon") // adds a weapon to the weapons list.
                        {
                            weapons.Add(EntityGenerator.GenerateWeapon(new Vector3(entity.X, entity.Y, currentFloor), int.Parse(entity.Properties.Find(x => x.Item1 == "durability").Item2), entity.Properties.Find(x => x.Item1 == "type").Item2));
                        }
                        else if (entity.Type == "Coin") // adds a coin to the coins list.
                        {
                            coins.Add(EntityGenerator.GenerateCoin(new Vector3(entity.X, entity.Y, currentFloor), int.Parse(entity.Properties.Find(x => x.Item1 == "value").Item2)));
                        }
                        else if (entity.Type == "Disguise") //adds a disguise to the disguises list.
                        {
                            disguises.Add(EntityGenerator.GenerateDisguise(new Vector3(entity.X, entity.Y, currentFloor), entity.Properties.Find(x => x.Item1 == "disguiseType").Item2));
                        }
                        else if (entity.Type == "FloorSwitcher") // adds a floor switcher to the floorSwitchers list.
                        {
                            floorSwitchers.Add(new FloorSwitcher(new Rectangle(entity.X, entity.Y, entity.Width, entity.Height), currentFloor, currentFloor + 1, bool.Parse(entity.Properties.Find(x => x.Item1 == "Horizontal").Item2)));
                        }
                    }
                }

                if (groupname.Contains("Room")) // layer contains rooms
                {
                    foreach (var entity in levelMap.ObjectGroups[groupname]) // goes through each room object in the layer.
                    {
                        // creates a new RoomGraphNode and sets up it's connections.
                        RoomGraphNode node = new RoomGraphNode(new Rectangle(entity.X, entity.Y, entity.Width, entity.Height), currentFloor, entity.Name);
                        List<string> connections = new List<string>();
                        foreach (var t in entity.Properties)
                        {
                            if (t.Item1 != null)
                                connections.Add(t.Item1);
                            if (t.Item2 != null)
                                node.validDisguises.Add(t.Item2);
                        }
                        roomGraph.AddNode(node, connections);
                    }
                }

                // how much money the player needs to complete the level is 70% of the total money in the level.
                player.moneyNeeded = (basicEnemies.Count + coins.Count) * 70;
            }

            foreach (Door lockedDoor in doors) // if there aren't enough keys, the extra locked doors are unlocked.
            {
                if (keys[lockedDoor.keyAssociation] == null)
                    lockedDoor.locked = false;
            }

            // sets up what part of the level to show on screen.
            windowSpace = new Rectangle((int)(player.location.X + (player.rectangle.Width / 2)) - (graphics.Viewport.Width / 2), (int)(player.location.Y + (player.rectangle.Height / 2)) - (graphics.Viewport.Height / 2), graphics.Viewport.Width, graphics.Viewport.Height);
        }