From d749838600fca6d99e4908b1c31a3a92a8c37ef1 Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Fri, 3 Dec 2021 08:28:58 +0100 Subject: [PATCH 1/9] fixed Error in trade method in Parser --- src/ch/zhaw/catan/Parser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch/zhaw/catan/Parser.java b/src/ch/zhaw/catan/Parser.java index 0632d9d..86d9f9a 100644 --- a/src/ch/zhaw/catan/Parser.java +++ b/src/ch/zhaw/catan/Parser.java @@ -73,7 +73,7 @@ public class Parser { if (!give){ output = "receive"; } - return textIO.newEnumInputReader(Config.Resource.class).read("Which Resource would you like to " + give ); + return textIO.newEnumInputReader(Config.Resource.class).read("Which Resource would you like to " + output ); } } From 57649df6baba4218d2a34216ba0ead453d5f5053 Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Fri, 3 Dec 2021 08:32:51 +0100 Subject: [PATCH 2/9] Fixed grammar error in method displayPlayerResource Stock. --- src/ch/zhaw/catan/Parser.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/ch/zhaw/catan/Parser.java b/src/ch/zhaw/catan/Parser.java index 86d9f9a..6421d23 100644 --- a/src/ch/zhaw/catan/Parser.java +++ b/src/ch/zhaw/catan/Parser.java @@ -25,10 +25,10 @@ public class Parser { textTerminal.println(gameboard); } - public void displayPlayerResourceStock(HashMap curruntPlayerResource){ + public void displayPlayerResourceStock(HashMap currentPlayerResource){ textTerminal.println("You own the follwing Resources"); - for(Config.Resource resource : curruntPlayerResource.keySet()){ - textTerminal.println(resource.name() + ":" + curruntPlayerResource.get(resource)); + for(Config.Resource resource : currentPlayerResource.keySet()){ + textTerminal.println(resource.name() + ":" + currentPlayerResource.get(resource)); } } @@ -52,8 +52,6 @@ public class Parser { public void thrownDices(int number){ textTerminal.println ("Dices have been thrown, the combined value is: " + number); - - } public void playerTurn(Config.Faction faction) { From f60b65af83f537374bedd20cf280a167984f488a Mon Sep 17 00:00:00 2001 From: schrom01 Date: Fri, 3 Dec 2021 08:34:48 +0100 Subject: [PATCH 3/9] fixed Error in Main Method --- src/ch/zhaw/catan/Siedler.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ch/zhaw/catan/Siedler.java b/src/ch/zhaw/catan/Siedler.java index df3fc8d..ca591ef 100644 --- a/src/ch/zhaw/catan/Siedler.java +++ b/src/ch/zhaw/catan/Siedler.java @@ -30,14 +30,14 @@ public class Siedler { switch (parser.getAction()) { case NEXTPLAYER: Config.Faction winner = game.getWinner(); - if(winner == null) { + if(winner == null && false) { //todo remove false game.switchToNextPlayer(); diceThrown = false; - break; } else { - parser.displayWinnertext(winner); + parser.displayWinnertext(game.getCurrentPlayerFaction());//todo replace with winner running = false; } + break; case BUILDSETTLEMENT: parser.giveCoordinatesForStructures(Config.Structure.SETTLEMENT); game.buildSettlement(parser.getPoint()); From 1e49424b9ce03bd518ac28396b85c106ef62498f Mon Sep 17 00:00:00 2001 From: schrom01 Date: Fri, 3 Dec 2021 08:35:37 +0100 Subject: [PATCH 4/9] fixed Error in Main Method --- src/ch/zhaw/catan/Siedler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch/zhaw/catan/Siedler.java b/src/ch/zhaw/catan/Siedler.java index ca591ef..d97cdb8 100644 --- a/src/ch/zhaw/catan/Siedler.java +++ b/src/ch/zhaw/catan/Siedler.java @@ -30,11 +30,11 @@ public class Siedler { switch (parser.getAction()) { case NEXTPLAYER: Config.Faction winner = game.getWinner(); - if(winner == null && false) { //todo remove false + if(winner == null) { game.switchToNextPlayer(); diceThrown = false; } else { - parser.displayWinnertext(game.getCurrentPlayerFaction());//todo replace with winner + parser.displayWinnertext(winner); running = false; } break; From ff734bce2355949630f6fd8b47ef92a51d38679e Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Fri, 3 Dec 2021 08:48:26 +0100 Subject: [PATCH 5/9] Delected CommandWords.java added quit Method in Parser Fixed minor grammar mistakes in Siedler Game --- src/ch/zhaw/catan/CommandWords.java | 4 ---- src/ch/zhaw/catan/Parser.java | 17 ++++++++++++++--- src/ch/zhaw/catan/SiedlerGame.java | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) delete mode 100644 src/ch/zhaw/catan/CommandWords.java diff --git a/src/ch/zhaw/catan/CommandWords.java b/src/ch/zhaw/catan/CommandWords.java deleted file mode 100644 index d67b327..0000000 --- a/src/ch/zhaw/catan/CommandWords.java +++ /dev/null @@ -1,4 +0,0 @@ -package ch.zhaw.catan; - -public class CommandWords { -} diff --git a/src/ch/zhaw/catan/Parser.java b/src/ch/zhaw/catan/Parser.java index 6421d23..1a4c6dd 100644 --- a/src/ch/zhaw/catan/Parser.java +++ b/src/ch/zhaw/catan/Parser.java @@ -25,15 +25,16 @@ public class Parser { textTerminal.println(gameboard); } - public void displayPlayerResourceStock(HashMap currentPlayerResource){ - textTerminal.println("You own the follwing Resources"); + public void displayPlayerInfo(HashMap currentPlayerResource, int winpoints){ + textTerminal.println("You are currently holding" + winpoints + " winpoints."); + textTerminal.println("You own the follwing resources:"); for(Config.Resource resource : currentPlayerResource.keySet()){ textTerminal.println(resource.name() + ":" + currentPlayerResource.get(resource)); } } public void displayWinnertext(Config.Faction winner){ - textTerminal.println(winner.name() + "won the game!"); + textTerminal.println(winner.name() + " won the game!"); } public HashMap gameStart(){ @@ -66,6 +67,11 @@ public class Parser { return textIO.newEnumInputReader(Command.class).read("What would you like to do?"); } + /** + * + * @param give if true ask for resource to give if false for resource to receive + * @return + */ public Config.Resource trade(boolean give) { String output = "give"; if (!give){ @@ -73,5 +79,10 @@ public class Parser { } return textIO.newEnumInputReader(Config.Resource.class).read("Which Resource would you like to " + output ); } + public void quit(){ + textTerminal.dispose(); + textIO.dispose(); + } + } diff --git a/src/ch/zhaw/catan/SiedlerGame.java b/src/ch/zhaw/catan/SiedlerGame.java index 9559984..ff80402 100644 --- a/src/ch/zhaw/catan/SiedlerGame.java +++ b/src/ch/zhaw/catan/SiedlerGame.java @@ -130,7 +130,7 @@ public class SiedlerGame { return allPlayers.get(activePlayer).getSpecificResource(resource); } - public HashMap getCurruntPlayerResource() { + public HashMap getCurrentPlayerResource() { return allPlayers.get(activePlayer).getResources(); } From c387420ca8c98f9d94d6c2e50555ca7b24e8d3bd Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Fri, 3 Dec 2021 08:52:26 +0100 Subject: [PATCH 6/9] Siedler Class minor bug fixes --- src/ch/zhaw/catan/Siedler.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/ch/zhaw/catan/Siedler.java b/src/ch/zhaw/catan/Siedler.java index d97cdb8..3149132 100644 --- a/src/ch/zhaw/catan/Siedler.java +++ b/src/ch/zhaw/catan/Siedler.java @@ -1,15 +1,8 @@ package ch.zhaw.catan; -import org.beryx.textio.TextIO; -import org.beryx.textio.TextIoFactory; -import org.beryx.textio.TextTerminal; - import java.util.HashMap; import java.util.Random; -import static ch.zhaw.catan.Command.*; -import static ch.zhaw.catan.Command.QUIT; - public class Siedler { public static void main(String[] args) { @@ -26,7 +19,7 @@ public class Siedler { throwDice(game, parser); diceThrown = true; } - parser.displayPlayerResourceStock(game.getCurruntPlayerResource()); + parser.displayPlayerInfo(game.getCurrentPlayerResource(),1); switch (parser.getAction()) { case NEXTPLAYER: Config.Faction winner = game.getWinner(); From 7d1a326dc016e19b3865776e8564a49ccaae3be9 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Fri, 3 Dec 2021 08:54:27 +0100 Subject: [PATCH 7/9] change in Main Method --- src/ch/zhaw/catan/Siedler.java | 3 ++- src/ch/zhaw/catan/SiedlerGame.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch/zhaw/catan/Siedler.java b/src/ch/zhaw/catan/Siedler.java index 3149132..c446197 100644 --- a/src/ch/zhaw/catan/Siedler.java +++ b/src/ch/zhaw/catan/Siedler.java @@ -19,7 +19,7 @@ public class Siedler { throwDice(game, parser); diceThrown = true; } - parser.displayPlayerInfo(game.getCurrentPlayerResource(),1); + parser.displayPlayerInfo(game.getCurrentPlayerResource(),game.getWinPoints().get(game.getCurrentPlayerFaction())); switch (parser.getAction()) { case NEXTPLAYER: Config.Faction winner = game.getWinner(); @@ -64,6 +64,7 @@ public class Siedler { Random random = new Random(); //sum of two integers from 0-5 + 2 --> sum of two integers from 1-6 int thrownDices = random.nextInt(6) + random.nextInt(6) + 2; + //todo check if 7 parser.thrownDices(thrownDices); game.throwDice(thrownDices); } diff --git a/src/ch/zhaw/catan/SiedlerGame.java b/src/ch/zhaw/catan/SiedlerGame.java index ff80402..8298fd9 100644 --- a/src/ch/zhaw/catan/SiedlerGame.java +++ b/src/ch/zhaw/catan/SiedlerGame.java @@ -323,7 +323,7 @@ public class SiedlerGame { return null; } - private HashMap getWinPoints(){ + public HashMap getWinPoints(){ HashMap winPoints = new HashMap<>(); List structures = board.getCorners(); for(Structure structure : structures) { From 8a494b247bb500208dae8a15f8344fc18b1ae406 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Fri, 3 Dec 2021 09:01:24 +0100 Subject: [PATCH 8/9] change in Main Method --- src/ch/zhaw/catan/Siedler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch/zhaw/catan/Siedler.java b/src/ch/zhaw/catan/Siedler.java index c446197..5088591 100644 --- a/src/ch/zhaw/catan/Siedler.java +++ b/src/ch/zhaw/catan/Siedler.java @@ -52,7 +52,7 @@ public class Siedler { break; case QUIT: running = false; - //todo close window + parser.quit(); break; default: parser.errorMessage(); From 8811410e442ada497f6c493d977cc75714dab8e8 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Fri, 3 Dec 2021 09:37:19 +0100 Subject: [PATCH 9/9] change in Main Method changed Method getWinner and getCurrentPlayerWinpoints --- src/ch/zhaw/catan/Siedler.java | 18 +++++++++++++----- src/ch/zhaw/catan/SiedlerGame.java | 21 ++++++--------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/ch/zhaw/catan/Siedler.java b/src/ch/zhaw/catan/Siedler.java index 5088591..8549296 100644 --- a/src/ch/zhaw/catan/Siedler.java +++ b/src/ch/zhaw/catan/Siedler.java @@ -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); diff --git a/src/ch/zhaw/catan/SiedlerGame.java b/src/ch/zhaw/catan/SiedlerGame.java index 8298fd9..4df7ee6 100644 --- a/src/ch/zhaw/catan/SiedlerGame.java +++ b/src/ch/zhaw/catan/SiedlerGame.java @@ -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 winPoints = getWinPoints(); - for(Faction faction : winPoints.keySet()){ - if(winPoints.get(faction) >= winPointsForWin){ - return faction; - } + if(getCurrentPlayerWinpoints() >= winPointsForWin){ + return getCurrentPlayerFaction(); } return null; } - public HashMap getWinPoints(){ - HashMap winPoints = new HashMap<>(); + public int getCurrentPlayerWinpoints(){ + int winPoints = 0; List 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;