示例#1
0
  @Override
  public void endTurn(Integer playerID) {
    Player player = playerRepository.getPlayerByPlayerId(playerID);
    Game game = player.getGame();
    if (!player.isTurnEnded()) {
      int commandPoints = player.getCommandPoints();
      player.setCommandPoints(commandPoints + COMMANDPOINTS_PER_TURN);
      player.setTurnEnded(true);

      boolean allTurnsEnded = true;
      List<Player> players = game.getPlayers();
      for (Player p : players) {
        if (!p.isTurnEnded()) {
          allTurnsEnded = false;
        }
      }
      if (allTurnsEnded) {
        for (Player p : players) {
          p.setTurnEnded(false);
        }
      }
    } else {
      throw new SpaceCrackNotAcceptableException("Turn is already ended");
    }
    gameSynchronizer.updateGame(game);
  }
示例#2
0
  @Override
  public void buildShip(Integer colonyId) {
    Ship shipOnPlanet = null;

    Colony colony = colonyRepository.getColonyById(colonyId);
    Player player = colony.getPlayer();

    Game game = player.getGame();
    if (player.getCommandPoints() < BUILDSHIP_COST || player.isTurnEnded()) {
      throw new SpaceCrackNotAcceptableException(
          "Dear Sir or Lady, you have either run out of command points or your turn has ended, please wait for the other players to end their turn.");
    }
    for (Ship ship : player.getShips()) {
      if (ship.getPlanet().getName().equals(colony.getPlanet().getName())) {
        shipOnPlanet = ship;
      }
    }

    Ship ship;
    if (shipOnPlanet == null) {
      ship = new Ship();
      ship.setStrength(NEW_SHIP_STRENGTH);
      ship.setPlayer(player);
      ship.setPlanet(colony.getPlanet());
    } else {
      shipOnPlanet.setStrength(shipOnPlanet.getStrength() + NEW_SHIP_STRENGTH);
    }

    player.setCommandPoints(player.getCommandPoints() - BUILDSHIP_COST);
    gameSynchronizer.updateGame(game);
  }
示例#3
0
 @Override
 public void acceptGameInvite(int gameId) {
   Game game = getGameByGameId(gameId);
   for (Player p : game.getPlayers()) {
     p.setRequestAccepted(true);
   }
   gameSynchronizer.updateGame(game);
 }
示例#4
0
 @Override
 public void moveShip(Integer shipId, String planetName) {
   Ship ship = shipRepository.getShipByShipId(shipId);
   Game game = ship.getPlayer().getGame();
   Planet destinationPlanet = planetRepository.getPlanetByName(planetName);
   validateActionMakeSureGameIsNotFinishedYet(game);
   moveShipHandler.validateMove(ship, destinationPlanet);
   moveShipHandler.moveShip(ship, destinationPlanet);
   checkLost(game);
   gameSynchronizer.updateGame(game);
 }