public Game(IGameControl control, String... playerNames) { players = new Player[playerNames.length]; for (int i = 0; i < players.length; i++) { players[i] = new Player(playerNames[i], i, Color.PINK, control, this); } this.control = control; IBoardBuilder builder = new EasyBoardBuilder(); Collections.addAll(intersections, builder.getIntersections()); Collections.addAll(paths, builder.getPaths()); terrains = builder.getTerrains(); for (Intersection i : intersections) { control.sendGameEvent(i.createSetupEvent()); } for (Path p : paths) { control.sendGameEvent(p.createSetupEvent()); } for (Terrain t : terrains) { control.sendGameEvent(t.createSetupEvent()); } control.sendGameEvent(new PreparationSettlementPhaseEvent(curPlayerIndex)); }
@Override public void buildStreet(int pathId) { Path path = findPathForBuilding(pathId); players[curPlayerIndex].buildSetupStreet(path); finishStreetBuilding(path); if (players[curPlayerIndex].getSettlements().length <= 1) { // Forward Preparation Round if (curPlayerIndex < players.length - 1) { curPlayerIndex++; } gamePhase = preparationSettlementPhase; control.sendGameEvent(new PreparationSettlementPhaseEvent(curPlayerIndex)); } else { // Backward Preparation Round if (curPlayerIndex > 0) { curPlayerIndex--; gamePhase = preparationSettlementPhase; control.sendGameEvent(new PreparationSettlementPhaseEvent(curPlayerIndex)); } else { for (Player p : players) { p.collectStartResources(); } gamePhase = resourcePhase; control.sendGameEvent(new ResourcePhaseEvent(curPlayerIndex)); } } }
private void finishSettlementBuilding(Intersection s) { control.sendGameEvent(new BuildSettlementEvent(curPlayerIndex, s.getId())); intersections.remove(s); for (Intersection i : s.getNeighborIntersections()) { if (intersections.contains(i)) { intersections.remove(i); control.sendGameEvent(new WaypointBlockedEvent(i.getId())); } } }
@Override void finishTurn() { curPlayerIndex++; if (curPlayerIndex >= players.length) { curPlayerIndex = 0; } control.sendGameEvent(new NextPlayerEvent(curPlayerIndex)); }
@Override public void buildSettlement(int intersectionId) { Intersection s = findIntersectionForBuilding(intersectionId); players[curPlayerIndex].buildSetupSettlement(s); finishSettlementBuilding(s); gamePhase = preparationStreetPhase; control.sendGameEvent(new BuildSettlementEvent(curPlayerIndex, intersectionId)); }
@Override void rollDice() { Random r = new Random(); int n1 = r.nextInt(6) + 1; int n2 = r.nextInt(6) + 1; control.sendGameEvent(new RollDiceEvent(n1, n2)); if (n1 + n2 != 7) { for (Player p : players) { p.collectMaterial(n1 + n2); } } else { // TODO Knight } gamePhase = actionPhase; }
void gameOver(int playerId) { gamePhase = gameOverPhase; control.sendGameEvent(new GameOverEvent(playerId)); }