示例#1
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);
  }
示例#2
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);
 }
示例#3
0
  @Override
  public int createGame(Profile userProfile, String gameName, Profile opponentProfile) {
    Game game = new Game();

    Player player1 = new Player();
    Player player2 = new Player();

    userProfile.addPlayer(player1);
    opponentProfile.addPlayer(player2);

    player1.setCommandPoints(START_COMMAND_POINTS);
    player2.setCommandPoints(START_COMMAND_POINTS);

    player1.setRequestAccepted(true);
    player2.setRequestAccepted(false);

    player1.setGame(game);
    player2.setGame(game);

    Planet planetA = planetRepository.getPlanetByName("a");
    Planet planetA3 = planetRepository.getPlanetByName("a3");

    Ship player1StartingShip = new Ship(planetA);
    Ship player2StartingShip = new Ship(planetA3);

    player1StartingShip.setStrength(NEW_SHIP_STRENGTH);
    player2StartingShip.setStrength(NEW_SHIP_STRENGTH);

    player1StartingShip.setPlayer(player1);
    player2StartingShip.setPlayer(player2);

    Colony player1StartingColony = new Colony(planetA);
    Colony player2StartingColony = new Colony(planetA3);

    player1StartingColony.setStrength(NEW_COLONY_STRENGHT);
    player2StartingColony.setStrength(NEW_COLONY_STRENGHT);

    player1StartingColony.setPlayer(player1);
    player2StartingColony.setPlayer(player2);

    game.setName(gameName);

    gameRepository.createOrUpdateGame(game);

    return game.getGameId();
  }
示例#4
0
 @Override
 public Planet getShipLocationByShipId(int shipId) {
   Ship shipDb = shipRepository.getShipByShipId(shipId);
   return shipDb.getPlanet();
 }