Merge remote-tracking branch 'refs/remotes/origin/main'

main
Brett 2023-04-15 21:12:12 -04:00
commit b336a143a6
4 changed files with 37 additions and 5 deletions

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
</set>
</option>
</component>
</project>

View File

@ -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);
}

View File

@ -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();
}

View File

@ -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;
}