Package model
Class XMLParser
java.lang.Object
model.XMLParser
public class XMLParser
extends java.lang.Object
Level class is reads an XML file that follows a certain XML schema. It specifies the framework of the playable
levels in the Anti-tower Defence game.
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description intgetCurrentIndex()For testing.Region[][]getGrid()For testing.intgetGridCols()For testing.intgetGridRows()For testing.intgetLevelCount()For testing.org.w3c.dom.DocumentgetLevelsDoc()For testing.char[][]getMapGrid()For testing.intgetPassToWin()RegiongetStartRegion()For testing.java.util.ArrayListgetTowerList()getTowerList()intgetWinCondition()getWinCondition - Reads and retrieves the specified win condition from XML sheet.java.lang.StringimageName()imageName() - Loads path source as string from current level in XML file and saves the image.voidinitGrid()initGrid() - Initiates grid with regions with specified rows and columns as its dimensions.voidlevelIncrement()levelIncrement() - Sets the new level (by changing current index).voidloadLevel()loadLevel() - Loads current level, i.e.voidloadRegions()loadRegions() - Loads specified regions from XML sheet and puts a marker together with corresponding the name into a hashmap as key-value pairs.static voidmain(java.lang.String[] args)For testing.voidnewReadTeleporterList()***** TO BE OVERLOOKED BEFORE USE *****voidreadArea()readArea() - Reads entire grid from XML and by using the hashmap (set in loadRegions) creates corresponding type of regions as well as putting these in grid.org.w3c.dom.DocumentreadLevels(java.lang.String fileName)readLevels() - Reads levels from XML sheet and puts them in a parsable document.intreadNrColumns(org.w3c.dom.Document doc, int index)getNrRows() - Reads column tag from xml.intreadNrRows(org.w3c.dom.Document doc, int index)readNrRows() - Reads row tag from xml.voidreadTowerList()newReadTowerList() - reads list of regions with possible tower positions and places specified amount of towers randomly.
-
Constructor Details
-
XMLParser
public XMLParser(java.lang.String fileName) throws javax.xml.parsers.ParserConfigurationException, java.io.IOException, org.xml.sax.SAXException- Throws:
javax.xml.parsers.ParserConfigurationExceptionjava.io.IOExceptionorg.xml.sax.SAXException
-
XMLParser
public XMLParser() throws javax.xml.parsers.ParserConfigurationException, java.io.IOException, org.xml.sax.SAXException- Throws:
javax.xml.parsers.ParserConfigurationExceptionjava.io.IOExceptionorg.xml.sax.SAXException
-
-
Method Details
-
readLevels
public org.w3c.dom.Document readLevels(java.lang.String fileName) throws javax.xml.parsers.ParserConfigurationException, java.io.IOException, org.xml.sax.SAXExceptionreadLevels() - Reads levels from XML sheet and puts them in a parsable document.- Returns:
- - Document to be read from.
- Throws:
javax.xml.parsers.ParserConfigurationExceptionjava.io.IOExceptionorg.xml.sax.SAXException
-
getWinCondition
public int getWinCondition()getWinCondition - Reads and retrieves the specified win condition from XML sheet.- Returns:
- - Win condition as an int.
-
readNrRows
public int readNrRows(org.w3c.dom.Document doc, int index)readNrRows() - Reads row tag from xml.- Parameters:
doc- is the xml document to be read from.index- is the index that corresponds to the current level.
-
readNrColumns
public int readNrColumns(org.w3c.dom.Document doc, int index)getNrRows() - Reads column tag from xml.- Parameters:
doc- is the xml document to be read from.index- is the index that corresponds to the current level.
-
loadRegions
public void loadRegions()loadRegions() - Loads specified regions from XML sheet and puts a marker together with corresponding the name into a hashmap as key-value pairs. -
readArea
public void readArea()readArea() - Reads entire grid from XML and by using the hashmap (set in loadRegions) creates corresponding type of regions as well as putting these in grid. -
readTowerList
public void readTowerList()newReadTowerList() - reads list of regions with possible tower positions and places specified amount of towers randomly. -
newReadTeleporterList
public void newReadTeleporterList()***** TO BE OVERLOOKED BEFORE USE ***** -
imageName
public java.lang.String imageName()imageName() - Loads path source as string from current level in XML file and saves the image.- Returns:
- - Path source read from XML sheet.
-
initGrid
public void initGrid()initGrid() - Initiates grid with regions with specified rows and columns as its dimensions. Method is to be called before any read-method of Level class is called. -
levelIncrement
public void levelIncrement()levelIncrement() - Sets the new level (by changing current index). -
loadLevel
public void loadLevel()loadLevel() - Loads current level, i.e. is to be used when game has been started and when levelIncrement is being invoked. -
getTowerList
public java.util.ArrayList getTowerList()getTowerList()- Returns:
- - Tower list containing placed towers in current level.
-
getPassToWin
public int getPassToWin() -
getGrid
For testing. -
getLevelsDoc
public org.w3c.dom.Document getLevelsDoc()For testing. -
getCurrentIndex
public int getCurrentIndex()For testing. -
getLevelCount
public int getLevelCount()For testing. -
getGridRows
public int getGridRows()For testing. -
getGridCols
public int getGridCols()For testing. -
getMapGrid
public char[][] getMapGrid()For testing. -
getStartRegion
For testing. -
main
public static void main(java.lang.String[] args) throws java.io.IOException, org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationExceptionFor testing.- Throws:
java.io.IOExceptionorg.xml.sax.SAXExceptionjavax.xml.parsers.ParserConfigurationException
-