change in Main Method

changed Method getWinner and getCurrentPlayerWinpoints
This commit is contained in:
schrom01 2021-12-03 09:37:19 +01:00
parent 8a494b247b
commit 8811410e44
2 changed files with 19 additions and 20 deletions

View File

@ -13,13 +13,15 @@ public class Siedler {
boolean running = true; boolean running = true;
boolean diceThrown = false; boolean diceThrown = false;
while (running){ while (running){
Config.Faction currentPlayerFaction = game.getCurrentPlayerFaction();
parser.displayGameboard(game.getBoard().getTextView()); parser.displayGameboard(game.getBoard().getTextView());
parser.playerTurn(game.getCurrentPlayerFaction()); parser.playerTurn(currentPlayerFaction);
if(!diceThrown) { if(!diceThrown) {
throwDice(game, parser); throwDice(game, parser);
diceThrown = true; diceThrown = true;
} }
parser.displayPlayerInfo(game.getCurrentPlayerResource(),game.getWinPoints().get(game.getCurrentPlayerFaction()));
parser.displayPlayerInfo(game.getCurrentPlayerResource(), game.getCurrentPlayerWinpoints());
switch (parser.getAction()) { switch (parser.getAction()) {
case NEXTPLAYER: case NEXTPLAYER:
Config.Faction winner = game.getWinner(); Config.Faction winner = game.getWinner();
@ -33,15 +35,21 @@ public class Siedler {
break; break;
case BUILDSETTLEMENT: case BUILDSETTLEMENT:
parser.giveCoordinatesForStructures(Config.Structure.SETTLEMENT); parser.giveCoordinatesForStructures(Config.Structure.SETTLEMENT);
game.buildSettlement(parser.getPoint()); if(!game.buildSettlement(parser.getPoint())){
parser.errorMessage();
}
break; break;
case BUILDCITY: case BUILDCITY:
parser.giveCoordinatesForStructures(Config.Structure.CITY); parser.giveCoordinatesForStructures(Config.Structure.CITY);
game.buildCity(parser.getPoint()); if(!game.buildCity(parser.getPoint())){
parser.errorMessage();
}
break; break;
case BUILDROAD: case BUILDROAD:
parser.giveCoordinatesForStructures(Config.Structure.ROAD); parser.giveCoordinatesForStructures(Config.Structure.ROAD);
game.buildRoad(parser.getPoint(), parser.getPoint()); if(game.buildRoad(parser.getPoint(), parser.getPoint())){
parser.errorMessage();
}
break; break;
case TRADEWITHBANK: case TRADEWITHBANK:
Config.Resource offer = parser.trade(true); Config.Resource offer = parser.trade(true);

View File

@ -314,17 +314,14 @@ public class SiedlerGame {
* @return the winner of the game or null, if there is no winner (yet) * @return the winner of the game or null, if there is no winner (yet)
*/ */
public Faction getWinner() { public Faction getWinner() {
HashMap<Faction, Integer> winPoints = getWinPoints(); if(getCurrentPlayerWinpoints() >= winPointsForWin){
for(Faction faction : winPoints.keySet()){ return getCurrentPlayerFaction();
if(winPoints.get(faction) >= winPointsForWin){
return faction;
}
} }
return null; return null;
} }
public HashMap<Faction, Integer> getWinPoints(){ public int getCurrentPlayerWinpoints(){
HashMap<Faction, Integer> winPoints = new HashMap<>(); int winPoints = 0;
List<Structure> structures = board.getCorners(); List<Structure> structures = board.getCorners();
for(Structure structure : structures) { for(Structure structure : structures) {
@ -334,15 +331,9 @@ public class SiedlerGame {
} else if(structure instanceof Settlement) { } else if(structure instanceof Settlement) {
newWinPoints = 1; newWinPoints = 1;
} }
if(structure.getFaction() == getCurrentPlayerFaction()){
Faction faction = structure.getFaction(); winPoints ++;
if(winPoints.containsKey(faction)) {
winPoints.put(faction, winPoints.get(faction) + newWinPoints);
} }
else {
winPoints.put(faction, newWinPoints);
}
} }
//todo add points for longest road //todo add points for longest road
return winPoints; return winPoints;