completed method getFieldsForDiceValue in SiedlerBoard

This commit is contained in:
schrom01 2021-11-24 17:03:55 +01:00
parent 6c36037444
commit ad1227ac98
4 changed files with 27 additions and 9 deletions

View File

@ -5,10 +5,8 @@ import ch.zhaw.hexboard.HexBoard;
import ch.zhaw.hexboard.Label; import ch.zhaw.hexboard.Label;
import java.awt.*; import java.awt.*;
import java.util.Collections; import java.util.*;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
public class SiedlerBoard extends HexBoard<Land, String, String, String> { public class SiedlerBoard extends HexBoard<Land, String, String, String> {
@ -35,6 +33,21 @@ public class SiedlerBoard extends HexBoard<Land, String, String, String> {
} }
private int getDiceNumber(Point field) {
Label label = lowerFieldLabel.get(field);
return Integer.parseInt(label.toString());
}
public SiedlerBoardTextView getTextView () {
SiedlerBoardTextView view = new SiedlerBoardTextView(this);
for (Map.Entry<Point, Label> e : lowerFieldLabel.entrySet()) {
view.setLowerFieldLabel(e.getKey(), e.getValue());
}
return view;
}
private void placeFieldWithoutLabel(Land fieldType, Integer[][] fieldCoordinates) { private void placeFieldWithoutLabel(Land fieldType, Integer[][] fieldCoordinates) {
for(Integer[] coordinates : fieldCoordinates) { for(Integer[] coordinates : fieldCoordinates) {
addField(new Point(coordinates[0], coordinates[1]), fieldType); addField(new Point(coordinates[0], coordinates[1]), fieldType);
@ -53,14 +66,10 @@ public class SiedlerBoard extends HexBoard<Land, String, String, String> {
} }
//TODO: Add fields, constructors and methods as you see fit. Do NOT change the signature //TODO: Add fields, constructors and methods as you see fit. Do NOT change the signature
// of the methods below. // of the methods below.
/** /**
* Returns the fields associated with the specified dice value. * Returns the fields associated with the specified dice value.
* *
@ -69,7 +78,13 @@ public class SiedlerBoard extends HexBoard<Land, String, String, String> {
*/ */
public List<Point> getFieldsForDiceValue(int dice) { public List<Point> getFieldsForDiceValue(int dice) {
//TODO: Implement. //TODO: Implement.
return Collections.emptyList(); ArrayList<Point> fields = new ArrayList<>();
for(Point field : lowerFieldLabel.keySet()){
if(getDiceNumber(field) == dice){
fields.add(field);
}
}
return fields;
} }
/** /**

View File

@ -2,6 +2,9 @@ package ch.zhaw.catan;
import ch.zhaw.catan.Config.Land; import ch.zhaw.catan.Config.Land;
import ch.zhaw.hexboard.HexBoardTextView; import ch.zhaw.hexboard.HexBoardTextView;
import ch.zhaw.hexboard.Label;
import java.awt.*;
public class SiedlerBoardTextView extends HexBoardTextView<Land, String, String, String> { public class SiedlerBoardTextView extends HexBoardTextView<Land, String, String, String> {