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;
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;
}
}

View File

@ -10,38 +10,37 @@ import java.util.*;
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(){
Map<Point,Land> resourcePlacement = Config.getStandardLandPlacement();
Map<Point, Integer> dicePlacement = Config.getStandardDiceNumberPlacement();
for (Map.Entry<Point,Land> resourceField : resourcePlacement.entrySet()) {
addField(resourceField.getKey(),resourceField.getValue());
}
for (Map.Entry<Point,Integer> 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<Point, Label> e : lowerFieldLabel.entrySet()) {
view.setLowerFieldLabel(e.getKey(), e.getValue());
for (Map.Entry<Point, Field> e : lowerFieldLabel.entrySet()) {
view.setLowerFieldLabel(e.getKey(), e.getValue().getLabel());
}
return view.toString();
}