Merge remote-tracking branch 'origin/main'

This commit is contained in:
Leonardo Brandenberger
2021-12-10 18:34:41 +01:00
15 changed files with 155 additions and 93 deletions
+2 -22
View File
@@ -2,39 +2,19 @@ package ch.zhaw.catan;
import java.util.HashMap;
/**
* Bank Class that stores Resources when not being owned by a player,
* and the needed functions to take and give resources to it.
*
* @author Leonardo Brandenberger
*/
public class Bank {
private final HashMap<Config.Resource, Integer> resources = new HashMap<>();
/**
* Construct a Bank Object and stores Config Values in own HashMap.
*/
public Bank() {
resources.putAll(Config.INITIAL_RESOURCE_CARDS_BANK);
}
/**
* Stores a desired resource in desired quantity in the bank.
*
* @param resource the resource type that gets added to the bank
* @param numberOfResources the quantity of resources of the chosen type get added
*/
public void storeResourceToBank(Config.Resource resource, int numberOfResources) {
resources.put(resource, resources.get(resource) + numberOfResources);
}
/**
* Checks if a Resource is available in the quantity desired. and then deducts it from the bank inventory.
*
* @param resource the resource type that has to be deducted
* @param numberOfResources the quantity of the resource that gets deducted from the inventory
* @return true if resources available and deducted false if not enough resources are in the bank
*/
public boolean getResourceFromBank(Config.Resource resource, int numberOfResources) {
if (resources.get(resource) >= numberOfResources) {
Integer newResourceNumber = resources.get(resource) - numberOfResources;
-2
View File
@@ -8,10 +8,8 @@ package ch.zhaw.catan;
public enum Command {
NEXT_PLAYER("next player"), BUILD_SETTLEMENT("build settlement"), BUILD_CITY("build city"),
BUILD_ROAD("build road"), TRADE_WITH_BANK("trade with bank"), QUIT("quit");
private final String commandWord;
Command(String commandWord) {
this.commandWord = commandWord;
}
+5
View File
@@ -11,6 +11,11 @@ import java.util.List;
*/
public class Player {
/**
* faction: The faction of the player
* resources: The resources the player owns
* structureToUse: The structures a player can build.
*/
private final Config.Faction faction;
private final HashMap<Config.Resource, Integer> resources;
private final HashMap<Config.Structure, Integer> structureToUse;
+1 -1
View File
@@ -1,6 +1,6 @@
package ch.zhaw.catan;
import java.awt.Point;
import java.awt.*;
/**
* Sub Class of Structure and Super Class of City
+3 -3
View File
@@ -31,7 +31,7 @@ public class Siedler {
boolean diceThrown = false;
while (running) {
Config.Faction currentPlayerFaction = game.getCurrentPlayerFaction();
parser.displayGameboard(game.getBoard().getTextView());
parser.displayGameboard(game.getBoardTextView());
parser.playerTurn(currentPlayerFaction);
if (!diceThrown) {
throwDice(parser, game);
@@ -170,7 +170,7 @@ public class Siedler {
* @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.
*/
private static void buildStructuresInFoundingPhase(Parser parser, SiedlerGame game, Boolean payout) {
parser.displayGameboard(game.getBoard().getTextView());
parser.displayGameboard(game.getBoardTextView());
parser.playerTurn(game.getCurrentPlayerFaction());
//build Settlement
@@ -185,7 +185,7 @@ public class Siedler {
} while (!successful);
//build Road
parser.displayGameboard(game.getBoard().getTextView());
parser.displayGameboard(game.getBoardTextView());
parser.giveCoordinatesForStructures(Config.Structure.ROAD);
successful = false;
do {
+1 -2
View File
@@ -2,7 +2,6 @@ package ch.zhaw.catan;
import ch.zhaw.hexboard.HexBoard;
import ch.zhaw.hexboard.Label;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Collections;
@@ -73,7 +72,7 @@ public class SiedlerBoard extends HexBoard<Config.Land, Settlement, Road, String
*
* @return String of actual board.
*/
public String getTextView() {
public String toString() {
SiedlerBoardTextView view = new SiedlerBoardTextView(this);
for (Map.Entry<Point, Field> field : fields.entrySet()) {
view.setLowerFieldLabel(field.getKey(), field.getValue().getLabel());
+6 -4
View File
@@ -3,11 +3,13 @@ package ch.zhaw.catan;
import ch.zhaw.catan.Config.Land;
import ch.zhaw.hexboard.HexBoardTextView;
//TODO Java Docs
/**
* This Class extends the Class HexBoardTextView
*/
public class SiedlerBoardTextView extends HexBoardTextView<Land, Settlement, Road, String> {
public SiedlerBoardTextView(SiedlerBoard board) {
super(board);
}
public SiedlerBoardTextView(SiedlerBoard board) {
super(board);
}
}
+44 -15
View File
@@ -1,19 +1,17 @@
package ch.zhaw.catan;
import java.awt.Point;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
* This class performs all actions related to modifying the game state.
* <p>
* TODO: (your documentation)
*
* @author TODO
* @author Andrin Fassbind, Leonardo Brandenberger, Roman Schenk, Stefan Amador
*/
public class SiedlerGame {
static final int FOUR_TO_ONE_TRADE_OFFER = 4;
@@ -34,9 +32,6 @@ public class SiedlerGame {
* or players is not between two and four
*/
public SiedlerGame(int winPoints, int numberOfPlayers) {
if (winPoints < 3 || numberOfPlayers < Config.MIN_NUMBER_OF_PLAYERS || numberOfPlayers > 4) {
throw new IllegalArgumentException();
}
bank = new Bank();
board = new SiedlerBoard();
board.createFixGameField();
@@ -74,7 +69,14 @@ public class SiedlerGame {
}
}
//TODO JavaDoc
/**
* This methode is used to add resources to the player.
*
* @param player the active Player
* @param resource the resource to add
* @param numberToAdd the quantity of resources to add
* @return true if resource has been added else false
*/
private boolean addResourcesToPlayer(Player player, Config.Resource resource, int numberToAdd) {
if (bank.getResourceFromBank(resource, numberToAdd)) {
player.addResource(resource, numberToAdd);
@@ -83,7 +85,14 @@ public class SiedlerGame {
return false;
}
//TODO JavaDoc
/**
* This methode is used to subtract resources from Player
*
* @param player the active player
* @param resource the resource to subtract
* @param numberToSubtract the quantity of resource to subtract
* @return true if resource has been subtracted
*/
private boolean subtractResourceFromPlayer(Player player, Config.Resource resource, int numberToSubtract) {
if (player.subtractResource(resource, numberToSubtract)) {
bank.storeResourceToBank(resource, numberToSubtract);
@@ -114,7 +123,7 @@ public class SiedlerGame {
}
/**
* Returns the game board.
* Returns the game board. Used for test
*
* @return the game board
*/
@@ -122,6 +131,13 @@ public class SiedlerGame {
return board;
}
/**
* Returns the String used to show the Board
*
* @return String of the Board.
*/
public String getBoardTextView(){return board.toString();}
/**
* Returns the {@link Config.Faction} of the current player.
*
@@ -142,6 +158,11 @@ public class SiedlerGame {
return allPlayers.get(activePlayer).getSpecificResource(resource);
}
/**
* Returns the resources of the current player.
*
* @return a hashmap with all resources the player has. Key: Resource name Value: number of resources
*/
public HashMap<Config.Resource, Integer> getCurrentPlayerResource() {
return allPlayers.get(activePlayer).getResources();
}
@@ -234,7 +255,11 @@ public class SiedlerGame {
return null;
}
//TODO JavaDoc
/**
* This method handles the case if a 7 has been diced.
*
* @param player the active player who rolls the dice.
*/
public void handleDiceThrow7(Player player) {
ArrayList<Config.Resource> resourceArrayList = new ArrayList<>();
HashMap<Config.Resource, Integer> resources = player.getResources();
@@ -376,7 +401,7 @@ public class SiedlerGame {
if (!board.hasEdge(roadStart, roadEnd)) {
return false;
}
//2. Check if edge is empty //TODO Check if always inverted is allowed
//2. Check if edge is empty
if (board.getEdge(roadStart, roadEnd) != null) {
return false;
}
@@ -482,7 +507,11 @@ public class SiedlerGame {
return null;
}
//Todo Java Doc
/**
* This methode counts the winpoints of the current player.
*
* @return the winpoints as an integer
*/
public int getCurrentPlayerWinPoints() {
int winPoints = 0;
List<Settlement> settlements = board.getCorners();