Major changes
The game now has several levels which can be travelled between Fake walls Stairs going uo Stairs going down Binoculars Shields can now be placed on the map Chests can now be randomly filled Inventory has been moved Shiny new health bar The player can use stairs
This commit is contained in:
@@ -59,6 +59,8 @@ public class Game implements IGame {
|
||||
* individual items don't.
|
||||
*/
|
||||
private IGameMap map;
|
||||
private List<IGameMap> maps = new ArrayList<>();
|
||||
private int currentLVL = 0;
|
||||
private IActor currentActor;
|
||||
private ILocation currentLocation;
|
||||
private int movePoints = 0;
|
||||
@@ -79,18 +81,13 @@ public class Game implements IGame {
|
||||
// inputGrid will be filled with single-character strings indicating what (if
|
||||
// anything)
|
||||
// should be placed at that map square
|
||||
IGrid<String> inputGrid = MapReader.readFile("maps/testmap.txt");
|
||||
if (inputGrid == null) {
|
||||
System.err.println("Map not found – falling back to builtin map");
|
||||
inputGrid = MapReader.readString(Main.BUILTIN_MAP);
|
||||
}
|
||||
this.map = new GameMap(inputGrid.getArea());
|
||||
for (ILocation loc : inputGrid.locations()) {
|
||||
IItem item = createItem(inputGrid.get(loc));
|
||||
if (item != null) {
|
||||
map.add(loc, item);
|
||||
}
|
||||
}
|
||||
loadMap("level1.txt", 1);
|
||||
loadMap("level2.txt", 2);
|
||||
loadMap("level3.txt", 3);
|
||||
loadMap("level4.txt", 4);
|
||||
loadMap("level5.txt", 5);
|
||||
map = maps.get(0);
|
||||
map.add(map.getLocation( 3, 3), new Player()); //We must be sure there is never more than one player
|
||||
|
||||
// Prints some helpful information.
|
||||
String[] info = {"Controls:", "WASD or arrow keys for movement", "E to pick up an item", "Q to drop an item", "1-0 to choose an item (10=0)", "N to change name", "ENTER to confirm", "R to use a ranged attack", "F to use a magic attack", "C to use a potion"};
|
||||
@@ -157,6 +154,28 @@ public class Game implements IGame {
|
||||
return defence;
|
||||
}
|
||||
|
||||
public void goUp() {
|
||||
if (currentLVL + 1 < maps.size()) {
|
||||
map = maps.get(++currentLVL);
|
||||
if (!map.has(currentLocation, currentActor)) {
|
||||
map.add(currentLocation, currentActor);
|
||||
}
|
||||
actors = new ArrayList<>();
|
||||
displayMessage("You went up the stairs");
|
||||
}
|
||||
}
|
||||
|
||||
public void goDown() {
|
||||
if (currentLVL > 0) {
|
||||
map = maps.get(--currentLVL);
|
||||
if (!map.has(currentLocation, currentActor)) {
|
||||
map.add(currentLocation, currentActor);
|
||||
}
|
||||
actors = new ArrayList<>();
|
||||
displayMessage("You went down the stairs");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the damage done against the current target.
|
||||
*
|
||||
@@ -270,10 +289,13 @@ public class Game implements IGame {
|
||||
kill();
|
||||
}
|
||||
while (!actors.isEmpty()) {
|
||||
// get the next player or non-player in the queue
|
||||
currentActor = actors.remove(0);
|
||||
if (currentActor.isDestroyed()) // skip if it's dead
|
||||
continue;
|
||||
// get the next player or non-player in the queue
|
||||
currentActor = actors.remove(0);
|
||||
if (currentActor == null) {
|
||||
return false; //TODO: Find out why a girl suddenly becomes null (only after map change, not caught in beginTurn)
|
||||
}
|
||||
if (currentActor.isDestroyed()) // skip if it's dead
|
||||
continue;
|
||||
currentLocation = map.getLocation(currentActor);
|
||||
if (currentLocation == null) {
|
||||
displayDebug("doTurn(): Whoops! Actor has disappeared from the map: " + currentActor);
|
||||
@@ -310,7 +332,7 @@ public class Game implements IGame {
|
||||
/**
|
||||
* Player is dead. It needs to be properly killed off.
|
||||
*/
|
||||
public void kill() {
|
||||
private void kill() {
|
||||
map.remove(currentLocation, currentActor);
|
||||
currentActor = null;
|
||||
currentLocation = null;
|
||||
@@ -330,13 +352,33 @@ public class Game implements IGame {
|
||||
System.err.println("Map not found – falling back to builtin map");
|
||||
inputGrid = MapReader.readString(Main.BUILTIN_MAP);
|
||||
}
|
||||
this.map = new GameMap(inputGrid.getArea());
|
||||
IGameMap map = new GameMap(inputGrid.getArea());
|
||||
for (ILocation loc : inputGrid.locations()) {
|
||||
IItem item = createItem(inputGrid.get(loc));
|
||||
if (item != null) {
|
||||
map.add(loc, item);
|
||||
}
|
||||
}
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
private void loadMap(String mapName, int lvl) {
|
||||
IGrid<String> inputGrid = MapReader.readFile("maps/" + mapName);
|
||||
if (inputGrid == null) {
|
||||
System.err.println("Map not found – falling back to builtin map");
|
||||
inputGrid = MapReader.readString(Main.BUILTIN_MAP);
|
||||
}
|
||||
IGameMap map = new GameMap(inputGrid.getArea());
|
||||
for (ILocation loc : inputGrid.locations()) {
|
||||
IItem item = createItem(inputGrid.get(loc));
|
||||
if (item instanceof Chest) {
|
||||
((Chest) item).fill(lvl);
|
||||
}
|
||||
if (item != null) {
|
||||
map.add(loc, item);
|
||||
}
|
||||
}
|
||||
maps.add(map);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -399,6 +441,11 @@ public class Game implements IGame {
|
||||
itemFactories.put("s", Staff::new);
|
||||
itemFactories.put("b", Bow::new);
|
||||
itemFactories.put("H", HealthPotion::new);
|
||||
itemFactories.put("=", FakeWall::new);
|
||||
itemFactories.put("<", StairsUp::new);
|
||||
itemFactories.put(">", StairsDown::new);
|
||||
itemFactories.put("m", Binoculars::new);
|
||||
itemFactories.put("f", Shield::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user