Hello, I am practicing on what ive learned so far in Java. (Which isnt very much). This is just for simple practice. In Battle.java I’m trying to calculate and attack between user1 and and Ene1. But I do not know how to call their variables from within Battle.java. I tried to type in user1.attack or ene1.defence. But nothing comes up unless i’m under the RPG.java (Main class).
I know this is probably horribly put together. but I’m still learning the basics.
Thanks
~Ty
RPG:
import java.util.Scanner;
public class RPG {
public static void main(String[] args){
Scanner myScan = new Scanner(System.in);
Player user1 = new Player(100,100,50,50);
Enemy Ene1 = new Enemy(5, 100,100);
Battle testbat = new Battle();
while(true){
System.out.println("Please Select what you want to do:");
System.out.println("1. Move");
System.out.println("2. Rest");
int input = myScan.nextInt();
if (input == 1){
user1.moveX();
user1.moveY();
} else {
System.out.println("You rest and gain your strength");
user1.HP += 10;
}
if(testbat.checkBattle()) {
testbat.enterBattle();
}
} // end while
} // End main
} // end class RPG
Battle
import java.util.Random;
import java.util.Scanner;
public class Battle {
Random generator = new Random();
Scanner myScan = new Scanner(System.in);
public Battle (){
}
public boolean checkBattle(){
int ranNum = generator.nextInt(10);
System.out.println(ranNum);
if (ranNum <4) {
return false;
} else {
return true;
}
}// end check battle
public void enterBattle(){
int ranNum = generator.nextInt(10);
//check to see who attacks first
if (ranNum < 7 ){
System.out.println("You sneak upon the enemy");
Fight();
} else if (ranNum >8){
System.out.println("The enemy sneak attacks you");
Fight();
}
} // end enterBattle
public void Fight(){
boolean endFight = true;
while (endFight){
System.out.println("What do you want to do?");
System.out.println("1. Attack");
System.out.println("2. Deffend");
int input = myScan.nextInt();
if (input == 1) {
System.out.println("You Attack");
//**NEED TO FIGURE OUT WHAT TO PUT HERE TO ATTACK
}
}
} // end fight
}