diff --git a/src/ch/zhaw/catan/Field.java b/src/ch/zhaw/catan/Field.java index 38a4774..1da46c7 100644 --- a/src/ch/zhaw/catan/Field.java +++ b/src/ch/zhaw/catan/Field.java @@ -1,11 +1,15 @@ package ch.zhaw.catan; +import ch.zhaw.hexboard.Label; + public class Field { private Config.Land land; + private Label label; - public Field(Config.Land land){ + public Field(Config.Land land, Label label){ this.land = land; + this.label = label; } public Config.Resource getResource(){ @@ -15,4 +19,8 @@ public class Field { public Config.Land getLand() { return land; } + + public Label getLabel() { + return label; + } } diff --git a/src/ch/zhaw/catan/SiedlerBoard.java b/src/ch/zhaw/catan/SiedlerBoard.java index 5a36dc7..64a2646 100644 --- a/src/ch/zhaw/catan/SiedlerBoard.java +++ b/src/ch/zhaw/catan/SiedlerBoard.java @@ -10,38 +10,37 @@ import java.util.*; public class SiedlerBoard extends HexBoard { - Map lowerFieldLabel = new HashMap<>(); + Map lowerFieldLabel = new HashMap<>(); public void createFixGamefield(){ 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])); - + if(dicePlacement.get(resourceField.getKey()) != null){ + String numberAsString = dicePlacement.get(resourceField.getKey()).toString(); + char[] numbersInChar = numberAsString.toCharArray(); + if (numberAsString.length() < 2) { + lowerFieldLabel.put(resourceField.getKey(), new Field(resourceField.getValue(), new Label('0', numbersInChar[0]))); + } + else { + lowerFieldLabel.put(resourceField.getKey(), new Field(resourceField.getValue(), new Label(numbersInChar[0],numbersInChar[1]))); + } } } } private int getDiceNumber(Point field) { - Label label = lowerFieldLabel.get(field); + Label label = lowerFieldLabel.get(field).getLabel(); return Integer.parseInt(label.toString()); } public String getTextView () { SiedlerBoardTextView view = new SiedlerBoardTextView(this); - for (Map.Entry e : lowerFieldLabel.entrySet()) { - view.setLowerFieldLabel(e.getKey(), e.getValue()); + for (Map.Entry e : lowerFieldLabel.entrySet()) { + view.setLowerFieldLabel(e.getKey(), e.getValue().getLabel()); } return view.toString(); }