Merge remote-tracking branch 'origin/main'

# Conflicts:
#	src/ch/zhaw/catan/Settlement.java
This commit is contained in:
schrom01 2021-12-09 18:19:19 +01:00
commit 378fdde58a
8 changed files with 40 additions and 46 deletions

View File

@ -2,8 +2,8 @@ package ch.zhaw.catan;
//TODO:JavaDoc //TODO:JavaDoc
public enum Command { public enum Command {
NEXTPLAYER("next player"), BUILDSETTLEMENT("build settlement"), BUILDCITY("build city"), NEXT_PLAYER("next player"), BUILD_SETTLEMENT("build settlement"), BUILD_CITY("build city"),
BUILDROAD("build road"), TRADEWITHBANK("trade with bank"), QUIT("quit"); BUILD_ROAD("build road"), TRADE_WITH_BANK("trade with bank"), QUIT("quit");
private final String commandWord; private final String commandWord;

View File

@ -4,7 +4,7 @@ import ch.zhaw.hexboard.Label;
public class Field { public class Field {
private Config.Land land; private final Config.Land land;
private final Label label; private final Label label;
public Field(Config.Land land, Label label) { public Field(Config.Land land, Label label) {

View File

@ -13,8 +13,8 @@ import java.util.HashMap;
* @author Leonardo Brandenberger * @author Leonardo Brandenberger
*/ */
public class Parser { public class Parser {
TextIO textIO; private final TextIO textIO;
TextTerminal<?> textTerminal; private final TextTerminal<?> textTerminal;
/** /**
* Constructs a parser Object, initializes the textIO components TextTerminal and textIO. * Constructs a parser Object, initializes the textIO components TextTerminal and textIO.

View File

@ -9,7 +9,7 @@ import java.awt.*;
public class Settlement extends Structure { public class Settlement extends Structure {
//the coordinates of the position on the board //the coordinates of the position on the board
private Point position; private final Point position;
public Settlement(Config.Faction faction, Point position) { public Settlement(Config.Faction faction, Point position) {
super(faction); super(faction);

View File

@ -29,7 +29,7 @@ public class Siedler {
boolean diceThrown = false; boolean diceThrown = false;
while (running) { while (running) {
Config.Faction currentPlayerFaction = game.getCurrentPlayerFaction(); Config.Faction currentPlayerFaction = game.getCurrentPlayerFaction();
parser.displayGameboard(game.getBoard().getTextView()); //todo jedesmal ausgeben? oder nur wenn neuer Spieler oder separater Befehl? parser.displayGameboard(game.getBoard().getTextView()); //TODO Every turn or separate command?
parser.playerTurn(currentPlayerFaction); parser.playerTurn(currentPlayerFaction);
if (!diceThrown) { if (!diceThrown) {
throwDice(parser, game); throwDice(parser, game);
@ -37,23 +37,23 @@ public class Siedler {
} }
parser.displayPlayerInfo(game.getCurrentPlayerResource(), game.getCurrentPlayerWinPoints()); parser.displayPlayerInfo(game.getCurrentPlayerResource(), game.getCurrentPlayerWinPoints());
switch (parser.getAction()) { switch (parser.getAction()) {
case NEXTPLAYER: case NEXT_PLAYER:
if (caseNextPlayer(parser, game)) { if (caseNextPlayer(parser, game)) {
running = false; running = false;
} else { } else {
diceThrown = false; diceThrown = false;
} }
break; break;
case BUILDSETTLEMENT: case BUILD_SETTLEMENT:
caseBuildStructure(parser, game, Config.Structure.SETTLEMENT); caseBuildStructure(parser, game, Config.Structure.SETTLEMENT);
break; break;
case BUILDCITY: case BUILD_CITY:
caseBuildStructure(parser, game, Config.Structure.CITY); caseBuildStructure(parser, game, Config.Structure.CITY);
break; break;
case BUILDROAD: case BUILD_ROAD:
caseBuildStructure(parser, game, Config.Structure.ROAD); caseBuildStructure(parser, game, Config.Structure.ROAD);
break; break;
case TRADEWITHBANK: case TRADE_WITH_BANK:
caseTradeWithBank(parser, game); caseTradeWithBank(parser, game);
break; break;
case QUIT: case QUIT:

View File

@ -1,6 +1,5 @@
package ch.zhaw.catan; package ch.zhaw.catan;
import ch.zhaw.catan.Config.Land;
import ch.zhaw.hexboard.HexBoard; import ch.zhaw.hexboard.HexBoard;
import ch.zhaw.hexboard.Label; import ch.zhaw.hexboard.Label;
@ -18,7 +17,7 @@ import java.util.Collections;
* 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.
*/ */
public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> { public class SiedlerBoard extends HexBoard<Config.Land, Settlement, Road, String> {
/** /**
* HashMap to save all Fields which are set yet. * HashMap to save all Fields which are set yet.
@ -26,7 +25,7 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
* //TODO Enhance JavaDoc * //TODO Enhance JavaDoc
* Value: Field Object * Value: Field Object
*/ */
HashMap<Point, Field> fields = new HashMap<>(); private final HashMap<Point, Field> fields = new HashMap<>();
Config.Faction longestRoadFaction = null; Config.Faction longestRoadFaction = null;
int longestRoadLenth = 0; int longestRoadLenth = 0;
@ -34,9 +33,9 @@ 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, Config.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, Config.Land> resourceField : resourcePlacement.entrySet()) {
addField(resourceField.getKey(), resourceField.getValue()); addField(resourceField.getKey(), resourceField.getValue());
if (dicePlacement.get(resourceField.getKey()) != null) { if (dicePlacement.get(resourceField.getKey()) != null) {
String numberAsString = dicePlacement.get(resourceField.getKey()).toString(); String numberAsString = dicePlacement.get(resourceField.getKey()).toString();
@ -113,15 +112,15 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
} }
/** /**
* Returns the {@link Land}s adjacent to the specified corner. * Returns the {@link Config.Land}s adjacent to the specified corner.
* *
* @param corner the corner * @param corner the corner
* @return the list with the adjacent {@link Land}s * @return the list with the adjacent {@link Config.Land}s
*/ */
public List<Land> getLandsForCorner(Point corner) { public List<Config.Land> getLandsForCorner(Point corner) {
Point above = new Point(corner.x, corner.y + 2); Point above = new Point(corner.x, corner.y + 2);
Point below = new Point(corner.x, corner.y - 2); Point below = new Point(corner.x, corner.y - 2);
Land[] lands = new Land[3]; Config.Land[] lands = new Config.Land[3];
if (hasField(above)) { if (hasField(above)) {
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));
@ -135,13 +134,11 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
} }
return List.of(lands); return List.of(lands);
} }
//TODO Java Doc no return //TODO Java Doc more details
/** /**
* This method checks for the player with the longest road according to the siedler 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 siedler game rules
* and the Integer representing the length of the road
*/ */
public Config.Faction getLongestRoadFaction(List<Config.Faction> factionList) { public Config.Faction getLongestRoadFaction(List<Config.Faction> factionList) {
List<Settlement> corners = getCorners(); List<Settlement> corners = getCorners();

View File

@ -1,8 +1,5 @@
package ch.zhaw.catan; package ch.zhaw.catan;
import ch.zhaw.catan.Config.Faction;
import ch.zhaw.catan.Config.Resource;
import java.awt.Point; import java.awt.Point;
import java.util.Map; import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
@ -78,7 +75,7 @@ public class SiedlerGame {
} }
//TODO JavaDoc //TODO JavaDoc
private boolean addResourcesToPlayer(Player player, Resource resource, int numberToAdd) { private boolean addResourcesToPlayer(Player player, Config.Resource resource, int numberToAdd) {
if (bank.getResourceFromBank(resource, numberToAdd)) { if (bank.getResourceFromBank(resource, numberToAdd)) {
player.addResource(resource, numberToAdd); player.addResource(resource, numberToAdd);
return true; return true;
@ -87,7 +84,7 @@ public class SiedlerGame {
} }
//TODO JavaDoc //TODO JavaDoc
private boolean subtractResourceFromPlayer(Player player, Resource resource, int numberToSubtract) { private boolean subtractResourceFromPlayer(Player player, Config.Resource resource, int numberToSubtract) {
if (player.subtractResource(resource, numberToSubtract)) { if (player.subtractResource(resource, numberToSubtract)) {
bank.storeResourceToBank(resource, numberToSubtract); bank.storeResourceToBank(resource, numberToSubtract);
return true; return true;
@ -96,7 +93,7 @@ public class SiedlerGame {
} }
/** /**
* Returns the {@link Faction}s of the active players. * Returns the {@link Config.Faction}s of the active players.
* *
* <p>The order of the player's factions in the list must * <p>The order of the player's factions in the list must
* correspond to the oder in which they play. * correspond to the oder in which they play.
@ -108,8 +105,8 @@ public class SiedlerGame {
* *
* @return the list with player's factions * @return the list with player's factions
*/ */
public List<Faction> getPlayerFactions() { public List<Config.Faction> getPlayerFactions() {
List<Faction> factions = new ArrayList<>(); List<Config.Faction> factions = new ArrayList<>();
for (Player player : allPlayers) { for (Player player : allPlayers) {
factions.add(player.getFaction()); factions.add(player.getFaction());
} }
@ -126,11 +123,11 @@ public class SiedlerGame {
} }
/** /**
* Returns the {@link Faction} of the current player. * Returns the {@link Config.Faction} of the current player.
* *
* @return the faction of the current player * @return the faction of the current player
*/ */
public Faction getCurrentPlayerFaction() { public Config.Faction getCurrentPlayerFaction() {
return allPlayers.get(activePlayer).getFaction(); return allPlayers.get(activePlayer).getFaction();
} }
@ -141,11 +138,11 @@ public class SiedlerGame {
* @param resource the resource type * @param resource the resource type
* @return the number of resource cards of this type * @return the number of resource cards of this type
*/ */
public int getCurrentPlayerResourceStock(Resource resource) { public int getCurrentPlayerResourceStock(Config.Resource resource) {
return allPlayers.get(activePlayer).getSpecificResource(resource); return allPlayers.get(activePlayer).getSpecificResource(resource);
} }
public HashMap<Resource, Integer> getCurrentPlayerResource() { public HashMap<Config.Resource, Integer> getCurrentPlayerResource() {
return allPlayers.get(activePlayer).getResources(); return allPlayers.get(activePlayer).getResources();
} }
@ -202,7 +199,7 @@ public class SiedlerGame {
* {@link Config#MAX_CARDS_IN_HAND_NO_DROP} resource cards. * {@link Config#MAX_CARDS_IN_HAND_NO_DROP} resource cards.
* <p> * <p>
* If a player does not get resource cards, the list for this players' * If a player does not get resource cards, the list for this players'
* {@link Faction} is <b>an empty list (not null)</b>!. * {@link Config.Faction} is <b>an empty list (not null)</b>!.
* *
* <p> * <p>
* The payout rules of the game take into account factors such as, the number * The payout rules of the game take into account factors such as, the number
@ -214,18 +211,18 @@ public class SiedlerGame {
* @param diceThrow the resource cards that have been distributed to the players * @param diceThrow the resource cards that have been distributed to the players
* @return the resource cards added to the stock of the different players * @return the resource cards added to the stock of the different players
*/ */
public Map<Faction, List<Resource>> throwDice(int diceThrow) { public Map<Config.Faction, List<Config.Resource>> throwDice(int diceThrow) {
if (diceThrow == 7) { if (diceThrow == 7) {
for (Player player : allPlayers) { for (Player player : allPlayers) {
handleDiceThrow7(player); handleDiceThrow7(player);
} }
} else { } else {
Map<Faction, List<Resource>> returnMap = new HashMap<>(); Map<Config.Faction, List<Config.Resource>> returnMap = new HashMap<>();
List<Point> diceValueFields = board.getFieldsForDiceValue(diceThrow); List<Point> diceValueFields = board.getFieldsForDiceValue(diceThrow);
for (Player player : allPlayers) { for (Player player : allPlayers) {
returnMap.put(player.getFaction(), new ArrayList<>()); returnMap.put(player.getFaction(), new ArrayList<>());
for (Point field : diceValueFields) { for (Point field : diceValueFields) {
List<Resource> resources = board.getResourcesForFaction(field, player.getFaction()); List<Config.Resource> resources = board.getResourcesForFaction(field, player.getFaction());
for (Config.Resource resource : resources) { for (Config.Resource resource : resources) {
returnMap.get(player.getFaction()).add(resource); returnMap.get(player.getFaction()).add(resource);
addResourcesToPlayer(player, resource, 1); addResourcesToPlayer(player, resource, 1);
@ -240,7 +237,7 @@ public class SiedlerGame {
//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<>();
HashMap<Resource, Integer> resources = player.getResources(); HashMap<Config.Resource, Integer> resources = player.getResources();
for (Config.Resource resource : resources.keySet()) { for (Config.Resource resource : resources.keySet()) {
for (int i = 0; i < resources.get(resource); i++) { for (int i = 0; i < resources.get(resource); i++) {
resourceArrayList.add(resource); resourceArrayList.add(resource);
@ -379,7 +376,7 @@ public class SiedlerGame {
if (!board.hasEdge(roadStart, roadEnd)) { if (!board.hasEdge(roadStart, roadEnd)) {
return false; return false;
} }
//2. Check if edge is empty //2. Check if edge is empty //TODO Check if always inverted is allowed
if (board.getEdge(roadStart, roadEnd) != null) { if (board.getEdge(roadStart, roadEnd) != null) {
return false; return false;
} }
@ -446,7 +443,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 empty
*/ */
private boolean checkAdjacentCornerList(Point point) { private boolean checkAdjacentCornerList(Point point) {
List<Settlement> results = board.getNeighboursOfCorner(point); List<Settlement> results = board.getNeighboursOfCorner(point);
@ -464,7 +461,7 @@ public class SiedlerGame {
* @param want wanted type * @param want wanted type
* @return true, if the trade was successful * @return true, if the trade was successful
*/ */
public boolean tradeWithBankFourToOne(Resource offer, Resource want) { public boolean tradeWithBankFourToOne(Config.Resource offer, Config.Resource want) {
Player player = allPlayers.get(activePlayer); Player player = allPlayers.get(activePlayer);
if (player.getSpecificResource(offer) >= FOUR_TO_ONE_TRADE_OFFER && addResourcesToPlayer(player, want, FOUR_TO_ONE_TRADE_WANT)) { if (player.getSpecificResource(offer) >= FOUR_TO_ONE_TRADE_OFFER && addResourcesToPlayer(player, want, FOUR_TO_ONE_TRADE_WANT)) {
subtractResourceFromPlayer(player, offer, FOUR_TO_ONE_TRADE_OFFER); subtractResourceFromPlayer(player, offer, FOUR_TO_ONE_TRADE_OFFER);
@ -478,7 +475,7 @@ public class SiedlerGame {
* *
* @return the winner of the game or null, if there is no winner (yet) * @return the winner of the game or null, if there is no winner (yet)
*/ */
public Faction getWinner() { public Config.Faction getWinner() {
if (getCurrentPlayerWinPoints() >= winPointsForWin) { if (getCurrentPlayerWinPoints() >= winPointsForWin) {
return getCurrentPlayerFaction(); return getCurrentPlayerFaction();
} }

View File

@ -1,7 +1,7 @@
package ch.zhaw.catan; package ch.zhaw.catan;
public abstract class Structure { public abstract class Structure {
private Config.Faction faction; private final Config.Faction faction;
public Structure(Config.Faction faction) { public Structure(Config.Faction faction) {
this.faction = faction; this.faction = faction;