LoadGame.java
package com.hunt.game;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class LoadGame {
public void PlayerContents(){
BufferedReader br = null;
try {
String sCurrentLine;
br = new BufferedReader(new FileReader("C:/Users/AncientPandas/Desktop/HuntersConquest/player.txt"));
while((sCurrentLine = br.readLine()) != null){
System.out.println(sCurrentLine);
}
} catch(IOException e){ e.printStackTrace();}
finally {
try {
if (br != null)br.close();
} catch (IOException ex){
ex.printStackTrace();
}
}
}
}
Player.java
package com.hunt.game;
import java.util.Scanner;
public class Player {
public static int atk = 5, def = 3, dmg, exp = 0, currentLife = 10, maxLife = 10, level = 1,
exptoLevel = 25, statPoints = 0, amount;
Main main = new Main();
public void PlayerStats(){
@SuppressWarnings("resource")
Scanner scanner = new Scanner(System.in);
int choice = 0;
System.out.println("Level: " + level + "\nAtk: " + atk + "\nDef: " + def + "\nLife: " + currentLife +
" / " + maxLife + "\nExp: " + exp + " / " + exptoLevel + "\n\n");
do{
if(statPoints > 0){
System.out.println("Level: " + level + "\nAtk: " + atk + "\nDef: " + def + "\nLife: " + currentLife +
" / " + maxLife + "\nExp: " + exp + " / " + exptoLevel + "\n\n");
System.out.println("The Player has " + statPoints + " unused stat points. Would you like to spend them now?");
System.out.println("(1) Yes\n(2) No");
choice = scanner.nextInt();
if(choice == 1){
System.out.println("What would you like to spend your stat points on?");
System.out.println("(1) Attack\n(2) Defense\n(3) Life\n(4) Do not spend");
choice = scanner.nextInt();
if(choice == 1){
do{
System.out.println("How many stat points would you like to spend on Attack? ");
amount = scanner.nextInt();
if(amount > statPoints){
System.out.println("Sorry you can only use the amount of stat points you have.");
}
}while(amount > statPoints);
atk = atk + amount;
statPoints = statPoints - amount;
main.run();
}
else if(choice == 2){
while(amount > statPoints);{
System.out.println("How many stat points would you like to spend on Defense? ");
amount = scanner.nextInt();
if(amount > statPoints){
System.out.println("Sorry you can only use the amount of stat points you have.");
}
}while(amount > statPoints);
def = def + amount;
statPoints = statPoints - amount;
main.run();
}
else if(choice == 3){
do{
System.out.println("How many stat points would you like to spend of Life? ");
amount = scanner.nextInt();
if(amount > statPoints){
System.out.println("Sorry you can only use the amount of stat point you have.");
}
}while(amount > statPoints);
maxLife = maxLife + amount;
statPoints = statPoints - amount;
currentLife = maxLife;
main.run();
}
else if(choice == 4){System.out.println("You have chosen not to spend any of your stat points.");
main.run();
}
}
}
else if(choice == 2){
main.run();
}
}while(choice > 4 && choice < 1);
main.run();
}
}
Player.txt
Quote
Defence: 4
Damage: 3
Current Life: 13
Current experience: 37
Experience to level: 45
Level: 2
Max Life: 13
Stat Points: 0
I am trying to load these stats ^

New Topic/Question
Reply



MultiQuote





|