created method storeResourceToBank in Bank.java
adapted method buildRoad and buildSettlement in SiedlerGame.java
This commit is contained in:
parent
9e347e8792
commit
d6c225a5aa
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_16" project-jdk-name="openjdk-17" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
|
@ -1,10 +0,0 @@
|
|||
<?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>
|
|
@ -1,5 +1,6 @@
|
|||
package ch.zhaw.catan;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Bank {
|
||||
|
@ -10,6 +11,12 @@ public class Bank {
|
|||
|
||||
}
|
||||
|
||||
public void storeResourceToBank(List<Config.Resource> resourceToGive) {
|
||||
for (Config.Resource resource : resourceToGive) {
|
||||
resources.put(resource,resources.get(resource)+1);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getResourceFromBank(Config.Resource resource,int numberOfResources) {
|
||||
if(resources.get(resource) >= numberOfResources) {
|
||||
Integer newResourceNumber = resources.get(resource) - numberOfResources;
|
||||
|
|
|
@ -18,7 +18,6 @@ public class Dummy {
|
|||
private void run() {
|
||||
TextIO textIO = TextIoFactory.getTextIO();
|
||||
TextTerminal<?> textTerminal = textIO.getTextTerminal();
|
||||
|
||||
SiedlerBoard board = new SiedlerBoard();
|
||||
board.addField(new Point(2, 2), Land.FOREST);
|
||||
board.setCorner(new Point(3, 3), new Settlement(Config.Faction.RED));
|
||||
|
|
|
@ -192,23 +192,25 @@ public class SiedlerGame {
|
|||
* @return true, if the placement was successful
|
||||
*/
|
||||
public boolean buildSettlement(Point position) {
|
||||
//1. Check if Edge
|
||||
//1. Check if Corner
|
||||
if (!board.hasCorner(position)) {
|
||||
// TODO: Error message
|
||||
return false;
|
||||
}
|
||||
//2. Check if Edge is empty
|
||||
//2. Check if Corner is empty
|
||||
if (board.getCorner(position) != null) {
|
||||
// TODO: Error message
|
||||
return false;
|
||||
}
|
||||
//3. Can Player build road
|
||||
//3. Can Player build Settlement
|
||||
if (!allPlayers.get(activePlayer).buildSettlement()) {
|
||||
// TODO: Error message
|
||||
return false;
|
||||
}
|
||||
//4. Insert Road to map
|
||||
board.setCorner(position, new Settlement(allPlayers.get(activePlayer).getFaction()));
|
||||
//5. Give Resoure to bank
|
||||
bank.storeResourceToBank(Config.Structure.SETTLEMENT.getCosts());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -262,6 +264,8 @@ public class SiedlerGame {
|
|||
}
|
||||
//4. Insert Road to map
|
||||
board.setEdge(roadStart, roadEnd, new Road(allPlayers.get(activePlayer).getFaction()));
|
||||
//5. Give Resource to bank
|
||||
bank.storeResourceToBank(Config.Structure.ROAD.getCosts());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue