Examples of Ship


Examples of net.coljac.pirates.Ship

    String response = FileTools.getFileContentsAsString(cacheFile);
    if (response == null) {
      response = WebTools.getURLAsString(url);
      file(cacheFile, response);
    }
    Ship ship = new Ship();
    ship.setName(getTableValue("Name", response));
    ship.setPoints(Integer.parseInt(getTableValue("Point Value", response)));
    String colNumber = getTableValue("Collector's Number", response);
    String number = colNumber;
    if (number.indexOf("-") > 0) {
      int base = -1;
      if (number.startsWith("PS")) {
        base = 0;
      }
      if (number.startsWith("ES")) {
        base = 40;
      }
      if (number.startsWith("SS")) {
        base = 68;
      }
      String remainder = number.substring(number.indexOf("-") + 1);
      if (base >= 0) {
        number = "" + (Integer.parseInt(remainder) + base);
      }
    }

    ship.setNumber(number);
    ship.setExtra(colNumber);
    ship.setRarity(getTableValue("Rarity", response));
    String cargoSpace = getTableValue("Cargo Space", response);
    if (cargoSpace == null) {
      cargoSpace = getTableValue("Capacity", response);
    }
    ship.setCargo(Integer.parseInt(cargoSpace));
    String guns = "";
    for (int i = 1; i < 7; i++) {
      String gun = getTableValue("Mast " + i + " Cannon", response);
      if (gun != null) {
        guns += "," + gun;
      } else {
        break;
      }
    }
    if (guns.startsWith(",")) {
      guns = guns.substring(1);
    }

    ship.setCannons(cleanGuns(guns));
    String movement = getTableValue("Movement", response);
    if (movement == null) {
      movement = getTableValue("Move", response);
    }
    ship.setMove(cleanMove(movement));
    String masts = getTableValue("Number of Masts", response);
    if (masts == null) {
      masts = getTableValue("Mast", response);
    }
    ship.setMasts(Integer.parseInt(masts));

    // <td><strong>Broadsides Attack</strong>
    //      <p>Not every ship can live up to the name "La Magnifique," but with Capitaine de
    // St. Croix in command, this ship is just that?nigh invincible when delivering a full cannon barrage.</p></td>

    String marker = "<td><strong>";

    if (response.indexOf(marker) > -1) {
      int start = response.indexOf(marker);
      int end = response.indexOf("</td>", start);

      String cell = response.substring(start + 12, end - 4);
      cell = cell.trim();
      cell = cell.replaceAll("<P>", "<p>");
      cell = cell.replaceAll("</strong>", "");
      cell = cell.replaceAll("^ *<p>", "");
      cell = cell.trim();
      cell = cell.replaceAll("^<p>", "");
      String[] parts = cell.trim().split("<p>");
      if (parts.length == 1) {
        ship.setRules("No ability.");
        ship.setFlavor(parts[0].trim());
      } else {
        ship.setRules(fixRules(parts[0].trim()));
        ship.setFlavor(parts[1].trim());
      }
    }

    if (response.indexOf("src=\"images/Release") > -1) {
      int start = response.indexOf("src=\"images/Release");
      int end = response.indexOf("width", start);
      String set = response.substring(start, end);
      set = set.replaceAll(".*alt=\"(.*)\"", "$1");
      ship.setExpansion(set.trim());
    }

    if (response.indexOf("src=\"images/faction") > -1) {
      int start = response.indexOf("src=\"images/faction");
      int end = response.indexOf("width", start);
      String faction = response.substring(start, end);
      faction = faction.replaceAll(".*alt=\"(.*)\"", "$1");
      ship.setFaction(faction.trim());
    }
    return ship;
  }
View Full Code Here

Examples of net.coljac.pirates.Ship

    addToShip.setEnabled(fleetsPanel.getCurrentFleet() != null);
    if (fleetsPanel.getCurrentFleet() != null) {
      List<Ship> ships = fleetsPanel.getCurrentFleet().getShips();

      for (Ship ship : ships) {
        final Ship craft = ship;
        final Crew man = cards.get(model.getLastClickedRow());
        JMenuItem item = new JMenuItem(ship.getName());
        item.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            fleetsPanel.getCurrentFleet().addCrewToShip(craft, man);
View Full Code Here

Examples of net.coljac.pirates.Ship

public class DataTest extends TestCase {

  public void testData() throws Exception {

    HibernateUtil.currentSession();
    Ship ship = new Ship("SHIP");
    ship.setCannons("3S,3L");
    ship.setCargo(2);
    ship.setMasts(3);
    ship.setPoints(4);
    HibernateUtil.save(ship);
    HibernateUtil.commit();

    List l = HibernateUtil.createQuery("from Ship as ship").list();
    assertEquals(1, l.size());

    Crew crew = new Crew();
    crew.setName("crew");
    crew.setExtra("aa");
    crew.setOwned(1);
    HibernateUtil.save(crew);
    HibernateUtil.commit();

    l = HibernateUtil.createQuery("from Crew as crew").list();
    assertEquals(1, l.size());


    l = HibernateUtil.createQuery("from Card as card").list();
    assertEquals(2, l.size());

    Fleet fleet = new Fleet();
    fleet.setName("BOB");
    fleet.addShip(ship);
    fleet.addCrew(crew);
    fleet.addCrewToShip(ship,crew);
    HibernateUtil.save(fleet);
    HibernateUtil.commit();

    Ship ship2 = new Ship();
    ship2.setName("SHIP 2");
    ship2.setPoints(2);
    HibernateUtil.save(ship2);
    fleet.addShip(ship2);
    HibernateUtil.currentSession().update(fleet);
    HibernateUtil.commit();
View Full Code Here

Examples of net.coljac.pirates.Ship

    Collections.sort(ships, this);
  }


  public int compare(Object o1, Object o2) {
    Ship ship1 = (Ship) o1;
    Ship ship2 = (Ship) o2;

    int criterion = 0;
    for (criterion = 0; criterion < sortOrder.length; criterion ++) {
      int result = compareShips(ship1, ship2, sortOrder[criterion]);
      if (result != 0) {
View Full Code Here

Examples of net.coljac.pirates.Ship

  public int compareShips(Ship ship1, Ship ship2, int criterion) {
    int c = criterion;
    if (c < 0) {
      c = Math.abs(c);
      Ship temp = ship1;
      ship1 = ship2;
      ship2 = temp;
    }

    int result = 0;
View Full Code Here

Examples of oop13.space.model.Ship

 
  @Test
  public void testRemoveIndividuals() {
    IModel model = new Model();
    model.initIndividuals();
    Ship spaceShip = model.getShip();
    ShipShot shot = model.addShot();
    model.removeIndividual(shot);
    model.removeIndividual(spaceShip);
    Assert.assertTrue(model.getList().size() == 64);
    for (Individual ind : model.getList()) {
View Full Code Here

Examples of oop13.space.model.Ship

  @Test
  public void testChangesInModel() {
    IModel model = new Model();
    model.initIndividuals();
    model.initAchievements();
    Ship spaceShip = model.getShip();
    Statistics statistics = model.getStatistics();
   
    //Testing adding and resetting statistics
    statistics.setLevelsCompleted(3);
    statistics.setMotherShipsKilled(5);
    statistics.setScore(300);
    statistics.setAliensKilled(100);
    Assert.assertTrue(statistics.getLevelsCompleted() == 3);
    Assert.assertTrue(statistics.getMotherShipsKilled() == 5);
    Assert.assertTrue(statistics.getScore() == 300);
    Assert.assertTrue(statistics.getAliensKilled() == 100);
    statistics.resetStatistics();
    for (Field f : statistics.getClass().getDeclaredFields()) {
      f.setAccessible(true);
      try {
        Assert.assertTrue(f.getInt(statistics) == 0);
      } catch (IllegalArgumentException e) {
        System.err.println(GameStrings.ILLEGAL_ARG_ERROR);
      } catch (IllegalAccessException e) {
        System.err.println(GameStrings.ILLEGAL_ACC_ERROR);
      }
    }
   
    //Testing movement and some methods of ship
    spaceShip.moveIndividual(spaceShip.getPositionX() + 10, spaceShip.getPositionY());
    Assert.assertTrue(spaceShip.getPositionX() == 280);
    spaceShip.moveIndividual(spaceShip.getPositionX() - 260, spaceShip.getPositionY());
    Assert.assertTrue(model.getShip().getPositionX() == 20);
    spaceShip.moveIndividual(spaceShip.getPositionX() - 10, spaceShip.getPositionY());
    Assert.assertTrue(spaceShip.getPositionX() == 20); //reached minimum left movement, the ship position doesn't change
    spaceShip.moveIndividual(spaceShip.getPositionX() + 520, spaceShip.getPositionY());
    Assert.assertTrue(spaceShip.getPositionX() == 540);
    spaceShip.moveIndividual(spaceShip.getPositionX() + 10, spaceShip.getPositionY());
    Assert.assertTrue(spaceShip.getPositionX() == 540); // reached maximum right movement, the ship position doesn't change
    spaceShip.decreaseLives();
    spaceShip.decreaseLives();
    Assert.assertTrue(spaceShip.getLives() == 1);
    spaceShip.increaseLives();
    Assert.assertTrue(spaceShip.getLives() == 2);
    spaceShip.decreaseLives();
   
    //Testing collisions AlienShot -> Ship and Shot -> Alien
    model.getList().add(new AlienShot(spaceShip.getPositionX(), spaceShip.getPositionY()));
    ShipShot shot = new ShipShot(10, 50);
    model.getList().add(shot);
    shot.collideWith(model.getList());
    spaceShip.collideWith(model.getList());
    Assert.assertTrue(spaceShip.isDead());
    Assert.assertTrue(shot.isDead());
    int individualsKilled = 0;
    for (Individual ind : model.getList()) {
      if (ind.isDead()) {
        individualsKilled++;
View Full Code Here

Examples of oop13.space.model.Ship

    int counterTimer = 0;
    int lives = model.getShip().getLives();
      double motherSpawnMoment = Math.random() * MOTHERSHIP_SPAWN_FREQ;
    AlienBlock alienBlock = model.getAliens();
    Ship spaceShip = model.getShip();
    List<Individual> individuals = model.getList();

    alienBlock.startMove();
    AudioPlayer.getAudioPlayer().playLoop(AudioPlayer.BACKGROUND_SOUND);

    while (!this.isOver) {
      counterTimer++;
      if (counterTimer % SHOT_RATIO == 0) {
        alienShot();
      }

      //Adds a mother ship to the game
      if (counterTimer >= motherSpawnMoment) {
          AlienMotherShip motherShip = model.addMotherShip();
        motherShip.startMove();
        motherSpawnMoment = MOTHERSHIP_BASE_FREQ + Math.random() * MOTHERSHIP_SPAWN_FREQ;
        counterTimer = 0;
      }

      /* Moves all the individuals
       * (except the aliens 'cause they already move).
       * Checks all the possible collisions of all individuals
       * Checks if some aliens are dead
       * Sets lives and score in the game panel */
      for (Individual ind : individuals) {
        if (!(ind instanceof Alien)) {
                    ind.moveIndividual(ind.getPositionX(), ind.getPositionY());
        }
        ind.collideWith(individuals);
        if (spaceShip.getLives() != lives) {
          this.obs.setShipLivesInPanel();
          lives--;
        }
        if (ind.isDead()) {
          this.model.removeIndividual(ind);
                    if (ind instanceof Alien && !(ind instanceof AlienMotherShip)) {
                      AudioPlayer.getAudioPlayer().playOnce(AudioPlayer.ALIEN_KILLED_SOUND);
            this.aliensKilled++;
          }
          if (ind instanceof AlienMotherShip) {
                        if (!((AlienMotherShip) ind).isOutOfLimit()) {
                this.motherShipsKilled++;
            }
          }
                    this.obs.setScoreInPanel(this.model.getStatistics().getScore());
        }
      }

      //Speed up the last alien survivor
      if (this.aliensKilled >= KILLED_ALIENS_BEFORE_SPEEDUP) {
        alienBlock.setSleepTime(ALIENS_SLEEP_TIME);
      }

      //Check game won
      if (alienBlock.checkGameWon()) {
        this.levelsCompleted++;
        this.obs.gameWon();
        this.isOver = true;
      }

      //Check game over
      if (alienBlock.checkGameOver() || spaceShip.isDead()) {
        //Stops the alien block's thread
        if (!alienBlock.checkGameOver()) {
          alienBlock.setGameOver();
        }
        spaceShip.setLives(0);
        this.obs.gameOver();
        this.isOver = true;
      }
      this.obs.updatePanel();
      try {
View Full Code Here

Examples of oop13.space.model.Ship

  /*Initialize all the individuals that will collide with the ship shot and add them
    in a list*/
  public void initIndividuals() {
    this.listIndividuals = new CopyOnWriteArrayList<Individual>();
    int startPositionX = INITIAL_POSITION_X;
    this.spaceShip = new Ship();
    this.alien1 = new Alien(new AlienType(1), startPositionX, POSITION_Y);
    startPositionX += DELTA_X;
    this.alien2 = new Alien(new AlienType(2), startPositionX, POSITION_Y);
    startPositionX += DELTA_X;
    this.alien3 = new Alien(new AlienType(3), startPositionX, POSITION_Y);
View Full Code Here

Examples of org.e2k.Ship

    UserIdentifier uid=new UserIdentifier();
    // Test with
    // <name val='THORNBURY-C6RS7'/>
    // <mmsi val='311168000'/>
    // <flag val='Bahamas'/>
    Ship ship=uid.getShipDetails("311168000");
    // Check the returns
    if (ship==null) fail("No ship found !");
    else if (ship.getName().indexOf("THORNBURY-C6RS7")!=0) fail("Wrong ships name returned !");
    else if (ship.getFlag().indexOf("Bahamas")!=0) fail("Wrong ships name returned !");
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.