From b30a01956616c9f1dafcf4b1c36194ebc1fbdad7 Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Sun, 28 Nov 2021 01:14:34 +0100 Subject: [PATCH] createFixGamefield method finished and removed depreciated code --- src/ch/zhaw/catan/SiedlerBoard.java | 51 +++++++++-------------------- 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/src/ch/zhaw/catan/SiedlerBoard.java b/src/ch/zhaw/catan/SiedlerBoard.java index 1466d52..361df74 100644 --- a/src/ch/zhaw/catan/SiedlerBoard.java +++ b/src/ch/zhaw/catan/SiedlerBoard.java @@ -13,24 +13,22 @@ public class SiedlerBoard extends HexBoard { Map lowerFieldLabel = new HashMap<>(); public void createFixGamefield(){ - Integer[][] waterCoordinates = {{4,2},{6,2},{8,2},{10,2},{3,5},{11,5},{2,8},{12,8},{1,11}, - {13,11},{2,14},{12,14},{3,17},{11,17},{4,20},{6,20},{8,20},{10,20}}; - Integer[][] desertCoordinates = {{7,11}}; - Integer[][] forestCoordinates = {{5,5,6},{10,8,10},{3,11,5},{8,14,3}}; - Integer[][] hillCoordinates = {{5,11,9},{5,17,8},{9,17,11}}; - Integer[][] fieldCoordinates = {{4,8,2},{8,8,5},{11,11,9},{4,14,10}}; - Integer[][] pastureCoordinates = {{7,5,3},{9,5,8},{10,14,12},{7,17,4}}; - Integer[][] mountainCoordinates = {{6,8,4},{9,11,6},{6,14,11}}; - - placeFieldWithoutLabel(Land.WATER, waterCoordinates); - placeFieldWithoutLabel(Land.DESERT, desertCoordinates); - placeFieldWithLabel(Land.FOREST, forestCoordinates); - placeFieldWithLabel(Land.HILLS, hillCoordinates); - placeFieldWithLabel(Land.FIELDS, fieldCoordinates); - placeFieldWithLabel(Land.PASTURE, pastureCoordinates); - placeFieldWithLabel(Land.MOUNTAIN, mountainCoordinates); - + Map resourcePlacement = Config.getStandardLandPlacement(); + Map dicePlacement = Config.getStandardDiceNumberPlacement(); + for (Map.Entry resourceField : resourcePlacement.entrySet()) { + addField(resourceField.getKey(),resourceField.getValue()); + } + for (Map.Entry diceField : dicePlacement.entrySet()) { + String numberAsString = diceField.getValue().toString(); + char[] numbersInChar = numberAsString.toCharArray(); + if (numberAsString.length() < 2) { + lowerFieldLabel.put(diceField.getKey(), new Label('0', numbersInChar[0])); + } + else { + lowerFieldLabel.put(diceField.getKey(), new Label(numbersInChar[0],numbersInChar[1])); + } + } } @@ -48,23 +46,6 @@ public class SiedlerBoard extends HexBoard { return view.toString(); } - private void placeFieldWithoutLabel(Land fieldType, Integer[][] fieldCoordinates) { - for(Integer[] coordinates : fieldCoordinates) { - addField(new Point(coordinates[0], coordinates[1]), fieldType); - } - } - private void placeFieldWithLabel(Land fieldType, Integer[][] fieldInformation) { - for(Integer[] information : fieldInformation) { - addField(new Point(information[0], information[1]), fieldType); - char[] label = information[2].toString().toCharArray(); - if (label.length == 1) { - lowerFieldLabel.put(new Point(information[0], information[1]), new ch.zhaw.hexboard.Label('0', label[0])); - } else { - lowerFieldLabel.put(new Point(information[0], information[1]), new Label(label[0], label[1])); - } - } - } - //TODO: Add fields, constructors and methods as you see fit. Do NOT change the signature // of the methods below. @@ -110,6 +91,6 @@ public class SiedlerBoard extends HexBoard { else { return Collections.emptyList(); } - return Collections.unmodifiableList(Arrays.asList(lands)); + return List.of(lands); } }