Ejemplo n.º 1
0
 public void load(String fileName) throws IOException {
   File file = new File(fileName);
   BufferedReader reader = new BufferedReader(new FileReader(file));
   String[] line;
   String temp;
   while ((temp = reader.readLine()) != null && (line = temp.split(",")) != null) {
     for (int i = 0; i < line.length; i++) line[i] = line[i].trim();
     if (line.length == 4) {
       line[2] = line[2].toUpperCase();
       cache.add(
           Item.createItem(
               line[0],
               Integer.parseInt(line[1]),
               ItemType.valueOf(line[2]),
               Integer.parseInt(line[3])));
     } else if (line.length == 5) {
       line[2] = line[2].toUpperCase();
       line[3] = line[3].toUpperCase();
       cache.add(
           Item.createItem(
               line[0],
               Integer.parseInt(line[1]),
               ItemType.valueOf(line[2]),
               ItemStatEffect.valueOf(line[3]),
               Integer.parseInt(line[4])));
     } else if (line.length == 3) {
       line[2] = line[2].toUpperCase();
       cache.add(Item.createItem(line[0], Integer.parseInt(line[1]), ItemType.valueOf(line[2])));
     }
   }
 }
Ejemplo n.º 2
0
 public void read(String path) throws FileNotFoundException, IOException, ClassNotFoundException {
   System.out.print("Enter the data file to deserialize: ");
   Scanner s = new Scanner(System.in);
   String name = s.nextLine();
   path += name;
   ObjectInputStream is = new ObjectInputStream(new FileInputStream(path));
   Object o = is.readObject();
   Item i = (Item) o;
   System.out.println("Data read successfully: ");
   System.out.println("\n" + i.toString());
 }
Ejemplo n.º 3
0
 public void write(String path) throws FileNotFoundException, IOException {
   ObjectOutputStream os;
   for (Item i : cache) {
     os =
         new ObjectOutputStream(
             new FileOutputStream(
                 ((path.charAt(path.length() - 1) == '/') ? path : path + "/")
                     + i.getName()
                     + ".i"));
     os.writeObject(i);
   }
 }
Ejemplo n.º 4
0
  /**
   * Draws the bar at LEFT_PADDING, TOP_PADDING, BAR_WIDTH, ITEM_SIZE (x,y,width,height) with the
   * specified items.
   */
  @Override
  public void draw(GameState gameState, float delta) {

    p.pushMatrix();
    p.pushStyle();

    p.noStroke();

    // Translate drawing to match location
    p.translate(LEFT_PADDING, TOP_PADDING);

    // Draw the background
    p.fill(0, 0, 0, 100);
    p.rect(0, 0, BAR_WIDTH, ITEM_SIZE);

    // p.imageMode(PApplet.CENTER);

    p.noFill();

    // Only draw the items if there are some
    if (items != null) {
      for (int i = 0; i < items.size(); i++) {
        Item item = items.get(i);

        // So if we apply a tint, it only affects the current item
        p.pushMatrix();
        p.pushStyle();

        if (item instanceof Key) {
          p.tint(Canvas.getSecurityColour(((Key) item).getAccessLevel(), false));
        }

        p.image(
            ENTITY_IMAGES.get(item.getImageName()),
            i * (ITEM_SIZE + ITEM_SPACING),
            0,
            ITEM_SIZE,
            ITEM_SIZE);

        p.popStyle();
        p.popMatrix();
      }
    }

    // pop matrix and style information from the stack
    p.popStyle();
    p.popMatrix();
  }