Пример #1
0
        public void SetPaths(Map myMap)
        {
            List<Tile> newCollisionList = new List<Tile>();

            leader.setDestination(destination);
            foreach(Mobile unit in units)
            {
                unit.isMoving = false;
                if(unit != leader)
                {
                    Vector2 newDestination = GetOffset(unit, myMap) + destination;
                    if(myMap.GetTile(newDestination) != null && myMap.GetTile(newDestination).isWalkable == true)
                    {
                        unit.setDestination(GetOffset(unit, myMap) + destination);
                    }
                    else
                        unit.setDestination(destination);
                }
                //unit.setDestination(destination);
                Vector2 startPoint = new Vector2(unit.Bounds.Center.X, unit.Bounds.Center.Y);
                unit.pathList.Clear();
                unit.pathList.AddRange(myMap.GetPath(startPoint, unit.destination, newCollisionList));
                unit.isMoving = true;
            }

        }
Пример #2
0
 private AIManager(ref Map newMap)
 {
     random = new Random();
     myMap = newMap;
     moveTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
     imTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent2);
     pursueTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent3);
 }
Пример #3
0
 private ModelManager(ref Map newMap)
 {
     player = new List<GameObject>();
     artificial = new List<GameObject>();
     inMotion = new List<GameObject>();
     autoPlace = new Vector2(0, 0);
     myMap = newMap;
 }
Пример #4
0
        // Once you beat a map, you return to the level selection screen and the next level is now interactable.

        public Selector(Rectangle space, Map current, Map next, Boolean interact)
        {
            this.selectionSpace = space;
            isOccupied = false;
            this.nextLevel = next;
            this.currentLevel = current;
            this.isInteractable = interact;
        }
Пример #5
0
 public static AIManager getInstance(ref Map newMap){
     if (instance == null)
     {
         instance = new AIManager(ref newMap);
         return instance;
     }
     else
         return instance;
 }
Пример #6
0
  // Need constructor, should it emulate the other managers?
  // startPrev will be defeatScreen; startCurr will be mainScreen; startNext will be levelSelect;
 
  private ScreenManager()
  {
      prevMap = null;
      currentMap = null;
      nextMap = null;
      victory = "undef";
      // progressIndex is pointing to mainScreen currently
      progressIndex = 0;
  }
Пример #7
0
        public Vector2 GetOffset(Mobile unit, Map myMap)
        {
            //  Save tiles for leader and unit position:
            Tile leaderTile = myMap.GetContainingTile(leader);
            Tile unitTile = myMap.GetContainingTile(unit);

            if (leaderTile == null || unitTile == null)
                return new Vector2(0, -0);

            // Upper left
            if (unitTile.xPosition < leaderTile.xPosition && unitTile.yPosition <= leaderTile.yPosition)
            {
                ulCounter++;
                if(ulCounter == 1)
                    return new Vector2(-32, 0);
                else
                    return new Vector2(-32, -32);
            }

            //  Upper right
            if (unitTile.xPosition >= leaderTile.xPosition && unitTile.yPosition < leaderTile.yPosition)
            {
                urCounter++;
                if (urCounter == 1)
                    return new Vector2(0, -32);
                else
                    return new Vector2(32, -32);
            }

            //  Bottom right
            if (unitTile.xPosition > leaderTile.xPosition && unitTile.yPosition >= leaderTile.yPosition)
            {
                brCounter++;
                if(brCounter == 1)
                    return new Vector2(32, 0);
                else
                    return new Vector2(32, 32);
            }

            // Bottom left
            if (unitTile.xPosition <= leaderTile.xPosition && unitTile.yPosition > leaderTile.yPosition)
            {
                blCounter++;
                if (blCounter == 1)
                    return new Vector2(32, 0);
                else
                    return new Vector2(-32, 32);
            }

            else
                return new Vector2(0, 0);
        }
Пример #8
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            try
            {
                Window.AllowUserResizing = true;
                //graphics.CreateDevice();
                graphics.PreferredBackBufferHeight = 704;
                graphics.PreferredBackBufferWidth = 1024;
                graphics.IsFullScreen = false;
             //   graphics.ToggleFullScreen();
                graphics.ApplyChanges();
            }
            catch
            {
            }
            // Create a new SpriteBatch, which can be used to draw textures.
            ClickTimer = 0;
            groupedUnits = new Dictionary<Keys, List<GameObject>>();
            spriteBatch = new SpriteBatch(GraphicsDevice);
            // TODO: Add your initialization logic here
            defeatScreen = new Map("Content/defeatScreen.txt");
            mainScreen = new Map("Content/MainScreen.txt");
            levelSelect = new Map("Content/levelSelect.txt");
            castleDefense = new Map("Content/castleDefense.txt");
            riverDefense = new Map("Content/riverDefense.txt");
            castleSiege = new Map("Content/castleSiege.txt");
            victoryScreen = new Map("Content/victoryScreen.txt");
            mainScreenSelector = new Selector(new Rectangle(448, 0, 128, 64), mainScreen, levelSelect, true);
            castleDefenseSelector = new Selector(new Rectangle(96, 320, 192, 96), levelSelect, castleDefense, false);
            riverDefenseSelector = new Selector(new Rectangle(416, 320, 192, 96), levelSelect, riverDefense, false);
            castleSiegeSelector = new Selector(new Rectangle(736, 320, 192, 96), levelSelect, castleSiege, false);
            defeatScreenSelector = new Selector(new Rectangle(448, 256, 128, 64), defeatScreen, mainScreen, false);
            victoryScreenSelector = new Selector(new Rectangle(448, 288, 128, 64), victoryScreen, mainScreen, false);
            modMan = ModelManager.getInstance(ref mainScreen);
            loadMan = LoadManager.getInstance();
            projMan = ProjectileManager.getInstance();
            screenManager = ScreenManager.getInstance();
            // Add all maps to screenManager.allMaps
            screenManager.allMaps.Add(defeatScreen);
            screenManager.allMaps.Add(mainScreen);
            screenManager.allMaps.Add(levelSelect);
            screenManager.allMaps.Add(castleDefense);
            screenManager.allMaps.Add(riverDefense);
            screenManager.allMaps.Add(castleSiege);
            screenManager.allMaps.Add(victoryScreen);
            // Add all selectors to screenManager.allSelectors
            screenManager.allSelectors.Add(defeatScreenSelector);
            screenManager.allSelectors.Add(mainScreenSelector);
            screenManager.allSelectors.Add(castleDefenseSelector);
            screenManager.allSelectors.Add(riverDefenseSelector);
            screenManager.allSelectors.Add(castleSiegeSelector);
            screenManager.allSelectors.Add(victoryScreenSelector);
            // Set initial maps; These will always be defeatScreen, mainScreen and levelSelect,
            // since the user spawns on mainScreen
            screenManager.prevMap = defeatScreen;
            screenManager.currentMap = mainScreen;
            screenManager.nextMap = levelSelect;
            healthChecker = new HealthSystem(ModelManager.player, ModelManager.artificial);
            attackChecker = new AttackSystem(ref ModelManager.player, ref ModelManager.artificial);
            attackChecker.linkSystem(projMan);
            attackChecker.linkContent(Content);
            movementManager = MovementManager.getInstance();
            movementManager.setMap(mainScreen);
            inputManager = new InputManager(ref modMan);
            aiManager = AIManager.getInstance(ref mainScreen);
            mBar = new MoraleBar(ref modMan);
            gui = new GUIButtons(ref modMan);
            info = new InfoCard(ref modMan);
            inputManager.linkGUI(gui);
            MoraleBar.resourceVal(buildResources);
            mousePrev = Mouse.GetState();
            //Create Player's units
            //testInitialization();
           


            testCommander();
            base.Initialize();
            this.IsMouseVisible = true;
           
           
        }
Пример #9
0
 // Ensures that the managers all know which map to work on.
 public void updateManagerMap(Map myMap)
 {
     modMan = ModelManager.getInstance(ref myMap);
     movementManager.setMap(myMap);
     aiManager = AIManager.getInstance(ref myMap);
 }
Пример #10
0
 public void setMap(Map newMap){
     myMap = newMap;
 }
Пример #11
0
 private MovementManager()
 {
     myMap = null;
     unitGroups = new List<UnitGroup>();
 }
Пример #12
0
        /* Screen manager needs to do the following:
         * Create a list of maps:
         *      screenList[0] = defeatScreen (graveyard) screenList[1] = mainScreen; screenList[2] = levelSelect;
         *      screenList[3] = castleDefense; screenList[4] = riverDefense; screenList[5] = castleSiege;
         * If current map is levelSelect, then all selectors will be pointing to game levels.
         * If current map is a game level, there are two conditions: 
         *      if victory, advance to next screen
         *      if loss, decrement screen
         * 
         * Turn the selectors off
         * 
         */

        public void updateSelectors(String victoryCondition)
        {
            if (victoryCondition.Equals("victory"))
            {
                // The only time you can achieve "victory" is on playable maps
                switch (currentMap.name)
                {
                    case "Content/castleDefense.txt":
                        //Console.WriteLine("We won castleDefense!");
                        currentMap = allMaps[2];
                        //Console.WriteLine("allMaps[2] is: " + allMaps[2].name);
                        allSelectors[3].setInteraction(true);
                        allSelectors[3].setUnlocked(true);
                        allSelectors[2].setUnlocked(true);
                        foreach (Selector select in allSelectors)
                        {
                            select.setOccupied(false);
                        }
                        break;
                    case "Content/riverDefense.txt":
                        currentMap = allMaps[2];
                        allSelectors[3].setUnlocked(true);
                        allSelectors[2].setUnlocked(true);
                        allSelectors[4].setUnlocked(true);
                        allSelectors[4].setInteraction(true);
                        foreach (Selector select in allSelectors)
                        {
                            select.setOccupied(false);
                        }
                        break;
                    case "Content/castleSiege.txt":
                        currentMap = allMaps[6];
                        allSelectors[5].setUnlocked(true);
                        allSelectors[5].setInteraction(true);
                        foreach (Selector select in allSelectors)
                        {
                            select.setOccupied(false);
                        }
                        break;
                }
                victory = "undef";
            }
            else if (victoryCondition.Equals("defeat"))
            {
                switch (currentMap.name)
                {
                    case "Content/castleDefense.txt":
                        currentMap = allMaps[0];
                        allSelectors[0].setUnlocked(true);
                        allSelectors[0].setInteraction(true);
                        //Console.WriteLine("interaction for defeatScreen is: " + allSelectors[0].getInteraction());
                        //allSelectors
                        break;
                    case "Content/riverDefense.txt":
                        currentMap = allMaps[2];
                        allSelectors[3].setUnlocked(false);
                        allSelectors[2].setUnlocked(true);
                        allSelectors[3].setInteraction(false);
                        break;
                    case "Content/castleSiege.txt":
                        currentMap = allMaps[2];
                        allSelectors[2].setUnlocked(true);
                        allSelectors[3].setUnlocked(true);
                        allSelectors[4].setUnlocked(false);
                        allSelectors[4].setInteraction(false);
                        break;
                }
                victory = "undef";
            }
            else
            {
                //Console.WriteLine("Victory condition in updateSelectors is " + victoryCondition);
                //Console.WriteLine(currentMap.name);
                switch (currentMap.name)
                {
                    case "Content/defeatScreen.txt":
                        //Console.WriteLine("Hello from updateSelectors in defeatScreen switch case");
                        //allSelectors[0].setInteraction(true);
                        //allSelectors[0].setUnlocked(true);
                        //allSelectors[0].setOccupied(false);
                        if ((allSelectors[0].getOccupied() == true) && (allSelectors[0].getInteraction() == true)
                            && (allSelectors[0].getUnlocked() == true))
                        {
                            currentMap = allMaps[1];
                            foreach (Selector select in allSelectors)
                            {
                                select.setUnlocked(false);
                                select.setInteraction(false);
                                select.setOccupied(false);
                            }
                            allSelectors[1].setInteraction(true);
                            allSelectors[1].setUnlocked(true);
                        }
                        break;
                    case "Content/MainScreen.txt":
                        // First update the selector attributes for the given level
                        //Console.WriteLine("Hello from updateSelectors in mainScreen switch case");
                        allSelectors[0].setUnlocked(false);
                        allSelectors[1].setInteraction(true);
                        allSelectors[1].setUnlocked(true);
                        if (allSelectors[1].getOccupied() == true)
                        {
                            //Console.WriteLine("You've reached the mainScreen selector!");
                            currentMap = allMaps[2];
                            nextMap = allMaps[3];
                            allSelectors[2].setInteraction(true);
                            allSelectors[2].setUnlocked(true);
                        }
                        break;
                    case "Content/levelSelect.txt":
                        if ((allSelectors[2].getOccupied() == true) && (allSelectors[2].getInteraction() == true)
                            && (allSelectors[2].getUnlocked() == true))
                        {
                            currentMap = allMaps[3];
                            foreach (Selector select in allSelectors)
                            {
                                select.setUnlocked(false);
                            }
                            progressIndex = 0;
                        }
                        if ((allSelectors[3].getOccupied() == true) && (allSelectors[3].getInteraction() == true)
                            && (allSelectors[3].getUnlocked() == true))
                        {
                            currentMap = allMaps[4];
                            foreach (Selector select in allSelectors)
                            {
                                select.setUnlocked(false);
                            }
                            progressIndex = 1;
                        }
                        if ((allSelectors[4].getOccupied() == true) && (allSelectors[4].getInteraction() == true)
                            && (allSelectors[4].getUnlocked() == true))
                        {
                            currentMap = allMaps[5];
                            foreach (Selector select in allSelectors)
                            {
                                select.setUnlocked(false);
                            }
                            progressIndex = 3;
                        }
                        break;
                    case "Content/victoryScreen.txt":
                        //Console.WriteLine("You made it!");
                        //allSelectors[5].setInteraction(true);
                        //allSelectors[5].setUnlocked(true);
                        if ((allSelectors[5].getOccupied() == true)  && (allSelectors[5].getInteraction() == true)
                            && (allSelectors[5].getUnlocked() == true))
                        {
                            currentMap = allMaps[1];
                            foreach (Selector select in allSelectors)
                            {
                                select.setUnlocked(false);
                                select.setInteraction(false);
                            }
                            allSelectors[1].setInteraction(true);
                            allSelectors[1].setUnlocked(true);
                        }
                        break;
                }
            }
        }