Beispiel #1
0
  public void open(File file) {
    try {
      BufferedReader in = new BufferedReader(new FileReader(file));
      game = "";

      for (String s = in.readLine(); s != null; s = in.readLine()) {
        game += s + "\n";
      }
      game.trim();
      in.close();
    } catch (IOException e) {
      System.out.println("File I/O error!");
    }
  }
Beispiel #2
0
  public GameFile() {
    game = "";

    // load character names and descriptions
    characters = "";
    File characterFile = new File("/home/cory/Programming/treasure_hunt/data/characters.data");
    try {
      BufferedReader in = new BufferedReader(new FileReader(characterFile));
      for (String s = in.readLine(); s != null; s = in.readLine()) {
        characters += s + "\n";
      }
      characters.trim();
      in.close();
    } catch (IOException e) {
      System.out.println("File I/O error! Couldn't load character data file.");
      System.exit(1);
    }

    // load weapon names and descriptions
    weapons = "";
    File weaponFile = new File("/home/cory/Programming/treasure_hunt/data/weapons.data");
    try {
      BufferedReader in = new BufferedReader(new FileReader(weaponFile));
      for (String s = in.readLine(); s != null; s = in.readLine()) {
        weapons += s + "\n";
      }
      weapons.trim();
      in.close();
    } catch (IOException e) {
      System.out.println("File I/O error! Couldn't load weapon data file.");
      System.exit(1);
    }

    // load treasure names and desciptions
    treasures = "";
    File treasureFile = new File("/home/cory/Programming/treasure_hunt/data/treasures.data");
    try {
      BufferedReader in = new BufferedReader(new FileReader(treasureFile));
      for (String s = in.readLine(); s != null; s = in.readLine()) {
        treasures += s + "\n";
      }
      treasures.trim();
      in.close();
    } catch (IOException e) {
      System.out.println("File I/O error! Couldn't load treasure data file.");
      System.exit(1);
    }
  }