gruppe06-hufflepuff-projekt.../src/ch/zhaw/catan/SiedlerBoard.java

116 lines
4.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(){
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);
}
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();
}
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.
/**
* 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 Collections.unmodifiableList(Arrays.asList(lands));
}
}