Advertisement
Guest User

inventory class

a guest
Apr 18th, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package escapegame;
  6.  
  7. /**
  8.  *
  9.  * @author 136-pghanem
  10.  */
  11. public class Inventory {
  12.  
  13.     int goldKey, rustedKey, gauze, drill, scalpel, alcohol, remote, clay, lighter, syringe, bunsenburner, lead;
  14.     int i, j;
  15.     String[][] inventory = new String[2][5];
  16.  
  17.     public void inv() {
  18.         for (int row = 0; row < inventory.length; row++) {
  19.             for (int col = 0; col < inventory[0].length; col++) {
  20.                 inventory[row][col] = "         ";
  21.             }
  22.         }
  23.     }
  24.  
  25.     public void displayBoard() {
  26.         System.out.println("                                              Inventory");
  27.         for (int row = 0; row < inventory.length; row++) {
  28.             for (int col = 0; col < inventory[0].length; col++) {
  29.                 System.out.print("[" + inventory[row][col] + "]");
  30.             }
  31.             System.out.println();
  32.         }
  33.     }
  34.  
  35.     public void add(String name) {
  36.         inventory[i][j] = name;
  37.         j++;
  38.         if (j == 4) {
  39.             j = 0;
  40.             i++;
  41.         }
  42.     }
  43.  
  44.     public void remove(String name) {
  45.         for (int x = 0; x < 5; x++) {
  46.             for (int y = 0; y < 2; y++) {
  47.                 if (inventory[y][x].equals(name)) {
  48.                     inventory[y][x] = ("         ");
  49.                 }
  50.             }
  51.         }
  52.  
  53.     }
  54.  
  55.     public boolean check(String name) {
  56.         for (int x = 0; x < 5; x++) {
  57.             for (int y = 0; y < 2; y++) {
  58.                 if (inventory[y][x].equals(name)) {
  59.                     return true;
  60.                 }
  61.  
  62.             }
  63.         }
  64.         return false;
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement