updated map format to read time limit & max ZPM count needed to win

This commit is contained in:
Kjistóf 2016-05-13 20:29:03 +02:00
parent 3be072e282
commit d64fb27413
4 changed files with 20 additions and 3 deletions

View File

@ -5,10 +5,15 @@ import java.util.HashMap;
import java.util.Map;
public class Dungeon {
private int ZPMsToWin = 0;
private long timeLimit = 0;
/* NOTE: this function assumes that the parameter input is a well-formatted dungeon file.
* Such file looks like as follows:
*
* <map width>x<map height>
* <time limit in seconds>
* <empty line>
* <map matrix line 1>
* ...
@ -42,8 +47,9 @@ public class Dungeon {
Tile replicatorlocation = defaultTile;
try(BufferedReader reader = new BufferedReader(new FileReader(input)))
{
String[] sizedata = reader.readLine().split("x"); // read size data at beginning of file
reader.readLine(); // throw empty line away
String[] sizedata = reader.readLine().split("x"); // read size data at beginning of file
timeLimit = Long.parseLong(reader.readLine()) * 1000; // read time limit
reader.readLine(); // throw empty line away
int width = Integer.parseInt(sizedata[0]);
int height = Integer.parseInt(sizedata[1]);
@ -75,6 +81,7 @@ public class Dungeon {
tile = new Field();
display.addVisual(new FieldDrawer((Field) tile));
tile.setZPMOnTile(new ZPM());
ZPMsToWin++;
break;
case 'B':
@ -181,4 +188,12 @@ public class Dungeon {
return playermap;
}
public int getZPMsToWin() {
return ZPMsToWin;
}
public long getTimeLimit() {
return timeLimit;
}
}

View File

@ -50,7 +50,7 @@ public class Game {
display.addVisual(new PlayerDrawer(jaffa));
display.addVisual(new PlayerBaseDrawer(replicator));
flowoftime.start(420*420);
flowoftime.start(dungeon.getTimeLimit());
}
private Direction getRandomDirection() {

View File

@ -1,4 +1,5 @@
5x5
10
W W W W W
W O B S W

View File

@ -1,4 +1,5 @@
5x5
5
W W W W W
W F F F W