Merge remote-tracking branch 'refs/remotes/origin/main'
commit
b336a143a6
|
@ -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>
|
|
@ -139,7 +139,7 @@ public class GameEngine {
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateMap(Map map) {
|
public synchronized void updateMap(Map map) {
|
||||||
for (int i = 0; i < map.contains.size(); i++) {
|
for (int i = 0; i < map.contains.size(); i++) {
|
||||||
if ((map.contains.get(i) instanceof ResourceBuilding)) {
|
if ((map.contains.get(i) instanceof ResourceBuilding)) {
|
||||||
((ResourceBuilding) map.contains.get(i)).update(map.getTownHall());
|
((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();
|
BuildingFactory bfactory = new BuildingFactory();
|
||||||
Building type = bfactory.getBuilding(buildingArg);
|
Building type = bfactory.getBuilding(buildingArg);
|
||||||
return map.build(new Tile(), type);
|
return map.build(new Tile(), type);
|
||||||
|
@ -159,7 +159,7 @@ public class GameEngine {
|
||||||
return map.train(type);
|
return map.train(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean upgradeBuilding (Map map, int buildingIndex) {
|
public synchronized boolean upgradeBuilding (Map map, int buildingIndex) {
|
||||||
return map.upgradeBuilding(buildingIndex);
|
return map.upgradeBuilding(buildingIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,23 @@ public class Client implements Runnable {
|
||||||
continue;
|
continue;
|
||||||
if (prompt.charAt(0) == '6')
|
if (prompt.charAt(0) == '6')
|
||||||
break;
|
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.printGameMenu();
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,13 @@ public class PacketTable {
|
||||||
public static final byte ACK = 0x3;
|
public static final byte ACK = 0x3;
|
||||||
// messageHeader, UTF8 String with length information (use DOS.writeUTF/DIS.readUTF)
|
// messageHeader, UTF8 String with length information (use DOS.writeUTF/DIS.readUTF)
|
||||||
public static final byte MESSAGE = 0x4;
|
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
|
// messageHeader, serial packets with map info
|
||||||
public static final byte MAP_DATA = 0x5;
|
public static final byte USER_MAP_DATA = 0x8;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue