removed to do's and updated java docs.
This commit is contained in:
parent
99da9715c5
commit
cff925de61
|
@ -4,17 +4,20 @@ import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New Class PLayer
|
* New Class PLayer
|
||||||
* This class is here to add players to the game.
|
* This class is here in order to maintain the resources of the players, the amount of structures that they can build,
|
||||||
|
* control to see if a player has enough to build a new structure and to add them into a faction.
|
||||||
*/
|
*/
|
||||||
public class Player {
|
public class Player {
|
||||||
|
|
||||||
private Config.Faction faction;
|
private Config.Faction faction;
|
||||||
private HashMap<Config.Resource, Integer> resources;
|
private HashMap<Config.Resource, Integer> resources;
|
||||||
private HashMap<Config.Structure, Integer> structureToUse;
|
private HashMap<Config.Structure, Integer> structureToUse;
|
||||||
private int roadsToUse;
|
|
||||||
private int settlementsToUse;
|
|
||||||
private int citiesToUse;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The constructor creates a new instance of the player class that initializes the Hashmap resources and structureToUse.
|
||||||
|
*
|
||||||
|
* @param faction this is the faction of the player.
|
||||||
|
*/
|
||||||
public Player(Config.Faction faction) {
|
public Player(Config.Faction faction) {
|
||||||
//Datenfelder
|
//Datenfelder
|
||||||
this.faction = faction;
|
this.faction = faction;
|
||||||
|
@ -30,9 +33,9 @@ public class Player {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns all the resources the player has at the moment
|
* This method returns all the resources the player has at the moment
|
||||||
|
*
|
||||||
* @return HashMap with the count of every resource
|
* @return HashMap with the count of every resource
|
||||||
*/
|
*/
|
||||||
public HashMap<Config.Resource, Integer> getResources() {
|
public HashMap<Config.Resource, Integer> getResources() {
|
||||||
|
@ -41,19 +44,26 @@ public class Player {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns player faction
|
* This method returns player faction
|
||||||
* @return
|
*
|
||||||
|
* @return the faction of the player.
|
||||||
*/
|
*/
|
||||||
public Config.Faction getFaction() { return faction; }
|
public Config.Faction getFaction() {
|
||||||
|
return faction;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns for specific resource how much player possesess.
|
* This method returns the amount of a specific resource that a player owns.
|
||||||
* @param resource
|
*
|
||||||
* @return
|
* @param resource the resource that is needed.
|
||||||
|
* @return the amount of the specific resource.
|
||||||
*/
|
*/
|
||||||
public int getSpecificResource(Config.Resource resource) { return resources.get(resource); }
|
public int getSpecificResource(Config.Resource resource) {
|
||||||
|
return resources.get(resource);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method adds a specific resource to resourcess
|
* This method adds a specific resource to resourcess
|
||||||
|
*
|
||||||
* @param resource to add
|
* @param resource to add
|
||||||
* @param numberToAdd how much to add
|
* @param numberToAdd how much to add
|
||||||
*/
|
*/
|
||||||
|
@ -63,6 +73,7 @@ public class Player {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method substracts a specific resource from resourcess but check first if player has enough resources.
|
* This method substracts a specific resource from resourcess but check first if player has enough resources.
|
||||||
|
*
|
||||||
* @param resource to substract
|
* @param resource to substract
|
||||||
* @param numberToSubstract how much to substract
|
* @param numberToSubstract how much to substract
|
||||||
* @return true if resource has been substracted false if player has not enough resources
|
* @return true if resource has been substracted false if player has not enough resources
|
||||||
|
@ -76,12 +87,12 @@ public class Player {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo java doc aktualisieren
|
|
||||||
/**
|
/**
|
||||||
* This method has to be used when a player wants to build a settlement. It checks if a player has enough roads
|
* This method has to be used when a player wants to build a structure. It checks if a player has enough of the specific structure
|
||||||
* and resources to build one more. If the player is able to build, this method subtracts the buildcost from the resources
|
* and resources to build one more. If the player is able to build, this method subtracts the buildcost from the resources
|
||||||
* in possession by the player.
|
* in possession by the player.
|
||||||
* @return true if road can be created false if road can't be created.
|
* 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) {
|
public boolean build(Config.Structure structure) {
|
||||||
List<Config.Resource> costs = structure.getCosts();
|
List<Config.Resource> costs = structure.getCosts();
|
||||||
|
@ -92,8 +103,13 @@ public class Player {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method checks the amount of resources a player has in order to determine if he haas enough
|
||||||
|
* resources to build a new structure.
|
||||||
|
*
|
||||||
|
* @param list the list that shows how many resources are required.
|
||||||
|
* @return true if the player has enough resources to build and return false if he doesn't.
|
||||||
|
*/
|
||||||
//returns true if player has enough resources else false
|
//returns true if player has enough resources else false
|
||||||
private boolean checkResourceToBuild(List<Config.Resource> list) {
|
private boolean checkResourceToBuild(List<Config.Resource> list) {
|
||||||
HashMap<Config.Resource, Integer> costs = new HashMap<>();
|
HashMap<Config.Resource, Integer> costs = new HashMap<>();
|
||||||
|
@ -111,6 +127,4 @@ public class Player {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,7 +161,6 @@ public class SiedlerGame {
|
||||||
* @return true, if the placement was successful
|
* @return true, if the placement was successful
|
||||||
*/
|
*/
|
||||||
public boolean placeInitialSettlement(Point position, boolean payout) {
|
public boolean placeInitialSettlement(Point position, boolean payout) {
|
||||||
// TODO: Implement
|
|
||||||
if(!validPositionForSettlement(position)){
|
if(!validPositionForSettlement(position)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -186,7 +185,6 @@ public class SiedlerGame {
|
||||||
* @return true, if the placement was successful
|
* @return true, if the placement was successful
|
||||||
*/
|
*/
|
||||||
public boolean placeInitialRoad(Point roadStart, Point roadEnd) {
|
public boolean placeInitialRoad(Point roadStart, Point roadEnd) {
|
||||||
// TODO: Implement
|
|
||||||
if (!validPositionForRoad(roadStart, roadEnd)){
|
if (!validPositionForRoad(roadStart, roadEnd)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -228,7 +226,6 @@ public class SiedlerGame {
|
||||||
for (Point field : diceValueFields) {
|
for (Point field : diceValueFields) {
|
||||||
List<Resource> resources = board.getResourcesforFaction(field,player.getFaction());
|
List<Resource> resources = board.getResourcesforFaction(field,player.getFaction());
|
||||||
for (Config.Resource resource : resources){
|
for (Config.Resource resource : resources){
|
||||||
//TODO: Check if Resource Null notwendig?
|
|
||||||
returnMap.get(player.getFaction()).add(resource);
|
returnMap.get(player.getFaction()).add(resource);
|
||||||
addResourcesToPlayer(player, resource, 1);
|
addResourcesToPlayer(player, resource, 1);
|
||||||
}
|
}
|
||||||
|
@ -309,7 +306,6 @@ public class SiedlerGame {
|
||||||
* @return true, if the placement was successful
|
* @return true, if the placement was successful
|
||||||
*/
|
*/
|
||||||
public boolean buildCity(Point position) {
|
public boolean buildCity(Point position) {
|
||||||
// TODO: OPTIONAL task - Implement
|
|
||||||
//1. Check if Corner.
|
//1. Check if Corner.
|
||||||
if (!board.hasCorner(position)){
|
if (!board.hasCorner(position)){
|
||||||
return false;
|
return false;
|
||||||
|
@ -356,7 +352,6 @@ public class SiedlerGame {
|
||||||
}
|
}
|
||||||
//2. Can Player build road
|
//2. Can Player build road
|
||||||
if (!allPlayers.get(activePlayer).build(Config.Structure.ROAD)) {
|
if (!allPlayers.get(activePlayer).build(Config.Structure.ROAD)) {
|
||||||
// TODO: Error message
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue