Package net.coljac.pirates

Examples of net.coljac.pirates.Ship


      while(number.length()<3) {
        number = "0" + number;
      }
      List<Card> ships = db.getCardsByName(name);
      if (ships.size() == 1) {
        Ship theShip = (Ship)ships.get(0);
        theShip.setOwned(owned);
        theShip.setWanted(wanted);
      } else if (ships.size() == 0) {
        System.out.println("Can't find ship " + name);
      } else {
        List numbered = new ArrayList<Ship>();
        for(Card c: ships) {
          if(c.getNumber().equals(number)) {
            numbered.add((Ship)c);
          }
        }
        if(numbered.size()==1) {
          Ship theShip = (Ship)numbered.get(0);
          theShip.setOwned(owned);
          theShip.setWanted(wanted);
          db.save();
        } else {
          System.out.println("Too many ships: " + name + "  " + numbered.size());
        }
      }
View Full Code Here


      WebLink link = links[i];
      if (link.getText().indexOf("Ship") > 0) {
        int start = link.getURLString().indexOf("unitid=") + 7;
        int end = link.getURLString().indexOf("'", start);
        String id = link.getURLString().substring(start, end);
        Ship ship = getShip(id);
        MakeDB.db.getShips().add(ship);
        MakeDB.db.getCards().add(ship);

        if (pw != null) {
          pw.println(ship.toCSV());
        }
        ships++;
      }
    }
//    HibernateUtil.commit();
View Full Code Here

    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

    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

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

    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

  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

TOP

Related Classes of net.coljac.pirates.Ship

Copyright © 2018 www.massapicom. 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.