first draft of foundigPhase Method
This commit is contained in:
		
							parent
							
								
									c4a3346fad
								
							
						
					
					
						commit
						9916d38073
					
				| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
package ch.zhaw.catan;
 | 
			
		||||
 | 
			
		||||
public class City extends Structure {
 | 
			
		||||
public class City extends Settlement {
 | 
			
		||||
 | 
			
		||||
    public City(Config.Faction faction) {
 | 
			
		||||
        super(faction);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,22 +4,79 @@ import org.beryx.textio.TextIO;
 | 
			
		|||
import org.beryx.textio.TextIoFactory;
 | 
			
		||||
import org.beryx.textio.TextTerminal;
 | 
			
		||||
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
 | 
			
		||||
public class Siedler {
 | 
			
		||||
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
 | 
			
		||||
        //Spiel erstellen
 | 
			
		||||
        SiedlerGame game = new SiedlerGame(3, 2);
 | 
			
		||||
        Parser parser = new Parser();
 | 
			
		||||
        SiedlerGame game = foundingPhase(parser);
 | 
			
		||||
 | 
			
		||||
        parser.getAction();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        //Spielfeld ausgeben
 | 
			
		||||
        TextIO textIO = TextIoFactory.getTextIO();
 | 
			
		||||
        TextTerminal<?> textTerminal = textIO.getTextTerminal();
 | 
			
		||||
        textTerminal.println(game.getBoard().getTextView());
 | 
			
		||||
        Parser parser = new Parser();
 | 
			
		||||
        parser.getAction();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    private static SiedlerGame foundingPhase(Parser parser) {
 | 
			
		||||
        HashMap<String, Integer> gameInfo = parser.gameStart();
 | 
			
		||||
        SiedlerGame game = new SiedlerGame(gameInfo.get("NumberOfWinPoints"), gameInfo.get("NumberOfPlayers"));
 | 
			
		||||
        for(int player = 1; player <= gameInfo.get("NumberOfPlayers"); player++){
 | 
			
		||||
            buildStructuresInFoundingPhase(game, parser, false);
 | 
			
		||||
            if(player < gameInfo.get("NumberOfPlayers")){
 | 
			
		||||
                game.switchToPreviousPlayer();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        for(int player = 1; player <= gameInfo.get("NumberOfPlayers"); player++){
 | 
			
		||||
            buildStructuresInFoundingPhase(game, parser, true);
 | 
			
		||||
            game.switchToNextPlayer();
 | 
			
		||||
        }
 | 
			
		||||
        return game;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    private static void buildStructuresInFoundingPhase(SiedlerGame game, Parser parser, Boolean payout){
 | 
			
		||||
 | 
			
		||||
        parser.displayGameboard(game.getBoard().getTextView());
 | 
			
		||||
        parser.playerTurn(game.getCurrentPlayerFaction());
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        //build Settlement
 | 
			
		||||
        parser.giveCoordinatesForStructures(Config.Structure.SETTLEMENT);
 | 
			
		||||
        boolean sucessful = false;
 | 
			
		||||
        do{
 | 
			
		||||
            if(game.placeInitialSettlement(parser.getPoint(), payout)) {
 | 
			
		||||
                sucessful = true;
 | 
			
		||||
            }
 | 
			
		||||
            else{
 | 
			
		||||
                parser.errorMessage();
 | 
			
		||||
            }
 | 
			
		||||
        }  while(!sucessful);
 | 
			
		||||
 | 
			
		||||
        //build Road
 | 
			
		||||
        parser.displayGameboard(game.getBoard().getTextView());
 | 
			
		||||
        parser.giveCoordinatesForStructures(Config.Structure.ROAD);
 | 
			
		||||
        sucessful = false;
 | 
			
		||||
        do{
 | 
			
		||||
            if(game.placeInitialRoad(parser.getPoint(), parser.getPoint())) {
 | 
			
		||||
                sucessful = true;
 | 
			
		||||
            }
 | 
			
		||||
            else{
 | 
			
		||||
                parser.errorMessage();
 | 
			
		||||
            }
 | 
			
		||||
        }  while(!sucessful);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -144,7 +144,7 @@ public class SiedlerGame {
 | 
			
		|||
     */
 | 
			
		||||
    public boolean placeInitialSettlement(Point position, boolean payout) {
 | 
			
		||||
        // TODO: Implement
 | 
			
		||||
        return false;
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
| 
						 | 
				
			
			@ -157,7 +157,7 @@ public class SiedlerGame {
 | 
			
		|||
     */
 | 
			
		||||
    public boolean placeInitialRoad(Point roadStart, Point roadEnd) {
 | 
			
		||||
        // TODO: Implement
 | 
			
		||||
        return false;
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
| 
						 | 
				
			
			@ -220,6 +220,11 @@ public class SiedlerGame {
 | 
			
		|||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean buildSettlementFoundation(Point position) {
 | 
			
		||||
        //todo implement
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Builds a city at the specified position on the board.
 | 
			
		||||
     *
 | 
			
		||||
| 
						 | 
				
			
			@ -276,6 +281,19 @@ public class SiedlerGame {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    private boolean validPositionForRoad(Point position){
 | 
			
		||||
        //todo implement
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean validPositionForSettlement(Point position){
 | 
			
		||||
        //todo implement
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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.
 | 
			
		||||
| 
						 | 
				
			
			@ -312,10 +330,10 @@ public class SiedlerGame {
 | 
			
		|||
        for(Structure structure : structures) {
 | 
			
		||||
 | 
			
		||||
            int newWinPoints = 0;
 | 
			
		||||
            if(structure instanceof Settlement){
 | 
			
		||||
                newWinPoints = 1;
 | 
			
		||||
            } else if(structure instanceof City) {
 | 
			
		||||
            if(structure instanceof City){
 | 
			
		||||
                newWinPoints = 2;
 | 
			
		||||
            } else if(structure instanceof Settlement) {
 | 
			
		||||
                newWinPoints = 1;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Faction faction = structure.getFaction();
 | 
			
		||||
| 
						 | 
				
			
			@ -327,6 +345,7 @@ public class SiedlerGame {
 | 
			
		|||
            }
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        //todo add points for longest road
 | 
			
		||||
        return winPoints;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue