Minor Grammar and Cameltow fixes

This commit is contained in:
Leonardo Brandenberger 2021-12-09 17:19:40 +01:00
parent f3b9cd2771
commit ffc97a39ef
11 changed files with 254 additions and 250 deletions

View File

@ -20,8 +20,7 @@ public class Bank {
Integer newResourceNumber = resources.get(resource) - numberOfResources;
resources.put(resource, newResourceNumber);
return true;
}
else {
} else {
return false;
}
}

View File

@ -8,11 +8,10 @@ public enum Command {
private final String commandWord;
Command(String commandWord) {
this.commandWord = commandWord;
}
public String toString() {
return commandWord;
}

View File

@ -2,7 +2,8 @@ package ch.zhaw.catan;
import java.util.HashMap;
import java.util.List;
//TODO Java Doc bearbeiten
//TODO Java Doc
/**
* New Class PLayer
* 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) {
//Data fields
this.faction = faction;
//Available Structures initialize
//Initialize available structures
structureToUse = new HashMap<>();
structureToUse.put(Config.Structure.ROAD, Config.Structure.ROAD.getStockPerPlayer());
structureToUse.put(Config.Structure.SETTLEMENT, Config.Structure.SETTLEMENT.getStockPerPlayer());
structureToUse.put(Config.Structure.CITY, Config.Structure.CITY.getStockPerPlayer());
//Resources initialize
//Initialize resources
resources = new HashMap<>();
for (Config.Resource resource : Config.Resource.values()) {
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 numberToSubstract how much to substract
* @return true if resource has been substracted false if player has not enough resources
* @param resource to subtract
* @param numberToSubtract how much to subtract
* @return true if resource has been subtracted false if player has not enough resources
*/
public boolean substractResource(Config.Resource resource, int numberToSubstract) {
int inPossesion = resources.get(resource);
if (inPossesion - numberToSubstract < 0) {
public boolean subtractResource(Config.Resource resource, int numberToSubtract) {
int inPossession = resources.get(resource);
if (inPossession - numberToSubtract < 0) {
return false;
}
resources.put(resource, inPossesion - numberToSubstract);
resources.put(resource, inPossession - numberToSubtract);
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
* in possession by the player.
* 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.
*/
public boolean build(Config.Structure structure) {

View File

@ -1,6 +1,7 @@
package ch.zhaw.catan;
import java.awt.Point;
import java.awt.*;
/// TODO: 09/12/2021 Java Doc
public class Road extends Structure {

View File

@ -1,6 +1,7 @@
package ch.zhaw.catan;
import java.awt.Point;
import java.awt.*;
//TODO Java Doc
public class Settlement extends Structure {

View File

@ -9,6 +9,7 @@ import java.util.Random;
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
*
* @param args There are no arguments needed.
*/
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.
*
* @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.
*/
@ -66,6 +68,7 @@ public class Siedler {
/**
* 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 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).
@ -83,6 +86,7 @@ public class Siedler {
/**
* 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 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.
*
* @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 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.
*
* @param parser The parser Object which will interact with the player.
* @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.
*
* @param parser The parser Object which will interact with the player.
* @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.
*
* @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 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 {
if (game.placeInitialSettlement(parser.getPoint(), payout)) {
successful = true;
}
else{
} else {
parser.errorMessage();
}
} while (!successful);
@ -182,8 +189,7 @@ public class Siedler {
do {
if (game.placeInitialRoad(parser.getPoint(), parser.getPoint())) {
successful = true;
}
else{
} else {
parser.errorMessage();
}
} while (!successful);

View File

@ -5,8 +5,15 @@ import ch.zhaw.hexboard.HexBoard;
import ch.zhaw.hexboard.Label;
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
/**
* Subclass of HexBoard
* 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.
*/
public void createFixGamefield(){
public void createFixGameField() {
Map<Point, Land> resourcePlacement = Config.getStandardLandPlacement();
Map<Point, Integer> dicePlacement = Config.getStandardDiceNumberPlacement();
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();
if (numberAsString.length() < 2) {
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])));
}
}
@ -44,6 +50,7 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
/**
* Method to get the DiceNumber of a specific field.
*
* @param field Point with coordinates of the specific 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.
*
* @return String of actual board.
*/
public String getTextView() {
@ -116,21 +124,21 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
lands[0] = getField(above);
lands[1] = 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[1] = 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 List.of(lands);
}
//TODO Java Doc no return
/**
* 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
* 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 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.
* 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 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 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.
*/
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) {
return roads;
}
Iterator<Road> it2 = roads.iterator();
while(it2.hasNext()) {
Road roadsroad = it2.next();
Iterator<Road> it3 = roadslist.iterator();
for (Road roadsRoad : roads) {
Iterator<Road> it3 = roadsList.iterator();
while (it3.hasNext()) {
Road roadslistRoad = it3.next();
if(roadslistRoad == roadsroad || roadslistRoad.getFaction() != faction) {
Road roadsListRoad = it3.next();
if (roadsListRoad == roadsRoad || roadsListRoad.getFaction() != faction) {
it3.remove();
}
}
}
if(roadslist.size() == 1) {
roads.add(roadslist.get(0));
position = getNextPoint(roadslist.get(0),position);
if (roadsList.size() == 1) {
roads.add(roadsList.get(0));
position = getNextPoint(roadsList.get(0), position);
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> listTwo = (HashSet<Road>) roads.clone();
listOne.add(roadslist.get(0));
Point positionOne = getNextPoint(roadslist.get(0),position);
listTwo.add(roadslist.get(1));
Point positionTwo = getNextPoint(roadslist.get(1),position);
listOne.add(roadsList.get(0));
Point positionOne = getNextPoint(roadsList.get(0), position);
listTwo.add(roadsList.get(1));
Point positionTwo = getNextPoint(roadsList.get(1), position);
listOne = countRoad(faction, positionOne, listOne, false);
listTwo = countRoad(faction, positionTwo, listTwo, false);
if (add) {
for (Road road : listOne) {
listTwo.add(road);
}
listTwo.addAll(listOne);
roads = listTwo;
} else {
HashSet<Road> tallest;
@ -232,52 +234,48 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
} else {
tallest = listTwo;
}
for (Road road : tallest) {
roads.add(road);
}
roads.addAll(tallest);
}
}
else if(roadslist.size() == 3) {
} else if (roadsList.size() == 3) {
HashSet<Road> listOne = (HashSet<Road>) roads.clone();
HashSet<Road> listTwo = (HashSet<Road>) roads.clone();
HashSet<Road> listThree = (HashSet<Road>) roads.clone();
listOne.add(roadslist.get(0));
Point positionOne = getNextPoint(roadslist.get(0),position);
listTwo.add(roadslist.get(1));
Point positionTwo = getNextPoint(roadslist.get(1),position);
listThree.add(roadslist.get(2));
Point positionThree = getNextPoint(roadslist.get(2),position);
listOne.add(roadsList.get(0));
Point positionOne = getNextPoint(roadsList.get(0), position);
listTwo.add(roadsList.get(1));
Point positionTwo = getNextPoint(roadsList.get(1), position);
listThree.add(roadsList.get(2));
Point positionThree = getNextPoint(roadsList.get(2), position);
listOne = countRoad(faction, positionOne, listOne, false);
listTwo = countRoad(faction, positionTwo, listTwo, false);
listThree = countRoad(faction, positionThree, listThree, false);
HashSet<Road> tallest;
HashSet<Road> secondtallest;
HashSet<Road> secondTallest;
if (listOne.size() >= listTwo.size()) {
tallest = listOne;
secondtallest = listTwo;
secondTallest = listTwo;
} else {
tallest = listTwo;
secondtallest = listOne;
}if(listThree.size() >= secondtallest.size()) {
secondtallest = listThree;
secondTallest = listOne;
}
for(Road road : secondtallest) {
tallest.add(road);
if (listThree.size() >= secondTallest.size()) {
secondTallest = listThree;
}
tallest.addAll(secondTallest);
roads = tallest;
}
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 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) {
Point start = road.getStart();

View File

@ -9,8 +9,6 @@ import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;
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 Bank bank;
private int activePlayer;
private HashMap<Config.Faction,Integer> longestRoadFaction;
private final HashMap<Config.Faction, Integer> longestRoadFaction;
/**
* Constructs a SiedlerGame game state object.
@ -45,7 +43,7 @@ public class SiedlerGame {
}
bank = new Bank();
board = new SiedlerBoard();
board.createFixGamefield();
board.createFixGameField();
allPlayers = new ArrayList<>();
createPlayer(numberOfPlayers);
activePlayer = 0;
@ -65,8 +63,7 @@ public class SiedlerGame {
public void switchToNextPlayer() {
if (activePlayer < allPlayers.size() - 1) {
activePlayer++;
}
else if (activePlayer == allPlayers.size() -1){
} else if (activePlayer == allPlayers.size() - 1) {
activePlayer = 0;
}
}
@ -77,11 +74,11 @@ public class SiedlerGame {
public void switchToPreviousPlayer() {
if (activePlayer > 0) {
activePlayer--;
}
else if (activePlayer == 0){
} else if (activePlayer == 0) {
activePlayer = allPlayers.size() - 1;
}
}
//TODO JavaDoc
private boolean addResourcesToPlayer(Player player, Resource resource, int numberToAdd) {
if (bank.getResourceFromBank(resource, numberToAdd)) {
@ -90,9 +87,10 @@ public class SiedlerGame {
}
return false;
}
//TODO JavaDoc
private boolean subtractResourceFromPlayer(Player player, Resource resource, int numberToSubtract) {
if(player.substractResource(resource, numberToSubtract)){
if (player.subtractResource(resource, numberToSubtract)) {
bank.storeResourceToBank(resource, numberToSubtract);
return true;
}
@ -117,11 +115,9 @@ public class SiedlerGame {
for (Player player : allPlayers) {
factions.add(player.getFaction());
}
return factions;
}
/**
* Returns the game board.
*
@ -242,6 +238,7 @@ public class SiedlerGame {
}
return null;
}
//TODO JavaDoc
public void handleDiceThrow7(Player player) {
ArrayList<Config.Resource> resourceArrayList = new ArrayList<>();
@ -261,7 +258,6 @@ public class SiedlerGame {
}
/**
* 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.
*
* @param roadStart the coordinates where the road begins.
* @param roadEnd the coordinates where the road ends.
* @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.
*
* @param position the position on the board to check for valid settlement position
* @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
*
* @param point point to check on
* @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
*
* @param point Corner to check
* @return true if all Neighbour Corners are emtpy
*/
@ -486,6 +486,7 @@ public class SiedlerGame {
}
return null;
}
//Todo Java Doc
public int getCurrentPlayerWinPoints() {
int winPoints = 0;

View File

@ -4,9 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
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 java.awt.*;
@ -45,7 +42,7 @@ public class SiedlerGameTest {
List<Config.Faction> factionList = Arrays.asList(Config.Faction.values());
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(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)));