SiedlerGame throwDice method implemented (for 7 not yet implemented) and method getResourcesforFaction implemented in SiedlerBoard

This commit is contained in:
Leonardo Brandenberger 2021-12-03 16:39:11 +01:00
parent 8b2b9e2882
commit 7129435fea
3 changed files with 29 additions and 3 deletions

View File

@ -26,7 +26,7 @@ public class Parser {
} }
public void displayPlayerInfo(HashMap<Config.Resource, Integer> currentPlayerResource, int winpoints){ public void displayPlayerInfo(HashMap<Config.Resource, Integer> currentPlayerResource, int winpoints){
textTerminal.println("You are currently holding" + winpoints + " winpoints."); textTerminal.println("You are currently holding " + winpoints + " winpoints.");
textTerminal.println("You own the follwing resources:"); textTerminal.println("You own the follwing resources:");
for(Config.Resource resource : currentPlayerResource.keySet()){ for(Config.Resource resource : currentPlayerResource.keySet()){
textTerminal.println(resource.name() + ":" + currentPlayerResource.get(resource)); textTerminal.println(resource.name() + ":" + currentPlayerResource.get(resource));

View File

@ -66,6 +66,21 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
return fields; return fields;
} }
public ArrayList<Config.Resource> getResourcesforFaction(Point point, Config.Faction faction){
List <Settlement> possibleSettlementField = super.getCornersOfField(point);
ArrayList<Config.Resource> resourcesToPlayer = new ArrayList<>();
for (Structure structure : possibleSettlementField) {
if (structure.getFaction() == faction) {
resourcesToPlayer.add(fields.get(point).getResource());
if (structure instanceof City) {
resourcesToPlayer.add(fields.get(point).getResource());
}
}
}
return resourcesToPlayer;
}
/** /**
* Returns the {@link Land}s adjacent to the specified corner. * Returns the {@link Land}s adjacent to the specified corner.
* *

View File

@ -198,8 +198,19 @@ public class SiedlerGame {
* @return the resource cards added to the stock of the different players * @return the resource cards added to the stock of the different players
*/ */
public Map<Faction, List<Resource>> throwDice(int dicethrow) { public Map<Faction, List<Resource>> throwDice(int dicethrow) {
// TODO: Implement Map<Faction,List<Resource>> returnMap= new HashMap<>();
return null; List<Point> diceValueFields = board.getFieldsForDiceValue(dicethrow);
for (Player player : allPlayers) {
returnMap.put(player.getFaction(), new ArrayList());
for (Point field : diceValueFields) {
List<Resource> resources= board.getResourcesforFaction(field,player.getFaction());
for (Config.Resource resource : resources){
returnMap.get(player.getFaction()).add(resource);
player.addResource(resource,1);
}
}
}
return returnMap;
} }
/** /**