예제 #1
0
파일: Game.java 프로젝트: paleber/Catan
  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));
  }
예제 #2
0
파일: Game.java 프로젝트: paleber/Catan
        @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));
            }
          }
        }
예제 #3
0
파일: Game.java 프로젝트: paleber/Catan
  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()));
      }
    }
  }
예제 #4
0
파일: Game.java 프로젝트: paleber/Catan
 @Override
 void finishTurn() {
   curPlayerIndex++;
   if (curPlayerIndex >= players.length) {
     curPlayerIndex = 0;
   }
   control.sendGameEvent(new NextPlayerEvent(curPlayerIndex));
 }
예제 #5
0
파일: Game.java 프로젝트: paleber/Catan
        @Override
        public void buildSettlement(int intersectionId) {
          Intersection s = findIntersectionForBuilding(intersectionId);
          players[curPlayerIndex].buildSetupSettlement(s);
          finishSettlementBuilding(s);

          gamePhase = preparationStreetPhase;
          control.sendGameEvent(new BuildSettlementEvent(curPlayerIndex, intersectionId));
        }
예제 #6
0
파일: Game.java 프로젝트: paleber/Catan
        @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;
        }
예제 #7
0
파일: Game.java 프로젝트: paleber/Catan
 void gameOver(int playerId) {
   gamePhase = gameOverPhase;
   control.sendGameEvent(new GameOverEvent(playerId));
 }