97 lines
3.3 KiB
Java
97 lines
3.3 KiB
Java
package ch.zhaw.catan;
|
|
|
|
import ch.zhaw.catan.Config.Land;
|
|
import ch.zhaw.hexboard.HexBoard;
|
|
import ch.zhaw.hexboard.Label;
|
|
|
|
import java.awt.*;
|
|
import java.util.*;
|
|
import java.util.List;
|
|
|
|
public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
|
|
|
|
Map<Point, ch.zhaw.hexboard.Label> 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]));
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private int getDiceNumber(Point field) {
|
|
Label label = lowerFieldLabel.get(field);
|
|
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());
|
|
}
|
|
return view.toString();
|
|
}
|
|
|
|
|
|
//TODO: Add fields, constructors and methods as you see fit. Do NOT change the signature
|
|
// of the methods below.
|
|
|
|
|
|
/**
|
|
* Returns the fields associated with the specified dice value.
|
|
*
|
|
* @param dice the dice value
|
|
* @return the fields associated with the dice value
|
|
*/
|
|
public List<Point> getFieldsForDiceValue(int dice) {
|
|
//TODO: Implement.
|
|
ArrayList<Point> fields = new ArrayList<>();
|
|
for(Point field : lowerFieldLabel.keySet()){
|
|
if(getDiceNumber(field) == dice){
|
|
fields.add(field);
|
|
}
|
|
}
|
|
return fields;
|
|
}
|
|
|
|
/**
|
|
* Returns the {@link Land}s adjacent to the specified corner.
|
|
*
|
|
* @param corner the corner
|
|
* @return the list with the adjacent {@link Land}s
|
|
*/
|
|
public List<Land> getLandsForCorner(Point corner) {
|
|
Point above = new Point(corner.x, corner.y + 2);
|
|
Point below = new Point(corner.x, corner.y -2);
|
|
Land[] lands = new Land[3];
|
|
if (hasField(above)) {
|
|
lands[0] = getField(above);
|
|
lands[1] = getField(new Point(corner.x + 1, corner.y - 1));
|
|
lands[2] = getField(new Point(corner.x - 1, corner.y - 1));
|
|
}
|
|
else if (hasField(below)) {
|
|
lands[0] = getField(below);
|
|
lands[1] = getField(new Point(corner.x + 1, corner.y + 1));
|
|
lands[2] = getField(new Point(corner.x - 1, corner.y + 1));
|
|
}
|
|
else {
|
|
return Collections.emptyList();
|
|
}
|
|
return List.of(lands);
|
|
}
|
|
}
|