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 { 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])); } } } 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 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 getFieldsForDiceValue(int dice) { //TODO: Implement. ArrayList 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 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); } }