Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.joejoe.rpg;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileReader;
- import java.io.FileWriter;
- public class Save {
- int[] saveInfo = { Game.hp, Game.level, Game.mana, Game.expTotal,
- Game.goldTotal, Game.arrow, Game.shuriken, Game.bomb,
- Game.hpPotion, Game.mpPotion, Game.potion, Game.items };
- public Save() {
- readPlayer("saveFile.txt");
- savePlayer("saveFile.txt");
- }
- private void readPlayer(String filePath) {
- File inputFile;
- BufferedReader inputReader;
- try {
- inputFile = new File(filePath);
- inputReader = new BufferedReader(new FileReader(inputFile));
- Game.hp = saveInfo[0];
- Game.level = saveInfo[1];
- Game.mana = saveInfo[2];
- Game.expTotal = saveInfo[3];
- Game.goldTotal = saveInfo[4];
- Game.arrow = saveInfo[5];
- Game.shuriken = saveInfo[6];
- Game.bomb = saveInfo[7];
- Game.hpPotion = saveInfo[8];
- Game.mpPotion = saveInfo[9];
- Game.potion = saveInfo[10];
- Game.items = saveInfo[11];
- for (int i = 0; i < saveInfo.length; i++) {
- saveInfo[i] = Integer.parseInt(inputReader.readLine());
- }
- inputReader.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private void savePlayer(String filePath) {
- File outputFile;
- BufferedWriter outputWriter;
- try {
- outputFile = new File(filePath);
- outputWriter = new BufferedWriter(new FileWriter(outputFile));
- saveInfo[0] = Game.hp;
- saveInfo[1] = Game.level;
- saveInfo[2] = Game.mana;
- saveInfo[3] = Game.expTotal;
- saveInfo[4] = Game.goldTotal;
- saveInfo[5] = Game.arrow;
- saveInfo[6] = Game.shuriken;
- saveInfo[7] = Game.bomb;
- saveInfo[8] = Game.hpPotion;
- saveInfo[9] = Game.mpPotion;
- saveInfo[10] = Game.potion;
- saveInfo[11] = Game.items;
- for(int i = 0; i < saveInfo.length; i++){
- outputWriter.write(Integer.toString(saveInfo[i]) + "\n");
- }
- outputWriter.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement