Skip to content
Snippets Groups Projects
Commit d9f62c3a authored by Chris Kearney's avatar Chris Kearney
Browse files

Well, building works.

parent a9756267
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ package com.comandante.creeper.server.command.admin; ...@@ -2,6 +2,7 @@ package com.comandante.creeper.server.command.admin;
import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.managers.GameManager;
import com.comandante.creeper.player.Player; import com.comandante.creeper.player.Player;
import com.comandante.creeper.player.PlayerMovement;
import com.comandante.creeper.server.ChannelUtils; import com.comandante.creeper.server.ChannelUtils;
import com.comandante.creeper.server.CreeperSession; import com.comandante.creeper.server.CreeperSession;
import com.comandante.creeper.server.command.Command; import com.comandante.creeper.server.command.Command;
...@@ -56,7 +57,7 @@ public class BuildCommand extends Command { ...@@ -56,7 +57,7 @@ public class BuildCommand extends Command {
mapMatrix.addRow(true); mapMatrix.addRow(true);
coords = new Coords(0, roomCoords.column); coords = new Coords(0, roomCoords.column);
} }
buildBasicRoom(currentRoom, coords, mapMatrix); buildBasicRoom(player, currentRoom, coords, mapMatrix);
utils.write(playerId, "Room created."); utils.write(playerId, "Room created.");
return; return;
} else { } else {
...@@ -68,7 +69,7 @@ public class BuildCommand extends Command { ...@@ -68,7 +69,7 @@ public class BuildCommand extends Command {
if (coords.getRow() >= mapMatrix.getMaxRow()) { if (coords.getRow() >= mapMatrix.getMaxRow()) {
mapMatrix.addRow(false); mapMatrix.addRow(false);
} }
buildBasicRoom(currentRoom, coords, mapMatrix); buildBasicRoom(player, currentRoom, coords, mapMatrix);
utils.write(playerId, "Room created."); utils.write(playerId, "Room created.");
return; return;
} else { } else {
...@@ -76,7 +77,12 @@ public class BuildCommand extends Command { ...@@ -76,7 +77,12 @@ public class BuildCommand extends Command {
} }
} else if (desiredBuildDirection.equalsIgnoreCase("e") | desiredBuildDirection.equalsIgnoreCase("east")) { } else if (desiredBuildDirection.equalsIgnoreCase("e") | desiredBuildDirection.equalsIgnoreCase("east")) {
if (!currentRoom.getEastId().isPresent() && mapMatrix.getEast(currentRoom.getRoomId()) == 0) { if (!currentRoom.getEastId().isPresent() && mapMatrix.getEast(currentRoom.getRoomId()) == 0) {
buildBasicRoom(currentRoom, new Coords(roomCoords.row, roomCoords.column + 1), mapMatrix); Coords coords = new Coords(roomCoords.row, roomCoords.column + 1);
if (coords.getColumn() >= mapMatrix.getMaxCol()) {
mapMatrix.addColumn(false);
coords = new Coords(roomCoords.row, roomCoords.column + 1);
}
buildBasicRoom(player, currentRoom, coords, mapMatrix);
utils.write(playerId, "Room created."); utils.write(playerId, "Room created.");
return; return;
} else { } else {
...@@ -84,7 +90,12 @@ public class BuildCommand extends Command { ...@@ -84,7 +90,12 @@ public class BuildCommand extends Command {
} }
} else if (desiredBuildDirection.equalsIgnoreCase("w") | desiredBuildDirection.equalsIgnoreCase("west")) { } else if (desiredBuildDirection.equalsIgnoreCase("w") | desiredBuildDirection.equalsIgnoreCase("west")) {
if (!currentRoom.getWestId().isPresent() && mapMatrix.getWest(currentRoom.getRoomId()) == 0) { if (!currentRoom.getWestId().isPresent() && mapMatrix.getWest(currentRoom.getRoomId()) == 0) {
buildBasicRoom(currentRoom, new Coords(roomCoords.row, roomCoords.column - 1), mapMatrix); Coords coords = new Coords(roomCoords.row, roomCoords.column - 1);
if (coords.getColumn() < 0) {
mapMatrix.addColumn(true);
coords = new Coords(roomCoords.row, 0);
}
buildBasicRoom(player, currentRoom, coords, mapMatrix);
utils.write(playerId, "Room created."); utils.write(playerId, "Room created.");
return; return;
} else { } else {
...@@ -96,7 +107,7 @@ public class BuildCommand extends Command { ...@@ -96,7 +107,7 @@ public class BuildCommand extends Command {
} }
} }
private void buildBasicRoom(Room currentRoom, Coords newCords, MapMatrix mapMatrix) { private void buildBasicRoom(Player player, Room currentRoom, Coords newCords, MapMatrix mapMatrix) {
Integer newRroomId = findRoomId(); Integer newRroomId = findRoomId();
mapMatrix.setCoordsValue(newCords, newRroomId); mapMatrix.setCoordsValue(newCords, newRroomId);
BasicRoomBuilder basicRoomBuilder = new BasicRoomBuilder(); BasicRoomBuilder basicRoomBuilder = new BasicRoomBuilder();
...@@ -124,6 +135,8 @@ public class BuildCommand extends Command { ...@@ -124,6 +135,8 @@ public class BuildCommand extends Command {
rebuildExits(roomManager.getRoom(basicRoom.getWestId().get()), mapMatrix); rebuildExits(roomManager.getRoom(basicRoom.getWestId().get()), mapMatrix);
} }
getGameManager().getMapsManager().generateAllMaps(9, 9); getGameManager().getMapsManager().generateAllMaps(9, 9);
getGameManager().movePlayer(new PlayerMovement(player, currentRoom.getRoomId(), basicRoom.getRoomId(), null, "", ""));
getGameManager().currentRoomLogic(player.getPlayerId());
} }
private void rebuildExits(Room room, MapMatrix mapMatrix) { private void rebuildExits(Room room, MapMatrix mapMatrix) {
......
...@@ -210,4 +210,17 @@ public class MapMatrix { ...@@ -210,4 +210,17 @@ public class MapMatrix {
} }
setMax(new Coords(matrix.size(), matrix.get(0).size())); setMax(new Coords(matrix.size(), matrix.get(0).size()));
} }
public void addColumn(boolean startOfArray) {
Iterator<List<Integer>> rows = getRows();
while (rows.hasNext()) {
List<Integer> next = rows.next();
if (startOfArray) {
next.add(0, 0);
} else {
next.add(0);
}
}
setMax(new Coords(matrix.size(), matrix.get(0).size()));
}
} }
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment