/// <summary> /// The main entry point for the application. /// /// Team Dynasty /// @author: Rob Husfeldt /// @author: Jenny Li /// @author: William Powell /// @author: Ryan Conrad /// @author: Zachary Behrmann /// </summary> static void Main(string[] args) { using (Game1 game = new Game1()) { game.Run(); } }
public Scenario Update(Game1 game) { if (InputManager.KeyButtonReady(Keys.Escape, Buttons.A, 1, false)) { Game1.Menus.Push(Game1.TitleMenu); } if (InputManager.MouseReleased()) { if (start.Contains(InputManager.MousePos)) { startGameSound.Play(); Game1.Menus.Pop(); scenarios[currentIndex].LoadScenarioArmies(); return scenarios[currentIndex]; } else if (mapRight.Contains(InputManager.MousePos)) { Game1.ClickSound.Play(); currentIndex++; if (currentIndex >= scenarios.Count) { currentIndex = 0; } imageChange = true; } else if (mapLeft.Contains(InputManager.MousePos)) { Game1.ClickSound.Play(); currentIndex--; if (currentIndex < 0) { currentIndex = scenarios.Count - 1; } imageChange = true; } else if (teamLeft.Contains(InputManager.MousePos)) { Game1.ClickSound.Play(); Game1.Team--; } else if (teamRight.Contains(InputManager.MousePos)) { Game1.ClickSound.Play(); Game1.Team++; } } if (imageChange) { try { FileStream blah = System.IO.File.Open(path + @"thumbnails\" + scenarios[currentIndex].Thumbnail, FileMode.Open); mapPreview = Texture2D.FromStream(game.GraphicsDevice, blah); blah.Close(); } catch { FileStream blah = System.IO.File.Open(path + @"thumbnails\default.png", FileMode.Open); mapPreview = Texture2D.FromStream(game.GraphicsDevice, blah, 240, 240, false); blah.Close(); } finally { imageChange = false; } } base.Update(); return null; }
/// <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; } } }
public void Update(Game1 g) { if (InputManager.KeyReady(Keys.Escape)) { // TODO: // Make a "Save Progress?" confirmation message come up. // Pressing no will actually erase the game's current state // otherwise, the menu will just be pushed on and "Start Game" will be changed to "Resume Game" Game1.PauseSound.Play(); Game1.Menus.Push(pauseMenu); } /* if (players[turn] is Human) { endTurn = (players[turn] as Human).Update(g.Camera, boxxy.EndTurnButton); } else { endTurn = players[turn].Update(g); } if (endTurn) { turn++; if (turn >= players.Count) turn = 0; } */ if (players[turn].Update(g.Camera)) { turn++; if (turn >= players.Length) turn = 0; } for (int i = 0; i < players.Length-1; i++) { if (players[i + 1].OwnArmy.Units.Count == 0) { playerWin = true; } else playerWin = false; } if (players[0].OwnArmy.Units.Count == 0) { if(playerWin) Game1.Menus.Push(new GameOverScreen(0, int.MaxValue, int.MaxValue, 2)); // push game over screen on the stack else Game1.Menus.Push(new GameOverScreen(0, int.MaxValue, int.MaxValue, 1)); // push game over screen on the stack } if (playerWin) { Game1.Menus.Push(new GameOverScreen(0, int.MaxValue, int.MaxValue, 0)); // push game over screen on the stack } }