Exemple #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Allies"></param>
        /// <param name="Enemies"></param>
        /// <param name="OwnArmy"></param>
        public AI(List<Army> Allies, List<Army> Enemies, Army OwnArmy)
        {
            turnStart = true;
            friendlyUnits = new List<Unit>();

            foreach (Army ally in Allies)
            {
                foreach (Unit u in ally.Units)
                {
                    friendlyUnits.Add(u);
                }
            }

            enemyUnits = new List<Unit>();

            foreach (Army enemy in Enemies)
            {
                foreach (Unit u in enemy.Units)
                {
                    enemyUnits.Add(u);
                }
            }

            ownArmy = OwnArmy;

            currentUnitIndex = 0;
            currentUnit = ownArmy.Units[0];
            animating = false;
            hasAttacked = false;
            turnStart = true;
        }
Exemple #2
0
 /// <summary>
 /// Create a new player
 /// </summary>
 /// <param name="input">The input manager of the game</param>
 /// <param name="bar">The infobar, player handles displaying and hiding the infobar</param>
 public Human(InfoBar bar, UpdateBox box, Texture2D sprite, Army a)
 {
     changeTurn = false;
     mapControl = true;
     infoBar = bar;
     updateBox = box;
     endTurnButton = box.EndTurnButton;
     currentGridX = 2;
     currentGridY = 2;
     texture = sprite;
     ownArmy = a;
     mainSelector = new Selector(tiles, actualPos, sprite, currentGridX, currentGridY);
     secondarySelector = new Selector(tiles, actualPos, sprite, currentGridX, currentGridY);
     highlightGone = true;
     //texture = Game1.GameContent.Load<Texture2D>("generic_unit");
 }
Exemple #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="player">The player - allows us to give player the array of tiles</param>
        /// <param name="terrainSheet">The spriteSheet that tiles will load their texture from</param>
        /// <param name="_armies">An array of armies participating in the battle</param>
        public Battle(Game1 g, Scenario loadedScenario)
        {
            endTurn = false;
            turn = 0;
            players = new Player[loadedScenario.ArmyAmount];
            pauseMenu = new PauseMenu(3, Game1.GameHeight / 2 - 25, 192);

            terrainSheet = Game1.GameContent.Load<Texture2D>("Spritesheet");
            playerSheet = Game1.GameContent.Load<Texture2D>("selector");
            unitSheet = Game1.GameContent.Load<Texture2D>("ArmySpriteSheet");

            testArmy = loadedScenario.Armies[0];
            g.InfoBar.YMod = 110;
            g.InfoBar.Visible = false;

            players[0] = new Human(g.InfoBar,Game1.UpdateBox, playerSheet, loadedScenario.Armies[0]);
            players[0].RectPos = new Rectangle(64, 64, GV.TileSize, GV.TileSize);
            players[0].ActualPosition = new Rectangle(64, 64, GV.TileSize, GV.TileSize);
            for (int i = 1; i < players.Length; i++)
            {
                List<Army> allies = new List<Army>();
                List<Army> enemies = new List<Army>();
                for (int j = 0; j < loadedScenario.ArmyAmount; j++)
                {
                    if (j != i)
                    {
                        if (loadedScenario.Armies[j].Team == loadedScenario.Armies[i].Team)
                        {
                            allies.Add(loadedScenario.Armies[j]);
                        }
                        else
                        {
                            enemies.Add(loadedScenario.Armies[j]);
                        }
                    }
                }
                players[i] = new AI(allies, enemies, loadedScenario.Armies[i]);
            }
            g.Camera.Focus = players[0];

            DirectoryInfo d = new DirectoryInfo(Environment.CurrentDirectory);
            while (d.ToString() != "dynasty")
                d = d.Parent;
            string path = d.FullName + @"\GameData\Maps\";

            XmlReader mapReader = XmlReader.Create(path + loadedScenario.MapFile);
            int currentRow = 0;
            int currentCol = 0;

            mapReader.ReadToFollowing("map"); //read to the first map element available

            players[0].Position2 = new Point(160, 160); //place the player at a default point for now

            mapSize = Convert.ToInt32(mapReader.GetAttribute("size")); //get the size of the map (both the length and width of the map are the same, so we use "size")
            tiles = new Tile[mapSize, mapSize]; //Create a 2D array that holds the required amount of tiles
            int lastPlaced = 0;
            currentRow = 0;
            currentCol = 0;
            mapReader.ReadToFollowing("tile"); //Read to the first tile elements of the map so we can begin creating tiles
            do
            {
                int length = Convert.ToInt32(mapReader.GetAttribute("length")); //Get the rectangle size of the tile
                //string[] bound = bounds.Split(','); //Split the values provided into an array
                //int startX = int.Parse(bound[0]); //our starting x location for creating tiles
                //int startY = int.Parse(bound[1]);  //our starting y location for creating tiles
                //int endX = int.Parse(bound[2]);  //our ending x location for creating tiles
                //int endY = int.Parse(bound[3]); //our ending y location for creating tiles
                for (int i = 0; i < length; i++)
                {
                    tiles[currentRow, currentCol] = new Tile(mapReader.GetAttribute("terrain"), terrainSheet, currentRow, currentCol);
                    currentRow++;
                    if (currentRow >= mapSize)
                    {
                        currentRow = 0;
                        currentCol++;
                    }
                    if ((currentCol == mapSize) && (currentRow == mapSize))
                        break;
                }
            } while (mapReader.ReadToNextSibling("tile"));

            mapReader.ReadToNextSibling("spawns");
            //spawns = new List<Tile>();
            mapReader.ReadToFollowing("tile");
            do
            {
                string bounds = mapReader.GetAttribute("location");
                string[] bound = bounds.Split(',');
                int startX = int.Parse(bound[0]);
                int startY = int.Parse(bound[1]);
                int endX = int.Parse(bound[2]);
                int endY = int.Parse(bound[3]);

                for (int i = startX; i < endX; i++)
                {
                    for (int j = startY; j < endY; j++)
                    {
                        //_tiles[i, j].Spawn = true;
                        //spawns.Add(_tiles[i, j]);
                    }
                }
            } while (mapReader.ReadToNextSibling("tile")); //head to the next tile element if one exists, otherwise we exit this loop

            mapReader.Close();

            foreach (Player p in players)
            {
                p.SetTiles(tiles);
                foreach (Unit u in p.OwnArmy.Units)
                {
                        tiles[u.UnitBox.X / GV.TileSize, u.UnitBox.Y / GV.TileSize].Unit = u;
                        u.UnitSprite = unitSheet;
                        u.UnitPic = unitSheet;
                }
            }
        }
Exemple #4
0
        public void LoadScenarioArmies()
        {
            XmlReader reader = XmlReader.Create(xmlFilePath);

            armies = new Army[armyAmount];
            int currentArmyNum = 0;
            reader.ReadToFollowing("army");

            do
            {
                int teamNumber = int.Parse(reader.GetAttribute("team"));
                List<Unit> tempUnits = new List<Unit>();
                reader.ReadToFollowing("unit");
                do
                {
                    string type = reader.GetAttribute("type");
                    switch (type)
                    {
                        case "helicopter": tempUnits.Add(
                            new Helicopter(null,
                                Convert.ToInt32(reader.GetAttribute("x")),
                                Convert.ToInt32(reader.GetAttribute("y")),
                                currentArmyNum, reader.GetAttribute("direction")));
                            break;
                        case "infantry": tempUnits.Add(
                            new Infantry(null,
                                Convert.ToInt32(reader.GetAttribute("x")),
                                Convert.ToInt32(reader.GetAttribute("y")),
                                currentArmyNum, reader.GetAttribute("direction")));
                            break;
                        case "tank": tempUnits.Add(
                        new Tank(null,
                            Convert.ToInt32(reader.GetAttribute("x")),
                            Convert.ToInt32(reader.GetAttribute("y")),
                            currentArmyNum, reader.GetAttribute("direction")));
                            break;
                        case "skimmer": tempUnits.Add(
                        new Skimmer(null,
                            Convert.ToInt32(reader.GetAttribute("x")),
                            Convert.ToInt32(reader.GetAttribute("y")),
                            currentArmyNum, reader.GetAttribute("direction")));
                            break;
                        default: break;
                    }
                } while (reader.ReadToNextSibling("unit"));
                armies[currentArmyNum] = new Army(tempUnits, teamNumber, currentArmyNum);
                currentArmyNum++;
            } while (reader.ReadToNextSibling("army"));
        }