Merge remote-tracking branch 'origin/main'

This commit is contained in:
Leonardo Brandenberger 2021-12-10 11:22:08 +01:00
commit 41174d30ad
5 changed files with 23 additions and 16 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-17" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_16" project-jdk-name="openjdk-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

View File

@ -5,6 +5,8 @@ import java.awt.Point;
/** /**
* Sub Class of Structure and Super Class of City * Sub Class of Structure and Super Class of City
* Can be saved in Siedler Board on a corner * Can be saved in Siedler Board on a corner
*
* @author Andrin Fassbind, Roman Schenk
*/ */
public class Settlement extends Structure { public class Settlement extends Structure {
@ -17,6 +19,8 @@ public class Settlement extends Structure {
} }
/** /**
* This Methode Returns the Position of the Settlement
*
* @return the datafield position * @return the datafield position
*/ */
public Point getPosition() { public Point getPosition() {

View File

@ -5,6 +5,8 @@ import java.util.Random;
/** /**
* This Class manages the game process and contains the Main Method which creates and starts a new Parser and a new Game. * This Class manages the game process and contains the Main Method which creates and starts a new Parser and a new Game.
*
* @author Leonardo Brandeberger, Roman Schenk
*/ */
public class Siedler { public class Siedler {
/** /**
@ -29,7 +31,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 Every turn or separate command? parser.displayGameboard(game.getBoard().getTextView());
parser.playerTurn(currentPlayerFaction); parser.playerTurn(currentPlayerFaction);
if (!diceThrown) { if (!diceThrown) {
throwDice(parser, game); throwDice(parser, game);

View File

@ -11,7 +11,6 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
//TODO Enhance JavaDoc
/** /**
* Subclass of HexBoard * Subclass of HexBoard
@ -22,12 +21,11 @@ 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.
* Key: Point with coordinates of the field * Key: Point with coordinates of the field
* //TODO Enhance JavaDoc
* Value: Field Object * Value: Field Object
*/ */
private final HashMap<Point, Field> fields = new HashMap<>(); private final HashMap<Point, Field> fields = new HashMap<>();
private Config.Faction longestRoadFaction = null; private Config.Faction longestRoadFaction = null;
private int longestRoadLenth = 0; private int longestRoadLength = 0;
/** /**
* Method to create the predefined game field from Config. * Method to create the predefined game field from Config.
@ -49,6 +47,15 @@ public class SiedlerBoard extends HexBoard<Config.Land, Settlement, Road, String
} }
} }
/**
* Get Paramter longestRoad
*
* @return longestRoadLength
*/
public int getLongestRoadLength() {
return longestRoadLength;
}
/** /**
* Method to get the DiceNumber of a specific field. * Method to get the DiceNumber of a specific field.
* *
@ -134,10 +141,9 @@ public class SiedlerBoard extends HexBoard<Config.Land, Settlement, Road, String
} }
return List.of(lands); return List.of(lands);
} }
//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.
* *
* @param factionList a List with all factions which can place structures on the board * @param factionList a List with all factions which can place structures on the board
* @return the faction who owns the longest road with minimum length of 5, null there is no road longer then 4 * @return the faction who owns the longest road with minimum length of 5, null there is no road longer then 4
@ -163,19 +169,14 @@ public class SiedlerBoard extends HexBoard<Config.Land, Settlement, Road, String
} }
for (Config.Faction factionA : players.keySet()) { for (Config.Faction factionA : players.keySet()) {
if (players.get(factionA) > longestRoadLenth && players.get(factionA) > 4) { if (players.get(factionA) > longestRoadLength && players.get(factionA) > 4) {
longestRoadFaction = factionA; longestRoadFaction = factionA;
longestRoadLenth = players.get(factionA); longestRoadLength = players.get(factionA);
} }
} }
return longestRoadFaction; return longestRoadFaction;
} }
//todo javadoc
public int getLongestRoadLenth() {
return longestRoadLenth;
}
/** /**
* 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.

View File

@ -41,7 +41,7 @@ public class SiedlerBoardTest {
System.out.println(board.getTextView()); System.out.println(board.getTextView());
assertEquals(Config.Faction.BLUE, board.getLongestRoadFaction(factionList)); assertEquals(Config.Faction.BLUE, board.getLongestRoadFaction(factionList));
assertEquals(6, board.getLongestRoadLenth()); assertEquals(6, board.getLongestRoadLength());
} }
@Test @Test
@ -50,7 +50,7 @@ public class SiedlerBoardTest {
System.out.println(board.getTextView()); System.out.println(board.getTextView());
assertEquals(Config.Faction.BLUE, board.getLongestRoadFaction(factionList)); assertEquals(Config.Faction.BLUE, board.getLongestRoadFaction(factionList));
assertEquals(5, board.getLongestRoadLenth()); assertEquals(5, board.getLongestRoadLength());
} }
} }