created method in SiedlerGame:
-checkAdjacentCornerList -checkAdjacentEdgesList -validPositionForSettlement -validPositionForRoad updated method in SiedlerGame: -buildRoad -buildSettlement
This commit is contained in:
parent
060310aebc
commit
a5f856313d
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="openjdk-17" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
|
@ -8,7 +8,7 @@ import java.awt.*;
|
|||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class SiedlerBoard extends HexBoard<Land, Structure, Road, String> {
|
||||
public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
|
||||
|
||||
Map<Point, ch.zhaw.hexboard.Label> lowerFieldLabel = new HashMap<>();
|
||||
|
||||
|
|
|
@ -5,8 +5,9 @@ import ch.zhaw.hexboard.HexBoardTextView;
|
|||
import ch.zhaw.hexboard.Label;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Set;
|
||||
|
||||
public class SiedlerBoardTextView extends HexBoardTextView<Land, Structure, Road, String> {
|
||||
public class SiedlerBoardTextView extends HexBoardTextView<Land, Settlement, Road, String> {
|
||||
|
||||
public SiedlerBoardTextView(SiedlerBoard board) {
|
||||
super(board);
|
||||
|
|
|
@ -204,20 +204,19 @@ public class SiedlerGame {
|
|||
* @return true, if the placement was successful
|
||||
*/
|
||||
public boolean buildSettlement(Point position) {
|
||||
//TODO Errors should be caught after this method is executed and returns false
|
||||
//1. Check if Corner
|
||||
if (!board.hasCorner(position)) {
|
||||
//1. Check if position is corner && is empty && neighbour Corners are empty
|
||||
if(!validPositionForSettlement(position)) {
|
||||
return false;
|
||||
}
|
||||
//2. Check if Corner is empty
|
||||
if (board.getCorner(position) != null) {
|
||||
//2. Check if neighbourEdge are Roads belong to active Player
|
||||
if(!checkAdjacentEdgesList(position)) {
|
||||
return false;
|
||||
}
|
||||
//3. Can Player build Settlement
|
||||
if (!allPlayers.get(activePlayer).buildSettlement()) {
|
||||
return false;
|
||||
}
|
||||
//4. Insert Road to map
|
||||
//4. Insert Settlement to map
|
||||
board.setCorner(position, new Settlement(allPlayers.get(activePlayer).getFaction()));
|
||||
//5. Give Resoure to bank
|
||||
bank.storeResourceToBank(Config.Structure.SETTLEMENT.getCosts());
|
||||
|
@ -257,39 +256,95 @@ public class SiedlerGame {
|
|||
* @return true, if the placement was successful
|
||||
*/
|
||||
public boolean buildRoad(Point roadStart, Point roadEnd) {
|
||||
//1. Check if Edge
|
||||
if (!board.hasEdge(roadStart, roadEnd)) {
|
||||
// TODO: Error message
|
||||
//1. Check if is edge && is empty && if neighbour Edge or Corners belong to Settlement of active Player
|
||||
if (!validPositionForRoad(roadStart,roadEnd)){
|
||||
return false;
|
||||
}
|
||||
//2. Check if Edge is empty
|
||||
if (board.getEdge(roadStart, roadEnd) != null) {
|
||||
// TODO: Error message
|
||||
return false;
|
||||
}
|
||||
//3. Can Player build road
|
||||
//2. Can Player build road
|
||||
if (!allPlayers.get(activePlayer).buildRoad()) {
|
||||
// TODO: Error message
|
||||
return false;
|
||||
}
|
||||
//4. Insert Road to map
|
||||
//3. Insert Road to map
|
||||
board.setEdge(roadStart, roadEnd, new Road(allPlayers.get(activePlayer).getFaction()));
|
||||
//5. Give Resource to bank
|
||||
//4. Give Resource to bank
|
||||
bank.storeResourceToBank(Config.Structure.ROAD.getCosts());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Can be used for both initial Settlement and normal Phase.
|
||||
* @param roadStart
|
||||
* @param roadEnd
|
||||
* @return
|
||||
*/
|
||||
private boolean validPositionForRoad(Point roadStart, Point roadEnd){
|
||||
//1. Check if Edge
|
||||
if (!board.hasEdge(roadStart, roadEnd)) {
|
||||
return false;
|
||||
}
|
||||
//2. Check if Edge is empty
|
||||
if (board.getEdge(roadStart, roadEnd) != null) {
|
||||
return false;
|
||||
}
|
||||
//3. Check if NeighbourEdge are Roads
|
||||
boolean hasNeighbourRoad = (checkAdjacentEdgesList(roadStart) || checkAdjacentEdgesList(roadEnd));
|
||||
//4.Check if roadStart or roadEnd is Settlement of current player or if 3. is valid
|
||||
if(board.getCorner(roadStart).getFaction() == allPlayers.get(activePlayer).getFaction()
|
||||
|| board.getCorner(roadEnd).getFaction() == allPlayers.get(activePlayer).getFaction()
|
||||
|| hasNeighbourRoad){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private boolean validPositionForRoad(Point position){
|
||||
//todo implement
|
||||
/**
|
||||
* Do not use for initial Settlement
|
||||
* @param position
|
||||
* @return
|
||||
*/
|
||||
private boolean validPositionForSettlement(Point position){
|
||||
//1. Check if Corner
|
||||
if (!board.hasCorner(position)) {
|
||||
return false;
|
||||
}
|
||||
//2. Check if Corner is empty
|
||||
if(board.getCorner(position) != null) {
|
||||
return false;
|
||||
}
|
||||
//3. Check if neighbourCorners are empty
|
||||
if(!checkAdjacentCornerList(position)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean validPositionForSettlement(Point position){
|
||||
//todo implement
|
||||
/**
|
||||
* This method checks if there are Roads build by active Player on adjacent edges
|
||||
* @param point
|
||||
* @return
|
||||
*/
|
||||
private boolean checkAdjacentEdgesList(Point point) {
|
||||
List<Road> results = board.getAdjacentEdges(point);
|
||||
for(int i = 0; i < results.size(); i++) {
|
||||
if(results.get(i).getFaction() == allPlayers.get(activePlayer).getFaction()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if Adjacent Corners are empty
|
||||
* @param point Corner to check
|
||||
* @return true if all Neighbour Corners are emtpy
|
||||
*/
|
||||
private boolean checkAdjacentCornerList(Point point) {
|
||||
List<Settlement> results = board.getNeighboursOfCorner(point);
|
||||
if(results.size() > 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -325,7 +380,7 @@ public class SiedlerGame {
|
|||
|
||||
private HashMap<Faction, Integer> getWinPoints(){
|
||||
HashMap<Faction, Integer> winPoints = new HashMap<>();
|
||||
List<Structure> structures = board.getCorners();
|
||||
List<Settlement> structures = board.getCorners();
|
||||
for(Structure structure : structures) {
|
||||
|
||||
int newWinPoints = 0;
|
||||
|
|
Loading…
Reference in New Issue