Merge remote-tracking branch 'origin/main'

This commit is contained in:
Andrin Fassbind 2021-12-03 09:49:01 +01:00
commit a2e7f60836
2 changed files with 37 additions and 4 deletions

View File

@ -13,6 +13,7 @@ public class Player {
private HashMap<Config.Resource,Integer> resources; private HashMap<Config.Resource,Integer> resources;
private int roadsToUse; private int roadsToUse;
private int settlementsToUse; private int settlementsToUse;
private int citiesToUse;
public Player (Config.Faction faction){ public Player (Config.Faction faction){
//Datenfelder //Datenfelder
@ -91,9 +92,9 @@ public class Player {
/** /**
* This method has to be used when a player wants to build a settlement. It checks if a player has enough roads * This method has to be used when a player wants to build a settlement. It checks if a player has enough roads
* and resources to build one more. If player is able to build, the method substract the buildcost from the resources * and resources to build one more. If the player is able to build, this method subtracts the buildcost from the resources
* in possesion by the player. * in possession by the player.
* @return true if road can be created false if road can't be created * @return true if road can be created false if road can't be created.
*/ */
public boolean buildSettlement() { public boolean buildSettlement() {
List<Config.Resource> costs = Config.Structure.SETTLEMENT.getCosts(); List<Config.Resource> costs = Config.Structure.SETTLEMENT.getCosts();
@ -106,6 +107,23 @@ public class Player {
return true; return true;
} }
/**
* This method has to be used when a player wants to build a city. It checks if a player already has a settlement
* on that position and if he has enough resource to build one. If the player is able to build, this method subtracts
* the buildcost from the resources in possession by the player.
* @return true if road can be created false if road can't be created.
*/
public boolean buildCity() {
List<Config.Resource> costs = Config.Structure.CITY.getCosts();
if ( citiesToUse == 0 || !checkRessourceToBuild(costs)){
return false;
}
for (Config.Resource resource : costs){
resources.put(resource,resources.get(resource)-1);
}
return true;
}
//returns true if player has enough resources else false //returns true if player has enough resources else false
private boolean checkRessourceToBuild(List<Config.Resource> liste) { private boolean checkRessourceToBuild(List<Config.Resource> liste) {
for (Config.Resource resource : liste) { for (Config.Resource resource : liste) {

View File

@ -218,7 +218,7 @@ public class SiedlerGame {
} }
//4. Insert Settlement to map //4. Insert Settlement to map
board.setCorner(position, new Settlement(allPlayers.get(activePlayer).getFaction())); board.setCorner(position, new Settlement(allPlayers.get(activePlayer).getFaction()));
//5. Give Resoure to bank //5. Give Resources to bank
bank.storeResourceToBank(Config.Structure.SETTLEMENT.getCosts()); bank.storeResourceToBank(Config.Structure.SETTLEMENT.getCosts());
return true; return true;
} }
@ -238,6 +238,21 @@ public class SiedlerGame {
*/ */
public boolean buildCity(Point position) { public boolean buildCity(Point position) {
// TODO: OPTIONAL task - Implement // TODO: OPTIONAL task - Implement
//1. Check if Corner.
if (!board.hasCorner(position)){
return false;
}
//2. Check if Settlement has already been built
Settlement atCurrentPosition = (Settlement) board.getCorner(position);
//3. Can player build a City.
if(!allPlayers.get(activePlayer).buildCity()){
return false;
}
//4.Insert City into the map.
board.setCorner(position,new City(allPlayers.get(activePlayer).getFaction()));
//5. Give resources to the bank.
bank.storeResourceToBank(Config.Structure.CITY.getCosts());
return false; return false;
} }