diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..797acea --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/Assignment 4/src/ca/cosc3p91/a4/game/GameEngine.java b/Assignment 4/src/ca/cosc3p91/a4/game/GameEngine.java index 1ae1fca..b5240df 100644 --- a/Assignment 4/src/ca/cosc3p91/a4/game/GameEngine.java +++ b/Assignment 4/src/ca/cosc3p91/a4/game/GameEngine.java @@ -139,7 +139,7 @@ public class GameEngine { return score; } - public void updateMap(Map map) { + public synchronized void updateMap(Map map) { for (int i = 0; i < map.contains.size(); i++) { if ((map.contains.get(i) instanceof ResourceBuilding)) { ((ResourceBuilding) map.contains.get(i)).update(map.getTownHall()); @@ -147,7 +147,7 @@ public class GameEngine { } } - public boolean build (Map map, String buildingArg) { + public synchronized boolean build (Map map, String buildingArg) { BuildingFactory bfactory = new BuildingFactory(); Building type = bfactory.getBuilding(buildingArg); return map.build(new Tile(), type); @@ -159,7 +159,7 @@ public class GameEngine { return map.train(type); } - public boolean upgradeBuilding (Map map, int buildingIndex) { + public synchronized boolean upgradeBuilding (Map map, int buildingIndex) { return map.upgradeBuilding(buildingIndex); } diff --git a/Assignment 4/src/ca/cosc3p91/a4/util/network/Client.java b/Assignment 4/src/ca/cosc3p91/a4/util/network/Client.java index 5b33716..8b1f9d8 100644 --- a/Assignment 4/src/ca/cosc3p91/a4/util/network/Client.java +++ b/Assignment 4/src/ca/cosc3p91/a4/util/network/Client.java @@ -36,7 +36,23 @@ public class Client implements Runnable { continue; if (prompt.charAt(0) == '6') break; - + switch (prompt.charAt(0)) { + case '1': + Message.Sent buildMessage = new Message.Sent(PacketTable.BUILD,0,++lastMessageID); + buildMessage.getData().write(prompt.substring(1).getBytes()); + sendMessage(buildMessage); + break; + case '2': + Message.Sent trainMessage = new Message.Sent(PacketTable.TRAIN,0,++lastMessageID); + trainMessage.getData().write(prompt.substring(1).getBytes()); + sendMessage(trainMessage); + break; + case '3': + Message.Sent upgradeMessage = new Message.Sent(PacketTable.UPGRADE,0,++lastMessageID); + upgradeMessage.getData().write(prompt.substring(1).getBytes()); + sendMessage(upgradeMessage); + break; + } view.printGameMenu(); } diff --git a/Assignment 4/src/ca/cosc3p91/a4/util/network/PacketTable.java b/Assignment 4/src/ca/cosc3p91/a4/util/network/PacketTable.java index a97bdaf..eab7859 100644 --- a/Assignment 4/src/ca/cosc3p91/a4/util/network/PacketTable.java +++ b/Assignment 4/src/ca/cosc3p91/a4/util/network/PacketTable.java @@ -16,7 +16,13 @@ public class PacketTable { public static final byte ACK = 0x3; // messageHeader, UTF8 String with length information (use DOS.writeUTF/DIS.readUTF) public static final byte MESSAGE = 0x4; + // messageHeader, build + public static final byte BUILD = 0x5; + // messageHeader, train + public static final byte TRAIN = 0x6; + // messageHeader, upgrade + public static final byte UPGRADE = 0x7; // messageHeader, serial packets with map info - public static final byte MAP_DATA = 0x5; + public static final byte USER_MAP_DATA = 0x8; }