From c28efe5331e04c4b16bb6c6da461226a3f694879 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Thu, 9 Dec 2021 15:23:34 +0100 Subject: [PATCH 1/2] Using Values of Config in SiedlerGame.java --- src/ch/zhaw/catan/SiedlerGame.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch/zhaw/catan/SiedlerGame.java b/src/ch/zhaw/catan/SiedlerGame.java index 6999147..68af8ab 100644 --- a/src/ch/zhaw/catan/SiedlerGame.java +++ b/src/ch/zhaw/catan/SiedlerGame.java @@ -35,7 +35,7 @@ public class SiedlerGame { * three or players is not between two and four */ public SiedlerGame(int winPoints, int numberOfPlayers) { - if(winPoints < 3 || numberOfPlayers < 2 || numberOfPlayers > 4) { + if(winPoints < 3 || numberOfPlayers < Config.MIN_NUMBER_OF_PLAYERS || numberOfPlayers > 4) { throw new IllegalArgumentException(); } bank = new Bank(); @@ -246,7 +246,7 @@ public class SiedlerGame { resourceArrayList.add(resource); } } - if(resourceArrayList.size() > 7){ + if(resourceArrayList.size() > Config.MAX_CARDS_IN_HAND_NO_DROP){ int resourcesToRemove =resourceArrayList.size() - (resourceArrayList.size() / 2); Random random = new Random(); for(int i = 0; i < resourcesToRemove; i++){ From 9983d3ea1d338e27d71bd746379153d904bde571 Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Thu, 9 Dec 2021 15:23:39 +0100 Subject: [PATCH 2/2] Deleted Dummy Class and minor fixes in several classes and use of Config Value MINPLAYER --- src/ch/zhaw/catan/Bank.java | 3 +- src/ch/zhaw/catan/City.java | 2 +- src/ch/zhaw/catan/Command.java | 5 ++- src/ch/zhaw/catan/Dummy.java | 58 ---------------------------------- src/ch/zhaw/catan/Parser.java | 2 +- src/ch/zhaw/catan/Player.java | 3 +- src/ch/zhaw/catan/Road.java | 4 +-- 7 files changed, 9 insertions(+), 68 deletions(-) delete mode 100644 src/ch/zhaw/catan/Dummy.java diff --git a/src/ch/zhaw/catan/Bank.java b/src/ch/zhaw/catan/Bank.java index 39e7319..f82f19b 100644 --- a/src/ch/zhaw/catan/Bank.java +++ b/src/ch/zhaw/catan/Bank.java @@ -1,11 +1,10 @@ package ch.zhaw.catan; import java.util.HashMap; -import java.util.List; public class Bank { - private HashMap resources = new HashMap<>(); + private final HashMap resources = new HashMap<>(); public Bank(){ resources.putAll(Config.INITIAL_RESOURCE_CARDS_BANK); diff --git a/src/ch/zhaw/catan/City.java b/src/ch/zhaw/catan/City.java index a976267..5e68330 100644 --- a/src/ch/zhaw/catan/City.java +++ b/src/ch/zhaw/catan/City.java @@ -1,6 +1,6 @@ package ch.zhaw.catan; -import java.awt.*; +import java.awt.Point; public class City extends Settlement { diff --git a/src/ch/zhaw/catan/Command.java b/src/ch/zhaw/catan/Command.java index 7e7b24e..9a96ed3 100644 --- a/src/ch/zhaw/catan/Command.java +++ b/src/ch/zhaw/catan/Command.java @@ -1,12 +1,11 @@ package ch.zhaw.catan; -import org.beryx.textio.TextIO; - +//TODO:JavaDoc public enum Command { NEXTPLAYER ("next player"), BUILDSETTLEMENT ("build settlement"), BUILDCITY("build city"), BUILDROAD("build road"), TRADEWITHBANK("trade with bank"),QUIT("quit"); - private String commandWord; + private final String commandWord; diff --git a/src/ch/zhaw/catan/Dummy.java b/src/ch/zhaw/catan/Dummy.java deleted file mode 100644 index bf94f5f..0000000 --- a/src/ch/zhaw/catan/Dummy.java +++ /dev/null @@ -1,58 +0,0 @@ -package ch.zhaw.catan; - -import ch.zhaw.catan.Config.Land; -import ch.zhaw.hexboard.Label; -import java.awt.Point; -import java.util.HashMap; -import java.util.Map; -import org.beryx.textio.TextIO; -import org.beryx.textio.TextIoFactory; -import org.beryx.textio.TextTerminal; - -public class Dummy { - - public enum Actions { - SHOW, QUIT - } - - private void run() { - TextIO textIO = TextIoFactory.getTextIO(); - TextTerminal textTerminal = textIO.getTextTerminal(); - SiedlerBoard board = new SiedlerBoard(); - board.addField(new Point(2, 2), Land.FOREST); - board.setCorner(new Point(3, 3), new Settlement(Config.Faction.RED,new Point(3, 3))); - board.setEdge(new Point(2, 0), new Point(3, 1), new Road(Config.Faction.BLUE,new Point(2, 0),new Point(2, 0))); - board.addFieldAnnotation(new Point(2, 2), new Point(3, 1), "AA"); - - Map lowerFieldLabel = new HashMap<>(); - lowerFieldLabel.put(new Point(2, 2), new Label('0', '9')); - SiedlerBoardTextView view = new SiedlerBoardTextView(board); - - for (Map.Entry e : lowerFieldLabel.entrySet()) { - view.setLowerFieldLabel(e.getKey(), e.getValue()); - } - - boolean running = true; - while (running) { - switch (getEnumValue(textIO, Actions.class)) { - case SHOW: - textTerminal.println(view.toString()); - break; - case QUIT: - running = false; - break; - default: - throw new IllegalStateException("Internal error found - Command not implemented."); - } - } - textIO.dispose(); - } - - public static > T getEnumValue(TextIO textIO, Class commands) { - return textIO.newEnumInputReader(commands).read("What would you like to do?"); - } - - public static void main(String[] args) { - new Dummy().run(); - } -} diff --git a/src/ch/zhaw/catan/Parser.java b/src/ch/zhaw/catan/Parser.java index 2f1bc69..b572dd2 100644 --- a/src/ch/zhaw/catan/Parser.java +++ b/src/ch/zhaw/catan/Parser.java @@ -76,7 +76,7 @@ public class Parser { */ public HashMap gameStart() { HashMap gameStartValues = new HashMap<>(); - gameStartValues.put("NumberOfPlayers", textIO.newIntInputReader().withMinVal(2).withMaxVal(4).read("Number of players:")); + gameStartValues.put("NumberOfPlayers", textIO.newIntInputReader().withMinVal(Config.MIN_NUMBER_OF_PLAYERS).withMaxVal(4).read("Number of players:")); gameStartValues.put("NumberOfWinPoints", textIO.newIntInputReader().withMinVal(5).withMaxVal(15).read("Winpoints needed for Victory:")); return gameStartValues; } diff --git a/src/ch/zhaw/catan/Player.java b/src/ch/zhaw/catan/Player.java index fc378a0..5b3b5cf 100644 --- a/src/ch/zhaw/catan/Player.java +++ b/src/ch/zhaw/catan/Player.java @@ -1,6 +1,7 @@ package ch.zhaw.catan; -import java.util.*; +import java.util.HashMap; +import java.util.List; /** * New Class PLayer diff --git a/src/ch/zhaw/catan/Road.java b/src/ch/zhaw/catan/Road.java index 1bc37a5..e43a6a7 100644 --- a/src/ch/zhaw/catan/Road.java +++ b/src/ch/zhaw/catan/Road.java @@ -1,10 +1,10 @@ package ch.zhaw.catan; -import java.awt.*; +import java.awt.Point; public class Road extends Structure { - private Point start,end; + private final Point start,end; public Road(Config.Faction faction,Point start,Point end) {