removed to do's and updated java docs.
This commit is contained in:
		
							parent
							
								
									99da9715c5
								
							
						
					
					
						commit
						cff925de61
					
				| 
						 | 
				
			
			@ -4,18 +4,21 @@ import java.util.*;
 | 
			
		|||
 | 
			
		||||
/**
 | 
			
		||||
 * 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 {
 | 
			
		||||
 | 
			
		||||
    private Config.Faction faction;
 | 
			
		||||
    private HashMap<Config.Resource,Integer> resources;
 | 
			
		||||
    private HashMap<Config.Structure,Integer> structureToUse;
 | 
			
		||||
    private int roadsToUse;
 | 
			
		||||
    private int settlementsToUse;
 | 
			
		||||
    private int citiesToUse;
 | 
			
		||||
    private HashMap<Config.Resource, Integer> resources;
 | 
			
		||||
    private HashMap<Config.Structure, Integer> structureToUse;
 | 
			
		||||
 | 
			
		||||
    public Player (Config.Faction faction){
 | 
			
		||||
    /**
 | 
			
		||||
     * 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) {
 | 
			
		||||
        //Datenfelder
 | 
			
		||||
        this.faction = faction;
 | 
			
		||||
        //Verfügbare Structures initialisieren
 | 
			
		||||
| 
						 | 
				
			
			@ -25,36 +28,43 @@ public class Player {
 | 
			
		|||
        structureToUse.put(Config.Structure.CITY, Config.Structure.CITY.getStockPerPlayer());
 | 
			
		||||
        //Ressourcen initialisiern
 | 
			
		||||
        resources = new HashMap<>();
 | 
			
		||||
        for(Config.Resource resource : Config.Resource.values()) {
 | 
			
		||||
            resources.put(resource,0);
 | 
			
		||||
        for (Config.Resource resource : Config.Resource.values()) {
 | 
			
		||||
            resources.put(resource, 0);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method returns all the resources the player has at the moment
 | 
			
		||||
     *
 | 
			
		||||
     * @return HashMap with the count of every resource
 | 
			
		||||
     */
 | 
			
		||||
    public HashMap<Config.Resource,Integer> getResources() {
 | 
			
		||||
    public HashMap<Config.Resource, Integer> getResources() {
 | 
			
		||||
        return resources;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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.
 | 
			
		||||
     * @param resource
 | 
			
		||||
     * @return
 | 
			
		||||
     * This method returns the amount of a specific resource that a player owns.
 | 
			
		||||
     *
 | 
			
		||||
     * @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
 | 
			
		||||
     * @param resource to add
 | 
			
		||||
     *
 | 
			
		||||
     * @param resource    to add
 | 
			
		||||
     * @param numberToAdd how much to add
 | 
			
		||||
     */
 | 
			
		||||
    public void addResource(Config.Resource resource, int numberToAdd) {
 | 
			
		||||
| 
						 | 
				
			
			@ -63,42 +73,48 @@ public class Player {
 | 
			
		|||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
     * @return true if resource has been substracted false if player has not enough resources
 | 
			
		||||
     */
 | 
			
		||||
    public boolean substractResource(Config.Resource resource, int numberToSubstract) {
 | 
			
		||||
        int inPossesion = resources.get(resource);
 | 
			
		||||
        if(inPossesion - numberToSubstract < 0) {
 | 
			
		||||
        if (inPossesion - numberToSubstract < 0) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        resources.put(resource,inPossesion - numberToSubstract);
 | 
			
		||||
        resources.put(resource, inPossesion - numberToSubstract);
 | 
			
		||||
        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
 | 
			
		||||
     * 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();
 | 
			
		||||
        if(structureToUse.get(structure) < 1 || !checkResourceToBuild(costs)){
 | 
			
		||||
        if (structureToUse.get(structure) < 1 || !checkResourceToBuild(costs)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        structureToUse.put(structure, structureToUse.get(structure) - 1);
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
   //returns true if player has enough resources else false
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
    private boolean checkResourceToBuild(List<Config.Resource> list) {
 | 
			
		||||
        HashMap<Config.Resource, Integer> costs = new HashMap<>();
 | 
			
		||||
        for(Config.Resource resource : list){
 | 
			
		||||
            if(costs.containsKey(resource)){
 | 
			
		||||
        for (Config.Resource resource : list) {
 | 
			
		||||
            if (costs.containsKey(resource)) {
 | 
			
		||||
                costs.put(resource, costs.get(resource) + 1);
 | 
			
		||||
            } else {
 | 
			
		||||
                costs.put(resource, 1);
 | 
			
		||||
| 
						 | 
				
			
			@ -111,6 +127,4 @@ public class Player {
 | 
			
		|||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -161,7 +161,6 @@ public class SiedlerGame {
 | 
			
		|||
     * @return true, if the placement was successful
 | 
			
		||||
     */
 | 
			
		||||
    public boolean placeInitialSettlement(Point position, boolean payout) {
 | 
			
		||||
        // TODO: Implement
 | 
			
		||||
        if(!validPositionForSettlement(position)){
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -186,7 +185,6 @@ public class SiedlerGame {
 | 
			
		|||
     * @return true, if the placement was successful
 | 
			
		||||
     */
 | 
			
		||||
    public boolean placeInitialRoad(Point roadStart, Point roadEnd) {
 | 
			
		||||
        // TODO: Implement
 | 
			
		||||
        if (!validPositionForRoad(roadStart, roadEnd)){
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -228,7 +226,6 @@ public class SiedlerGame {
 | 
			
		|||
                for (Point field : diceValueFields) {
 | 
			
		||||
                    List<Resource> resources = board.getResourcesforFaction(field,player.getFaction());
 | 
			
		||||
                    for (Config.Resource resource : resources){
 | 
			
		||||
                        //TODO: Check if Resource Null notwendig?
 | 
			
		||||
                        returnMap.get(player.getFaction()).add(resource);
 | 
			
		||||
                        addResourcesToPlayer(player, resource, 1);
 | 
			
		||||
                    }
 | 
			
		||||
| 
						 | 
				
			
			@ -309,7 +306,6 @@ public class SiedlerGame {
 | 
			
		|||
     * @return true, if the placement was successful
 | 
			
		||||
     */
 | 
			
		||||
    public boolean buildCity(Point position) {
 | 
			
		||||
        // TODO: OPTIONAL task - Implement
 | 
			
		||||
        //1. Check if Corner.
 | 
			
		||||
        if (!board.hasCorner(position)){
 | 
			
		||||
            return false;
 | 
			
		||||
| 
						 | 
				
			
			@ -356,7 +352,6 @@ public class SiedlerGame {
 | 
			
		|||
        }
 | 
			
		||||
        //2. Can Player build road
 | 
			
		||||
        if (!allPlayers.get(activePlayer).build(Config.Structure.ROAD)) {
 | 
			
		||||
            // TODO: Error message
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue