adjust countRoad in SiedlerGame
This commit is contained in:
parent
99a8feca03
commit
161dec226e
|
@ -372,7 +372,7 @@ public class SiedlerGame {
|
|||
* This Method is used to check if the chosen position for a road is valid or not.
|
||||
* @param roadStart the coordinates where the road begins.
|
||||
* @param roadEnd the coordinates where the roads ends.
|
||||
* @return
|
||||
* @return true if road position is valid otherwise false
|
||||
*/
|
||||
private boolean validPositionForRoad(Point roadStart, Point roadEnd){
|
||||
//1. Check if Edge
|
||||
|
@ -389,17 +389,14 @@ public class SiedlerGame {
|
|||
return true;
|
||||
}
|
||||
//4.Check if roadStart or roadEnd is Settlement of current player
|
||||
if((board.getCorner(roadStart)!=null && board.getCorner(roadStart).getFaction() == allPlayers.get(activePlayer).getFaction())
|
||||
||(board.getCorner(roadEnd)!=null && board.getCorner(roadEnd).getFaction() == allPlayers.get(activePlayer).getFaction())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return (board.getCorner(roadStart) != null && board.getCorner(roadStart).getFaction() == allPlayers.get(activePlayer).getFaction())
|
||||
|| (board.getCorner(roadEnd) != null && board.getCorner(roadEnd).getFaction() == allPlayers.get(activePlayer).getFaction());
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used for both initial Settlement and normal Phase.
|
||||
* @param position
|
||||
* @return
|
||||
* @param position the position on the board to check for valid settlement position
|
||||
* @return true if valid position for settlement
|
||||
*/
|
||||
private boolean validPositionForSettlement(Point position){
|
||||
//1. Check if Corner
|
||||
|
@ -415,10 +412,7 @@ public class SiedlerGame {
|
|||
return false;
|
||||
}
|
||||
//3. Check if neighbourCorners are empty
|
||||
if(!checkAdjacentCornerList(position)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return checkAdjacentCornerList(position);
|
||||
}
|
||||
|
||||
private boolean checkIfWater(Point point) {
|
||||
|
@ -433,13 +427,13 @@ public class SiedlerGame {
|
|||
|
||||
/**
|
||||
* This method checks if there are Roads build by active Player on adjacent edges
|
||||
* @param point
|
||||
* @return
|
||||
* @param point point to check on
|
||||
* @return true if there is a road build next to the point.
|
||||
*/
|
||||
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()) {
|
||||
for (Road result : results) {
|
||||
if (result.getFaction() == allPlayers.get(activePlayer).getFaction()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -453,10 +447,7 @@ public class SiedlerGame {
|
|||
*/
|
||||
private boolean checkAdjacentCornerList(Point point) {
|
||||
List<Settlement> results = board.getNeighboursOfCorner(point);
|
||||
if(results.size() > 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return results.size() <= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -503,7 +494,7 @@ public class SiedlerGame {
|
|||
newWinPoints = 1;
|
||||
}
|
||||
if(structure.getFaction() == getCurrentPlayerFaction()){
|
||||
winPoints ++;
|
||||
winPoints += newWinPoints;
|
||||
}
|
||||
}
|
||||
longestRoadFaction = getLongestRoadFaction(longestRoadFaction);
|
||||
|
@ -515,14 +506,14 @@ public class SiedlerGame {
|
|||
|
||||
|
||||
/**
|
||||
* This method returns the faction of the player with the longest road longer than 5.
|
||||
* @return null if there is no player with a road longer than 5 otherwise it returns the faction of the specific player
|
||||
* This method checks for the player with the longest road according to the catan game rules.
|
||||
* @return a HashMap<Faction,Integer> where faction is the player with the longest road longer according to catan game rules
|
||||
* and the Integer representing the length of the road
|
||||
*/
|
||||
private HashMap<Config.Faction, Integer> getLongestRoadFaction(HashMap<Config.Faction,Integer> currentLongestRoad) {
|
||||
List<Settlement> corners = board.getCorners();
|
||||
List<Config.Faction> factionList = getPlayerFactions();
|
||||
HashMap<Config.Faction,Integer> players = new HashMap<>();
|
||||
int highest = 0;
|
||||
|
||||
for(Config.Faction faction : factionList) {
|
||||
int count = 0;
|
||||
|
@ -563,12 +554,12 @@ public class SiedlerGame {
|
|||
return roads;
|
||||
}
|
||||
|
||||
Iterator it2 = roads.iterator();
|
||||
Iterator<Road> it2 = roads.iterator();
|
||||
while(it2.hasNext()) {
|
||||
Road roadsroad = (Road) it2.next();
|
||||
Iterator it3 = roadslist.iterator();
|
||||
Road roadsroad = it2.next();
|
||||
Iterator<Road> it3 = roadslist.iterator();
|
||||
while (it3.hasNext()){
|
||||
Road roadslistRoad = (Road) it3.next();
|
||||
Road roadslistRoad = it3.next();
|
||||
if(roadslistRoad == roadsroad || roadslistRoad.getFaction() != faction) {
|
||||
it3.remove();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue