SiedlerGame.java added few methodes
This commit is contained in:
parent
3ddd86e4e1
commit
971cfe8868
|
@ -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_17" default="true" project-jdk-name="openjdk-17" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" 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>
|
|
@ -9,15 +9,13 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class Player {
|
public class Player {
|
||||||
|
|
||||||
private String name;
|
|
||||||
private Config.Faction faction;
|
private Config.Faction faction;
|
||||||
private HashMap<Config.Resource,Integer> resources;
|
private HashMap<Config.Resource,Integer> resources;
|
||||||
private int roadsToUse;
|
private int roadsToUse;
|
||||||
private int settlementsToUse;
|
private int settlementsToUse;
|
||||||
|
|
||||||
public Player (String name, Config.Faction faction){
|
public Player (Config.Faction faction){
|
||||||
//Datenfelder
|
//Datenfelder
|
||||||
this.name = name;
|
|
||||||
this.faction = faction;
|
this.faction = faction;
|
||||||
roadsToUse = Config.Structure.ROAD.getStockPerPlayer();
|
roadsToUse = Config.Structure.ROAD.getStockPerPlayer();
|
||||||
settlementsToUse = Config.Structure.SETTLEMENT.getStockPerPlayer();
|
settlementsToUse = Config.Structure.SETTLEMENT.getStockPerPlayer();
|
||||||
|
|
|
@ -7,6 +7,7 @@ import org.beryx.textio.TextIoFactory;
|
||||||
import org.beryx.textio.TextTerminal;
|
import org.beryx.textio.TextTerminal;
|
||||||
|
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -14,39 +15,48 @@ import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class performs all actions related to modifying the game state.
|
* This class performs all actions related to modifying the game state.
|
||||||
*
|
* <p>
|
||||||
* TODO: (your documentation)
|
* TODO: (your documentation)
|
||||||
*
|
*
|
||||||
* @author TODO
|
* @author TODO
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class SiedlerGame {
|
public class SiedlerGame {
|
||||||
static final int FOUR_TO_ONE_TRADE_OFFER = 4;
|
static final int FOUR_TO_ONE_TRADE_OFFER = 4;
|
||||||
static final int FOUR_TO_ONE_TRADE_WANT = 1;
|
static final int FOUR_TO_ONE_TRADE_WANT = 1;
|
||||||
|
|
||||||
private SiedlerBoard board;
|
private SiedlerBoard board;
|
||||||
private Player[] allPlayers;
|
private ArrayList<Player> allPlayers;
|
||||||
private int winPoints;
|
private int winPoints;
|
||||||
private Bank bank;
|
private Bank bank;
|
||||||
private Player activePlayer;
|
private int activePlayer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a SiedlerGame game state object.
|
* Constructs a SiedlerGame game state object.
|
||||||
*
|
*
|
||||||
* @param winPoints the number of points required to win the game
|
* @param winPoints the number of points required to win the game
|
||||||
* @param numberOfPlayers the number of players
|
* @param numberOfPlayers the number of players
|
||||||
*
|
|
||||||
* @throws IllegalArgumentException if winPoints is lower than
|
* @throws IllegalArgumentException if winPoints is lower than
|
||||||
* three or players is not between two and four
|
* three or players is not between two and four
|
||||||
*/
|
*/
|
||||||
public SiedlerGame(int winPoints, int numberOfPlayers) {
|
public SiedlerGame(int winPoints, int numberOfPlayers) {
|
||||||
|
if(winPoints < 3 || numberOfPlayers < 2 || numberOfPlayers > 4) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
bank = new Bank();
|
bank = new Bank();
|
||||||
board = new SiedlerBoard();
|
board = new SiedlerBoard();
|
||||||
board.createFixGamefield();
|
board.createFixGamefield();
|
||||||
allPlayers = new Player[numberOfPlayers];
|
allPlayers = new ArrayList<>();
|
||||||
|
createPlayer(numberOfPlayers);
|
||||||
|
activePlayer = 0;
|
||||||
this.winPoints = winPoints;
|
this.winPoints = winPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createPlayer(int numberOfPlayers) {
|
||||||
|
for (int i = 0; i < numberOfPlayers; i++) {
|
||||||
|
allPlayers.add(new Player(Config.Faction.values()[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Switches to the next player in the defined sequence of players.
|
* Switches to the next player in the defined sequence of players.
|
||||||
*/
|
*/
|
||||||
|
@ -76,10 +86,12 @@ public class SiedlerGame {
|
||||||
*/
|
*/
|
||||||
public List<Faction> getPlayerFactions() {
|
public List<Faction> getPlayerFactions() {
|
||||||
// TODO: Implement
|
// TODO: Implement
|
||||||
Faction[] factions = new Faction[allPlayers.length];
|
List<Faction> factions = new ArrayList<>();
|
||||||
|
for (Player player: allPlayers ) {
|
||||||
|
factions.add(player.getFaction());
|
||||||
|
}
|
||||||
|
|
||||||
|
return factions;
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,7 +101,6 @@ public class SiedlerGame {
|
||||||
* @return the game board
|
* @return the game board
|
||||||
*/
|
*/
|
||||||
public SiedlerBoard getBoard() {
|
public SiedlerBoard getBoard() {
|
||||||
// TODO: Implement
|
|
||||||
return board;
|
return board;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,8 +110,7 @@ public class SiedlerGame {
|
||||||
* @return the faction of the current player
|
* @return the faction of the current player
|
||||||
*/
|
*/
|
||||||
public Faction getCurrentPlayerFaction() {
|
public Faction getCurrentPlayerFaction() {
|
||||||
// TODO: Implement
|
return allPlayers.get(activePlayer).getFaction();
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -111,8 +121,8 @@ public class SiedlerGame {
|
||||||
* @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(Resource resource) {
|
||||||
// TODO: Implement
|
int ressourceInStock = allPlayers.get(activePlayer).getSpecificResource(resource);
|
||||||
return 0;
|
return ressourceInStock;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,12 +157,12 @@ public class SiedlerGame {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method takes care of actions depending on the dice throw result.
|
* This method takes care of actions depending on the dice throw result.
|
||||||
*
|
* <p>
|
||||||
* A key action is the payout of the resource cards to the players
|
* A key action is the payout of the resource cards to the players
|
||||||
* according to the payout rules of the game. This includes the
|
* according to the payout rules of the game. This includes the
|
||||||
* "negative payout" in case a 7 is thrown and a player has more than
|
* "negative payout" in case a 7 is thrown and a player has more than
|
||||||
* {@link Config#MAX_CARDS_IN_HAND_NO_DROP} resource cards.
|
* {@link Config#MAX_CARDS_IN_HAND_NO_DROP} resource cards.
|
||||||
*
|
* <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 Faction} is <b>an empty list (not null)</b>!.
|
||||||
*
|
*
|
||||||
|
@ -185,9 +195,25 @@ public class SiedlerGame {
|
||||||
* @return true, if the placement was successful
|
* @return true, if the placement was successful
|
||||||
*/
|
*/
|
||||||
public boolean buildSettlement(Point position) {
|
public boolean buildSettlement(Point position) {
|
||||||
// TODO: Implement
|
//1. Check if Edge
|
||||||
|
if (!board.hasCorner(position)) {
|
||||||
|
// TODO: Error message
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
//2. Check if Edge is empty
|
||||||
|
if (board.getCorner(position) != null) {
|
||||||
|
// TODO: Error message
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//3. Can Player build road
|
||||||
|
if (!allPlayers.get(activePlayer).buildSettlement()) {
|
||||||
|
// TODO: Error message
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//4. Insert Road to map
|
||||||
|
board.setCorner(position, new Settlement(allPlayers.get(activePlayer).getFaction()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a city at the specified position on the board.
|
* Builds a city at the specified position on the board.
|
||||||
|
@ -225,23 +251,28 @@ public class SiedlerGame {
|
||||||
//1. Check if Edge
|
//1. Check if Edge
|
||||||
if (!board.hasEdge(roadStart, roadEnd)) {
|
if (!board.hasEdge(roadStart, roadEnd)) {
|
||||||
// TODO: Error message
|
// TODO: Error message
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
//2. Check if Edge is empty
|
//2. Check if Edge is empty
|
||||||
if (board.getEdge(roadStart, roadEnd) != null) {
|
if (board.getEdge(roadStart, roadEnd) != null) {
|
||||||
// TODO: Error message
|
// TODO: Error message
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
//3. Can Player build road
|
//3. Can Player build road
|
||||||
// TODO
|
if (!allPlayers.get(activePlayer).buildRoad()) {
|
||||||
|
// TODO: Error message
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
//4. Insert Road to map
|
||||||
|
board.setEdge(roadStart, roadEnd, new Road(allPlayers.get(activePlayer).getFaction()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trades in {@link #FOUR_TO_ONE_TRADE_OFFER} resource cards of the
|
* Trades in {@link #FOUR_TO_ONE_TRADE_OFFER} resource cards of the
|
||||||
* offered type for {@link #FOUR_TO_ONE_TRADE_WANT} resource cards of the wanted type.
|
* offered type for {@link #FOUR_TO_ONE_TRADE_WANT} resource cards of the wanted type.
|
||||||
*
|
* <p>
|
||||||
* The trade only works when bank and player possess the resource cards
|
* The trade only works when bank and player possess the resource cards
|
||||||
* for the trade before the trade is executed.
|
* for the trade before the trade is executed.
|
||||||
*
|
*
|
||||||
|
|
|
@ -6,4 +6,8 @@ public abstract class Structure {
|
||||||
public Structure(Config.Faction faction) {
|
public Structure(Config.Faction faction) {
|
||||||
this.faction = faction;
|
this.faction = faction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Config.Faction getFaction() {
|
||||||
|
return faction;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue