changes in Siedler Board. Usage of Field Class added.

This commit is contained in:
schrom01 2021-12-03 11:52:32 +01:00
parent 7c913089b5
commit b38e24b612
2 changed files with 22 additions and 15 deletions

View File

@ -1,11 +1,15 @@
package ch.zhaw.catan; package ch.zhaw.catan;
import ch.zhaw.hexboard.Label;
public class Field { public class Field {
private Config.Land land; private Config.Land land;
private Label label;
public Field(Config.Land land){ public Field(Config.Land land, Label label){
this.land = land; this.land = land;
this.label = label;
} }
public Config.Resource getResource(){ public Config.Resource getResource(){
@ -15,4 +19,8 @@ public class Field {
public Config.Land getLand() { public Config.Land getLand() {
return land; return land;
} }
public Label getLabel() {
return label;
}
} }

View File

@ -10,38 +10,37 @@ import java.util.*;
public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> { public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
Map<Point, ch.zhaw.hexboard.Label> lowerFieldLabel = new HashMap<>(); Map<Point, Field> lowerFieldLabel = new HashMap<>();
public void createFixGamefield(){ public void createFixGamefield(){
Map<Point,Land> resourcePlacement = Config.getStandardLandPlacement(); Map<Point,Land> resourcePlacement = Config.getStandardLandPlacement();
Map<Point, Integer> dicePlacement = Config.getStandardDiceNumberPlacement(); Map<Point, Integer> dicePlacement = Config.getStandardDiceNumberPlacement();
for (Map.Entry<Point,Land> resourceField : resourcePlacement.entrySet()) { for (Map.Entry<Point,Land> resourceField : resourcePlacement.entrySet()) {
addField(resourceField.getKey(),resourceField.getValue()); addField(resourceField.getKey(),resourceField.getValue());
} if(dicePlacement.get(resourceField.getKey()) != null){
for (Map.Entry<Point,Integer> diceField : dicePlacement.entrySet()) { String numberAsString = dicePlacement.get(resourceField.getKey()).toString();
String numberAsString = diceField.getValue().toString(); char[] numbersInChar = numberAsString.toCharArray();
char[] numbersInChar = numberAsString.toCharArray(); if (numberAsString.length() < 2) {
if (numberAsString.length() < 2) { lowerFieldLabel.put(resourceField.getKey(), new Field(resourceField.getValue(), new Label('0', numbersInChar[0])));
lowerFieldLabel.put(diceField.getKey(), new Label('0', numbersInChar[0])); }
} else {
else { lowerFieldLabel.put(resourceField.getKey(), new Field(resourceField.getValue(), new Label(numbersInChar[0],numbersInChar[1])));
lowerFieldLabel.put(diceField.getKey(), new Label(numbersInChar[0],numbersInChar[1])); }
} }
} }
} }
private int getDiceNumber(Point field) { private int getDiceNumber(Point field) {
Label label = lowerFieldLabel.get(field); Label label = lowerFieldLabel.get(field).getLabel();
return Integer.parseInt(label.toString()); return Integer.parseInt(label.toString());
} }
public String getTextView () { public String getTextView () {
SiedlerBoardTextView view = new SiedlerBoardTextView(this); SiedlerBoardTextView view = new SiedlerBoardTextView(this);
for (Map.Entry<Point, Label> e : lowerFieldLabel.entrySet()) { for (Map.Entry<Point, Field> e : lowerFieldLabel.entrySet()) {
view.setLowerFieldLabel(e.getKey(), e.getValue()); view.setLowerFieldLabel(e.getKey(), e.getValue().getLabel());
} }
return view.toString(); return view.toString();
} }