Minor Grammar and Cameltow fixes
This commit is contained in:
parent
f3b9cd2771
commit
ffc97a39ef
|
@ -20,8 +20,7 @@ public class Bank {
|
||||||
Integer newResourceNumber = resources.get(resource) - numberOfResources;
|
Integer newResourceNumber = resources.get(resource) - numberOfResources;
|
||||||
resources.put(resource, newResourceNumber);
|
resources.put(resource, newResourceNumber);
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,10 @@ public enum Command {
|
||||||
private final String commandWord;
|
private final String commandWord;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Command(String commandWord) {
|
Command(String commandWord) {
|
||||||
this.commandWord = commandWord;
|
this.commandWord = commandWord;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return commandWord;
|
return commandWord;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,8 @@ package ch.zhaw.catan;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
//TODO Java Doc bearbeiten
|
//TODO Java Doc
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New Class PLayer
|
* New Class PLayer
|
||||||
* This class is here in order to maintain the resources of the players, the amount of structures that they can build,
|
* This class is here in order to maintain the resources of the players, the amount of structures that they can build,
|
||||||
|
@ -22,12 +23,12 @@ public class Player {
|
||||||
public Player(Config.Faction faction) {
|
public Player(Config.Faction faction) {
|
||||||
//Data fields
|
//Data fields
|
||||||
this.faction = faction;
|
this.faction = faction;
|
||||||
//Available Structures initialize
|
//Initialize available structures
|
||||||
structureToUse = new HashMap<>();
|
structureToUse = new HashMap<>();
|
||||||
structureToUse.put(Config.Structure.ROAD, Config.Structure.ROAD.getStockPerPlayer());
|
structureToUse.put(Config.Structure.ROAD, Config.Structure.ROAD.getStockPerPlayer());
|
||||||
structureToUse.put(Config.Structure.SETTLEMENT, Config.Structure.SETTLEMENT.getStockPerPlayer());
|
structureToUse.put(Config.Structure.SETTLEMENT, Config.Structure.SETTLEMENT.getStockPerPlayer());
|
||||||
structureToUse.put(Config.Structure.CITY, Config.Structure.CITY.getStockPerPlayer());
|
structureToUse.put(Config.Structure.CITY, Config.Structure.CITY.getStockPerPlayer());
|
||||||
//Resources initialize
|
//Initialize resources
|
||||||
resources = new HashMap<>();
|
resources = new HashMap<>();
|
||||||
for (Config.Resource resource : Config.Resource.values()) {
|
for (Config.Resource resource : Config.Resource.values()) {
|
||||||
resources.put(resource, 0);
|
resources.put(resource, 0);
|
||||||
|
@ -73,18 +74,18 @@ public class Player {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method substracts a specific resource from resourcess but check first if player has enough resources.
|
* This method subtracts a specific resource from the player's resources. but check first if player has the specific resources.
|
||||||
*
|
*
|
||||||
* @param resource to substract
|
* @param resource to subtract
|
||||||
* @param numberToSubstract how much to substract
|
* @param numberToSubtract how much to subtract
|
||||||
* @return true if resource has been substracted false if player has not enough resources
|
* @return true if resource has been subtracted false if player has not enough resources
|
||||||
*/
|
*/
|
||||||
public boolean substractResource(Config.Resource resource, int numberToSubstract) {
|
public boolean subtractResource(Config.Resource resource, int numberToSubtract) {
|
||||||
int inPossesion = resources.get(resource);
|
int inPossession = resources.get(resource);
|
||||||
if (inPossesion - numberToSubstract < 0) {
|
if (inPossession - numberToSubtract < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
resources.put(resource, inPossesion - numberToSubstract);
|
resources.put(resource, inPossession - numberToSubtract);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,6 +94,7 @@ public class Player {
|
||||||
* and resources to build one more. If the player is able to build, this method subtracts the building cost from the resources
|
* and resources to build one more. If the player is able to build, this method subtracts the building cost from the resources
|
||||||
* in possession by the player.
|
* in possession by the player.
|
||||||
* It reduces the amount of the specific structure a player can build by 1.
|
* It reduces the amount of the specific structure a player can build by 1.
|
||||||
|
*
|
||||||
* @return true if the structure can be created false if the structure can't be created.
|
* @return true if the structure can be created false if the structure can't be created.
|
||||||
*/
|
*/
|
||||||
public boolean build(Config.Structure structure) {
|
public boolean build(Config.Structure structure) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package ch.zhaw.catan;
|
package ch.zhaw.catan;
|
||||||
|
|
||||||
import java.awt.Point;
|
import java.awt.*;
|
||||||
|
|
||||||
/// TODO: 09/12/2021 Java Doc
|
/// TODO: 09/12/2021 Java Doc
|
||||||
public class Road extends Structure {
|
public class Road extends Structure {
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package ch.zhaw.catan;
|
package ch.zhaw.catan;
|
||||||
|
|
||||||
import java.awt.Point;
|
import java.awt.*;
|
||||||
|
|
||||||
//TODO Java Doc
|
//TODO Java Doc
|
||||||
public class Settlement extends Structure {
|
public class Settlement extends Structure {
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.util.Random;
|
||||||
public class Siedler {
|
public class Siedler {
|
||||||
/**
|
/**
|
||||||
* The main Method of the game. It creates a Parser Object and calls the Methods foundingPhase (to create a new Game) and gamePhase
|
* The main Method of the game. It creates a Parser Object and calls the Methods foundingPhase (to create a new Game) and gamePhase
|
||||||
|
*
|
||||||
* @param args There are no arguments needed.
|
* @param args There are no arguments needed.
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -19,6 +20,7 @@ public class Siedler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Method for the usual game Process. It contains the Main loop to get new commands from the players and calls the associated methods.
|
* The Method for the usual game Process. It contains the Main loop to get new commands from the players and calls the associated methods.
|
||||||
|
*
|
||||||
* @param parser The Parser Object which will interact with the player.
|
* @param parser The Parser Object which will interact with the player.
|
||||||
* @param game The Game object which is already created and has the founding phase completed.
|
* @param game The Game object which is already created and has the founding phase completed.
|
||||||
*/
|
*/
|
||||||
|
@ -66,6 +68,7 @@ public class Siedler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Method which is called if the player chooses the command "next Player".
|
* The Method which is called if the player chooses the command "next Player".
|
||||||
|
*
|
||||||
* @param parser The parser Object which will interact with the player.
|
* @param parser The parser Object which will interact with the player.
|
||||||
* @param game The game Object which will be used to execute the Method.
|
* @param game The game Object which will be used to execute the Method.
|
||||||
* @return true: if there is a winner and game is finished. false: if there is no winner (yet).
|
* @return true: if there is a winner and game is finished. false: if there is no winner (yet).
|
||||||
|
@ -83,6 +86,7 @@ public class Siedler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Method which is called if the player chooses the command "Trade with bank".
|
* The Method which is called if the player chooses the command "Trade with bank".
|
||||||
|
*
|
||||||
* @param parser The parser Object which will interact with the player.
|
* @param parser The parser Object which will interact with the player.
|
||||||
* @param game The game Object which will be used to execute the Method.
|
* @param game The game Object which will be used to execute the Method.
|
||||||
*/
|
*/
|
||||||
|
@ -96,6 +100,7 @@ public class Siedler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Method which is called if the player chooses a command to build any structure.
|
* The Method which is called if the player chooses a command to build any structure.
|
||||||
|
*
|
||||||
* @param parser The parser Object which will interact with the player.
|
* @param parser The parser Object which will interact with the player.
|
||||||
* @param game The game Object which will be used to execute the Method.
|
* @param game The game Object which will be used to execute the Method.
|
||||||
* @param structure The kind of Structure the player selected to build.
|
* @param structure The kind of Structure the player selected to build.
|
||||||
|
@ -117,6 +122,7 @@ public class Siedler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The method which calculates a random dice number and calls the method throwDice in the game Object.
|
* The method which calculates a random dice number and calls the method throwDice in the game Object.
|
||||||
|
*
|
||||||
* @param parser The parser Object which will interact with the player.
|
* @param parser The parser Object which will interact with the player.
|
||||||
* @param game The game Object which will be used to execute the Method.
|
* @param game The game Object which will be used to execute the Method.
|
||||||
*/
|
*/
|
||||||
|
@ -130,6 +136,7 @@ public class Siedler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Method which executes the whole founding phase. It Creates a new SiedlerGame Object and prompts the players to build their first structures.
|
* The Method which executes the whole founding phase. It Creates a new SiedlerGame Object and prompts the players to build their first structures.
|
||||||
|
*
|
||||||
* @param parser The parser Object which will interact with the player.
|
* @param parser The parser Object which will interact with the player.
|
||||||
* @return The new SiedlerGame Object which is created.
|
* @return The new SiedlerGame Object which is created.
|
||||||
*/
|
*/
|
||||||
|
@ -155,6 +162,7 @@ public class Siedler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Method is called by foundingPhase. It prompts the Player to build a Settlement and a Road.
|
* The Method is called by foundingPhase. It prompts the Player to build a Settlement and a Road.
|
||||||
|
*
|
||||||
* @param parser The parser Object which will interact with the player.
|
* @param parser The parser Object which will interact with the player.
|
||||||
* @param game The game Object which will be used to execute the Method.
|
* @param game The game Object which will be used to execute the Method.
|
||||||
* @param payout true (for second Settlement in founding Phase): the Player gets a payout for the settlement. false (for first Settlement in founding Phase): The Player gets no payout.
|
* @param payout true (for second Settlement in founding Phase): the Player gets a payout for the settlement. false (for first Settlement in founding Phase): The Player gets no payout.
|
||||||
|
@ -169,8 +177,7 @@ public class Siedler {
|
||||||
do {
|
do {
|
||||||
if (game.placeInitialSettlement(parser.getPoint(), payout)) {
|
if (game.placeInitialSettlement(parser.getPoint(), payout)) {
|
||||||
successful = true;
|
successful = true;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
parser.errorMessage();
|
parser.errorMessage();
|
||||||
}
|
}
|
||||||
} while (!successful);
|
} while (!successful);
|
||||||
|
@ -182,8 +189,7 @@ public class Siedler {
|
||||||
do {
|
do {
|
||||||
if (game.placeInitialRoad(parser.getPoint(), parser.getPoint())) {
|
if (game.placeInitialRoad(parser.getPoint(), parser.getPoint())) {
|
||||||
successful = true;
|
successful = true;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
parser.errorMessage();
|
parser.errorMessage();
|
||||||
}
|
}
|
||||||
} while (!successful);
|
} while (!successful);
|
||||||
|
|
|
@ -5,8 +5,15 @@ import ch.zhaw.hexboard.HexBoard;
|
||||||
import ch.zhaw.hexboard.Label;
|
import ch.zhaw.hexboard.Label;
|
||||||
|
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Collections;
|
||||||
//TODO Enhance JavaDoc
|
//TODO Enhance JavaDoc
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subclass of HexBoard
|
* Subclass of HexBoard
|
||||||
* Saves the fields which are set and handles Methods with specific Dice Numbers.
|
* Saves the fields which are set and handles Methods with specific Dice Numbers.
|
||||||
|
@ -24,7 +31,7 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
|
||||||
/**
|
/**
|
||||||
* Method to create the predefined game field from Config.
|
* Method to create the predefined game field from Config.
|
||||||
*/
|
*/
|
||||||
public void createFixGamefield(){
|
public void createFixGameField() {
|
||||||
Map<Point, Land> resourcePlacement = Config.getStandardLandPlacement();
|
Map<Point, Land> resourcePlacement = Config.getStandardLandPlacement();
|
||||||
Map<Point, Integer> dicePlacement = Config.getStandardDiceNumberPlacement();
|
Map<Point, Integer> dicePlacement = Config.getStandardDiceNumberPlacement();
|
||||||
for (Map.Entry<Point, Land> resourceField : resourcePlacement.entrySet()) {
|
for (Map.Entry<Point, Land> resourceField : resourcePlacement.entrySet()) {
|
||||||
|
@ -34,8 +41,7 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
|
||||||
char[] numbersInChar = numberAsString.toCharArray();
|
char[] numbersInChar = numberAsString.toCharArray();
|
||||||
if (numberAsString.length() < 2) {
|
if (numberAsString.length() < 2) {
|
||||||
fields.put(resourceField.getKey(), new Field(resourceField.getValue(), new Label('0', numbersInChar[0])));
|
fields.put(resourceField.getKey(), new Field(resourceField.getValue(), new Label('0', numbersInChar[0])));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
fields.put(resourceField.getKey(), new Field(resourceField.getValue(), new Label(numbersInChar[0], numbersInChar[1])));
|
fields.put(resourceField.getKey(), new Field(resourceField.getValue(), new Label(numbersInChar[0], numbersInChar[1])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,6 +50,7 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to get the DiceNumber of a specific field.
|
* Method to get the DiceNumber of a specific field.
|
||||||
|
*
|
||||||
* @param field Point with coordinates of the specific field
|
* @param field Point with coordinates of the specific field
|
||||||
* @return the DiceNumber of the field.
|
* @return the DiceNumber of the field.
|
||||||
*/
|
*/
|
||||||
|
@ -53,8 +60,9 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to create a SiedlerBoardTextView Object set the LowerFieldLabels with theirs Dicenumber.
|
* Method to create a SiedlerBoardTextView Object set the LowerFieldLabels with theirs dice number.
|
||||||
* It is used to print the actual board in TextIO.
|
* It is used to print the actual board in TextIO.
|
||||||
|
*
|
||||||
* @return String of actual board.
|
* @return String of actual board.
|
||||||
*/
|
*/
|
||||||
public String getTextView() {
|
public String getTextView() {
|
||||||
|
@ -116,21 +124,21 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
|
||||||
lands[0] = getField(above);
|
lands[0] = getField(above);
|
||||||
lands[1] = getField(new Point(corner.x + 1, corner.y - 1));
|
lands[1] = getField(new Point(corner.x + 1, corner.y - 1));
|
||||||
lands[2] = getField(new Point(corner.x - 1, corner.y - 1));
|
lands[2] = getField(new Point(corner.x - 1, corner.y - 1));
|
||||||
}
|
} else if (hasField(below)) {
|
||||||
else if (hasField(below)) {
|
|
||||||
lands[0] = getField(below);
|
lands[0] = getField(below);
|
||||||
lands[1] = getField(new Point(corner.x + 1, corner.y + 1));
|
lands[1] = getField(new Point(corner.x + 1, corner.y + 1));
|
||||||
lands[2] = getField(new Point(corner.x - 1, corner.y + 1));
|
lands[2] = getField(new Point(corner.x - 1, corner.y + 1));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
return List.of(lands);
|
return List.of(lands);
|
||||||
}
|
}
|
||||||
|
//TODO Java Doc no return
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method checks for the player with the longest road according to the catan game rules.
|
* This method checks for the player with the longest road according to the siedler game rules.
|
||||||
* @return a HashMap<Faction,Integer> where faction is the player with the longest road longer according to catan game rules
|
*
|
||||||
|
* @return a HashMap<Faction,Integer> where faction is the player with the longest road longer according to siedler game rules
|
||||||
* and the Integer representing the length of the road
|
* and the Integer representing the length of the road
|
||||||
*/
|
*/
|
||||||
public void getLongestRoadFaction(HashMap<Config.Faction, Integer> currentLongestRoad, List<Config.Faction> factionList) {
|
public void getLongestRoadFaction(HashMap<Config.Faction, Integer> currentLongestRoad, List<Config.Faction> factionList) {
|
||||||
|
@ -180,50 +188,44 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
|
||||||
/**
|
/**
|
||||||
* This method is recursive and adds all roads which belongs to a specific players and stringing together to a HashSet.
|
* This method is recursive and adds all roads which belongs to a specific players and stringing together to a HashSet.
|
||||||
* The length of the HashSet represents the length of the longest Road the player has.
|
* The length of the HashSet represents the length of the longest Road the player has.
|
||||||
|
*
|
||||||
* @param faction the faction of the player to check on
|
* @param faction the faction of the player to check on
|
||||||
* @param position there has to be a starting point to start counting. In this case it's a corner where a settlement belonging to the players faction is build on.
|
* @param position there has to be a starting point to start counting. In this case it's a corner where a settlement belonging to the player's faction is build on.
|
||||||
* @param roads is the hashset with all roads belong to the player which are stringing together
|
* @param roads is the hashset with all roads belong to the player which are stringing together
|
||||||
* @param add if true branches needs to be count together. (for example if it is the starting point(first time of counting)) otherwise the longest branch is beeing added to roads.
|
* @param add if true branches needs to be count together. (for example if it is the starting point(first time of counting)) otherwise the longest branch is being added to roads.
|
||||||
* @return HashSet with all roads from a specific player which are string together.
|
* @return HashSet with all roads from a specific player which are string together.
|
||||||
*/
|
*/
|
||||||
private HashSet<Road> countRoad(Config.Faction faction, Point position, HashSet<Road> roads, boolean add) {
|
private HashSet<Road> countRoad(Config.Faction faction, Point position, HashSet<Road> roads, boolean add) {
|
||||||
List<Road> roadslist = getAdjacentEdges(position);
|
List<Road> roadsList = getAdjacentEdges(position);
|
||||||
if (getCorner(position) != null && getCorner(position).getFaction() != faction) {
|
if (getCorner(position) != null && getCorner(position).getFaction() != faction) {
|
||||||
return roads;
|
return roads;
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<Road> it2 = roads.iterator();
|
for (Road roadsRoad : roads) {
|
||||||
while(it2.hasNext()) {
|
Iterator<Road> it3 = roadsList.iterator();
|
||||||
Road roadsroad = it2.next();
|
|
||||||
Iterator<Road> it3 = roadslist.iterator();
|
|
||||||
while (it3.hasNext()) {
|
while (it3.hasNext()) {
|
||||||
Road roadslistRoad = it3.next();
|
Road roadsListRoad = it3.next();
|
||||||
if(roadslistRoad == roadsroad || roadslistRoad.getFaction() != faction) {
|
if (roadsListRoad == roadsRoad || roadsListRoad.getFaction() != faction) {
|
||||||
it3.remove();
|
it3.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (roadsList.size() == 1) {
|
||||||
if(roadslist.size() == 1) {
|
roads.add(roadsList.get(0));
|
||||||
roads.add(roadslist.get(0));
|
position = getNextPoint(roadsList.get(0), position);
|
||||||
position = getNextPoint(roadslist.get(0),position);
|
|
||||||
roads = countRoad(faction, position, roads, false);
|
roads = countRoad(faction, position, roads, false);
|
||||||
}
|
} else if (roadsList.size() == 2) {
|
||||||
|
|
||||||
else if(roadslist.size() == 2) {
|
|
||||||
HashSet<Road> listOne = (HashSet<Road>) roads.clone();
|
HashSet<Road> listOne = (HashSet<Road>) roads.clone();
|
||||||
HashSet<Road> listTwo = (HashSet<Road>) roads.clone();
|
HashSet<Road> listTwo = (HashSet<Road>) roads.clone();
|
||||||
listOne.add(roadslist.get(0));
|
listOne.add(roadsList.get(0));
|
||||||
Point positionOne = getNextPoint(roadslist.get(0),position);
|
Point positionOne = getNextPoint(roadsList.get(0), position);
|
||||||
listTwo.add(roadslist.get(1));
|
listTwo.add(roadsList.get(1));
|
||||||
Point positionTwo = getNextPoint(roadslist.get(1),position);
|
Point positionTwo = getNextPoint(roadsList.get(1), position);
|
||||||
listOne = countRoad(faction, positionOne, listOne, false);
|
listOne = countRoad(faction, positionOne, listOne, false);
|
||||||
listTwo = countRoad(faction, positionTwo, listTwo, false);
|
listTwo = countRoad(faction, positionTwo, listTwo, false);
|
||||||
if (add) {
|
if (add) {
|
||||||
for (Road road : listOne) {
|
listTwo.addAll(listOne);
|
||||||
listTwo.add(road);
|
|
||||||
}
|
|
||||||
roads = listTwo;
|
roads = listTwo;
|
||||||
} else {
|
} else {
|
||||||
HashSet<Road> tallest;
|
HashSet<Road> tallest;
|
||||||
|
@ -232,52 +234,48 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
|
||||||
} else {
|
} else {
|
||||||
tallest = listTwo;
|
tallest = listTwo;
|
||||||
}
|
}
|
||||||
for (Road road : tallest) {
|
roads.addAll(tallest);
|
||||||
roads.add(road);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} else if (roadsList.size() == 3) {
|
||||||
|
|
||||||
else if(roadslist.size() == 3) {
|
|
||||||
HashSet<Road> listOne = (HashSet<Road>) roads.clone();
|
HashSet<Road> listOne = (HashSet<Road>) roads.clone();
|
||||||
HashSet<Road> listTwo = (HashSet<Road>) roads.clone();
|
HashSet<Road> listTwo = (HashSet<Road>) roads.clone();
|
||||||
HashSet<Road> listThree = (HashSet<Road>) roads.clone();
|
HashSet<Road> listThree = (HashSet<Road>) roads.clone();
|
||||||
listOne.add(roadslist.get(0));
|
listOne.add(roadsList.get(0));
|
||||||
Point positionOne = getNextPoint(roadslist.get(0),position);
|
Point positionOne = getNextPoint(roadsList.get(0), position);
|
||||||
listTwo.add(roadslist.get(1));
|
listTwo.add(roadsList.get(1));
|
||||||
Point positionTwo = getNextPoint(roadslist.get(1),position);
|
Point positionTwo = getNextPoint(roadsList.get(1), position);
|
||||||
listThree.add(roadslist.get(2));
|
listThree.add(roadsList.get(2));
|
||||||
Point positionThree = getNextPoint(roadslist.get(2),position);
|
Point positionThree = getNextPoint(roadsList.get(2), position);
|
||||||
listOne = countRoad(faction, positionOne, listOne, false);
|
listOne = countRoad(faction, positionOne, listOne, false);
|
||||||
listTwo = countRoad(faction, positionTwo, listTwo, false);
|
listTwo = countRoad(faction, positionTwo, listTwo, false);
|
||||||
listThree = countRoad(faction, positionThree, listThree, false);
|
listThree = countRoad(faction, positionThree, listThree, false);
|
||||||
|
|
||||||
HashSet<Road> tallest;
|
HashSet<Road> tallest;
|
||||||
HashSet<Road> secondtallest;
|
HashSet<Road> secondTallest;
|
||||||
|
|
||||||
if (listOne.size() >= listTwo.size()) {
|
if (listOne.size() >= listTwo.size()) {
|
||||||
tallest = listOne;
|
tallest = listOne;
|
||||||
secondtallest = listTwo;
|
secondTallest = listTwo;
|
||||||
} else {
|
} else {
|
||||||
tallest = listTwo;
|
tallest = listTwo;
|
||||||
secondtallest = listOne;
|
secondTallest = listOne;
|
||||||
}if(listThree.size() >= secondtallest.size()) {
|
|
||||||
secondtallest = listThree;
|
|
||||||
}
|
}
|
||||||
for(Road road : secondtallest) {
|
if (listThree.size() >= secondTallest.size()) {
|
||||||
tallest.add(road);
|
secondTallest = listThree;
|
||||||
}
|
}
|
||||||
|
tallest.addAll(secondTallest);
|
||||||
roads = tallest;
|
roads = tallest;
|
||||||
}
|
}
|
||||||
return roads;
|
return roads;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is beeing used to evaluate the next starting position to get the adjacent Roads from it.
|
* This method is being used to evaluate the next starting position to get the adjacent Roads from it.
|
||||||
|
*
|
||||||
* @param road the next road to check on
|
* @param road the next road to check on
|
||||||
* @param position the current starting point
|
* @param position the current starting point
|
||||||
* @return return the oposite point of the current point.
|
* @return return the opposite point of the current point.
|
||||||
*/
|
*/
|
||||||
private Point getNextPoint(Road road, Point position) {
|
private Point getNextPoint(Road road, Point position) {
|
||||||
Point start = road.getStart();
|
Point start = road.getStart();
|
||||||
|
|
|
@ -9,8 +9,6 @@ import java.util.HashMap;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,7 +27,7 @@ public class SiedlerGame {
|
||||||
private final int winPointsForWin;
|
private final int winPointsForWin;
|
||||||
private final Bank bank;
|
private final Bank bank;
|
||||||
private int activePlayer;
|
private int activePlayer;
|
||||||
private HashMap<Config.Faction,Integer> longestRoadFaction;
|
private final HashMap<Config.Faction, Integer> longestRoadFaction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a SiedlerGame game state object.
|
* Constructs a SiedlerGame game state object.
|
||||||
|
@ -45,7 +43,7 @@ public class SiedlerGame {
|
||||||
}
|
}
|
||||||
bank = new Bank();
|
bank = new Bank();
|
||||||
board = new SiedlerBoard();
|
board = new SiedlerBoard();
|
||||||
board.createFixGamefield();
|
board.createFixGameField();
|
||||||
allPlayers = new ArrayList<>();
|
allPlayers = new ArrayList<>();
|
||||||
createPlayer(numberOfPlayers);
|
createPlayer(numberOfPlayers);
|
||||||
activePlayer = 0;
|
activePlayer = 0;
|
||||||
|
@ -65,8 +63,7 @@ public class SiedlerGame {
|
||||||
public void switchToNextPlayer() {
|
public void switchToNextPlayer() {
|
||||||
if (activePlayer < allPlayers.size() - 1) {
|
if (activePlayer < allPlayers.size() - 1) {
|
||||||
activePlayer++;
|
activePlayer++;
|
||||||
}
|
} else if (activePlayer == allPlayers.size() - 1) {
|
||||||
else if (activePlayer == allPlayers.size() -1){
|
|
||||||
activePlayer = 0;
|
activePlayer = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,11 +74,11 @@ public class SiedlerGame {
|
||||||
public void switchToPreviousPlayer() {
|
public void switchToPreviousPlayer() {
|
||||||
if (activePlayer > 0) {
|
if (activePlayer > 0) {
|
||||||
activePlayer--;
|
activePlayer--;
|
||||||
}
|
} else if (activePlayer == 0) {
|
||||||
else if (activePlayer == 0){
|
|
||||||
activePlayer = allPlayers.size() - 1;
|
activePlayer = allPlayers.size() - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO JavaDoc
|
//TODO JavaDoc
|
||||||
private boolean addResourcesToPlayer(Player player, Resource resource, int numberToAdd) {
|
private boolean addResourcesToPlayer(Player player, Resource resource, int numberToAdd) {
|
||||||
if (bank.getResourceFromBank(resource, numberToAdd)) {
|
if (bank.getResourceFromBank(resource, numberToAdd)) {
|
||||||
|
@ -90,9 +87,10 @@ public class SiedlerGame {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO JavaDoc
|
//TODO JavaDoc
|
||||||
private boolean subtractResourceFromPlayer(Player player, Resource resource, int numberToSubtract) {
|
private boolean subtractResourceFromPlayer(Player player, Resource resource, int numberToSubtract) {
|
||||||
if(player.substractResource(resource, numberToSubtract)){
|
if (player.subtractResource(resource, numberToSubtract)) {
|
||||||
bank.storeResourceToBank(resource, numberToSubtract);
|
bank.storeResourceToBank(resource, numberToSubtract);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -117,11 +115,9 @@ public class SiedlerGame {
|
||||||
for (Player player : allPlayers) {
|
for (Player player : allPlayers) {
|
||||||
factions.add(player.getFaction());
|
factions.add(player.getFaction());
|
||||||
}
|
}
|
||||||
|
|
||||||
return factions;
|
return factions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the game board.
|
* Returns the game board.
|
||||||
*
|
*
|
||||||
|
@ -242,6 +238,7 @@ public class SiedlerGame {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO JavaDoc
|
//TODO JavaDoc
|
||||||
public void handleDiceThrow7(Player player) {
|
public void handleDiceThrow7(Player player) {
|
||||||
ArrayList<Config.Resource> resourceArrayList = new ArrayList<>();
|
ArrayList<Config.Resource> resourceArrayList = new ArrayList<>();
|
||||||
|
@ -261,7 +258,6 @@ public class SiedlerGame {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a settlement at the specified position on the board.
|
* Builds a settlement at the specified position on the board.
|
||||||
*
|
*
|
||||||
|
@ -375,6 +371,7 @@ public class SiedlerGame {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This Method is used to check if the chosen position for a road is valid or not.
|
* 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 roadStart the coordinates where the road begins.
|
||||||
* @param roadEnd the coordinates where the road ends.
|
* @param roadEnd the coordinates where the road ends.
|
||||||
* @return true if road position is valid otherwise false
|
* @return true if road position is valid otherwise false
|
||||||
|
@ -400,6 +397,7 @@ public class SiedlerGame {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can be used for both initial Settlement and normal Phase.
|
* Can be used for both initial Settlement and normal Phase.
|
||||||
|
*
|
||||||
* @param position the position on the board to check for valid settlement position
|
* @param position the position on the board to check for valid settlement position
|
||||||
* @return true if valid position for settlement
|
* @return true if valid position for settlement
|
||||||
*/
|
*/
|
||||||
|
@ -432,6 +430,7 @@ public class SiedlerGame {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method checks if there are Roads build by active Player on adjacent edges
|
* This method checks if there are Roads build by active Player on adjacent edges
|
||||||
|
*
|
||||||
* @param point point to check on
|
* @param point point to check on
|
||||||
* @return true if there is a road build next to the point.
|
* @return true if there is a road build next to the point.
|
||||||
*/
|
*/
|
||||||
|
@ -447,6 +446,7 @@ public class SiedlerGame {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if Adjacent Corners are empty
|
* Checks if Adjacent Corners are empty
|
||||||
|
*
|
||||||
* @param point Corner to check
|
* @param point Corner to check
|
||||||
* @return true if all Neighbour Corners are emtpy
|
* @return true if all Neighbour Corners are emtpy
|
||||||
*/
|
*/
|
||||||
|
@ -486,6 +486,7 @@ public class SiedlerGame {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Todo Java Doc
|
//Todo Java Doc
|
||||||
public int getCurrentPlayerWinPoints() {
|
public int getCurrentPlayerWinPoints() {
|
||||||
int winPoints = 0;
|
int winPoints = 0;
|
||||||
|
|
|
@ -4,9 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import ch.zhaw.catan.games.ThreePlayerStandard;
|
import ch.zhaw.catan.games.ThreePlayerStandard;
|
||||||
import org.beryx.textio.TextIO;
|
|
||||||
import org.beryx.textio.TextIoFactory;
|
|
||||||
import org.beryx.textio.TextTerminal;
|
|
||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
@ -45,7 +42,7 @@ public class SiedlerGameTest {
|
||||||
List<Config.Faction> factionList = Arrays.asList(Config.Faction.values());
|
List<Config.Faction> factionList = Arrays.asList(Config.Faction.values());
|
||||||
|
|
||||||
SiedlerBoard board = new SiedlerBoard();
|
SiedlerBoard board = new SiedlerBoard();
|
||||||
board.createFixGamefield();
|
board.createFixGameField();
|
||||||
board.setEdge(new Point(6, 6), new Point(5, 7), new Road(Config.Faction.BLUE,new Point(6, 6),new Point(5, 7)));
|
board.setEdge(new Point(6, 6), new Point(5, 7), new Road(Config.Faction.BLUE,new Point(6, 6),new Point(5, 7)));
|
||||||
board.setEdge(new Point(4, 6), new Point(5, 7), new Road(Config.Faction.BLUE,new Point(4, 6),new Point(5, 7)));
|
board.setEdge(new Point(4, 6), new Point(5, 7), new Road(Config.Faction.BLUE,new Point(4, 6),new Point(5, 7)));
|
||||||
board.setEdge(new Point(4, 6), new Point(4, 4), new Road(Config.Faction.BLUE,new Point(4, 6),new Point(4, 4)));
|
board.setEdge(new Point(4, 6), new Point(4, 4), new Road(Config.Faction.BLUE,new Point(4, 6),new Point(4, 4)));
|
||||||
|
|
Loading…
Reference in New Issue