public Level loadLevel(String filepath) { currentLevel = Level.loadSimpleLevelXML(filepath); return currentLevel; }
public static Level loadLevelXML(String fileName) { FileStream fileStream = new FileStream(fileName, FileMode.Open); XmlSerializer xml = new XmlSerializer(typeof(LevelXML)); LevelXML currentXML = (LevelXML)xml.Deserialize(fileStream); Level newLevel = new Level(currentXML.sizeX, currentXML.sizeY, currentXML.Name); newLevel.levelGrid = new Grid(currentXML.sizeX, currentXML.sizeY); newLevel.LevelName = currentXML.Name; foreach (RowXML row in currentXML.rows) { foreach (ColumnXML column in row.columns) { newLevel.levelGrid.GridSpaces[row.index, column.index] = new GridSpace(column.type, row.index, column.index, column.elevation, newLevel.levelGrid); newLevel.levelGrid.setMoveCost(row.index, column.index, row.index, column.index - 1, column.costNorth); newLevel.levelGrid.setMoveCost(row.index, column.index, row.index + 1, column.index + (row.index % 2 == 0 ? -1 : 0), column.costNorthEast); newLevel.levelGrid.setMoveCost(row.index, column.index, row.index + 1, column.index + (row.index % 2 == 0 ? 0 : 1), column.costSouthEast); newLevel.levelGrid.setMoveCost(row.index, column.index, row.index, column.index + 1, column.costSouth); newLevel.levelGrid.setMoveCost(row.index, column.index, row.index - 1, column.index + (row.index % 2 == 0 ? 0 : 1), column.costSouthWest); newLevel.levelGrid.setMoveCost(row.index, column.index, row.index - 1, column.index + (row.index % 2 == 0 ? -1 : 0), column.costNorthWest); if (column.hero != null) { HeroXML h = column.hero; newLevel.levelGrid.GridSpaces[row.index, column.index].tryPutActor(new Hero(h.currentHP, h.maxHP, h.currentEnergy, h.maxEnergy, h.moveSpeed, h.level, h.currentXP, h.name, new Vector2(row.index, column.index))); } else if (column.person != null) { PersonXML p = column.person; newLevel.levelGrid.GridSpaces[row.index, column.index].tryPutActor(new Person(p.currentHP, p.maxHP, p.currentEnergy, p.maxEnergy, p.moveSpeed, p.name, new Vector2(row.index, column.index))); } else if (column.actor != null) { ActorXML a = column.actor; newLevel.levelGrid.GridSpaces[row.index, column.index].tryPutActor(new Actor()); } } } for (int i = 0; i < currentXML.sizeX; ++i) { for (int j = 0; j < currentXML.sizeY; ++j) { if (newLevel.levelGrid.GridSpaces[i, j] == null) { newLevel.levelGrid.GridSpaces[i, j] = new GridSpace(0, i, j, 0, newLevel.levelGrid); } } } fileStream.Close(); return newLevel; }
public Level makeNewLevel(int sizeX, int sizeY, String name) { currentLevel = Level.makeEmptyGrid(sizeX, sizeY, name); return currentLevel; }