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 diceThrown = false;
while (running){
Config.Faction currentPlayerFaction = game.getCurrentPlayerFaction();
parser.displayGameboard(game.getBoard().getTextView());
parser.playerTurn(game.getCurrentPlayerFaction());
parser.playerTurn(currentPlayerFaction);
if(!diceThrown) {
throwDice(game, parser);
diceThrown = true;
}
parser.displayPlayerInfo(game.getCurrentPlayerResource(),game.getWinPoints().get(game.getCurrentPlayerFaction()));
parser.displayPlayerInfo(game.getCurrentPlayerResource(), game.getCurrentPlayerWinpoints());
switch (parser.getAction()) {
case NEXTPLAYER:
Config.Faction winner = game.getWinner();
@ -33,15 +35,21 @@ public class Siedler {
break;
case BUILDSETTLEMENT:
parser.giveCoordinatesForStructures(Config.Structure.SETTLEMENT);
game.buildSettlement(parser.getPoint());
if(!game.buildSettlement(parser.getPoint())){
parser.errorMessage();
}
break;
case BUILDCITY:
parser.giveCoordinatesForStructures(Config.Structure.CITY);
game.buildCity(parser.getPoint());
if(!game.buildCity(parser.getPoint())){
parser.errorMessage();
}
break;
case BUILDROAD:
parser.giveCoordinatesForStructures(Config.Structure.ROAD);
game.buildRoad(parser.getPoint(), parser.getPoint());
if(game.buildRoad(parser.getPoint(), parser.getPoint())){
parser.errorMessage();
}
break;
case TRADEWITHBANK:
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)
*/
public Faction getWinner() {
HashMap<Faction, Integer> winPoints = getWinPoints();
for(Faction faction : winPoints.keySet()){
if(winPoints.get(faction) >= winPointsForWin){
return faction;
}
if(getCurrentPlayerWinpoints() >= winPointsForWin){
return getCurrentPlayerFaction();
}
return null;
}
public HashMap<Faction, Integer> getWinPoints(){
HashMap<Faction, Integer> winPoints = new HashMap<>();
public int getCurrentPlayerWinpoints(){
int winPoints = 0;
List<Structure> structures = board.getCorners();
for(Structure structure : structures) {
@ -334,15 +331,9 @@ public class SiedlerGame {
} else if(structure instanceof Settlement) {
newWinPoints = 1;
}
Faction faction = structure.getFaction();
if(winPoints.containsKey(faction)) {
winPoints.put(faction, winPoints.get(faction) + newWinPoints);
if(structure.getFaction() == getCurrentPlayerFaction()){
winPoints ++;
}
else {
winPoints.put(faction, newWinPoints);
}
}
//todo add points for longest road
return winPoints;