I'm trying to make a simple text game just for fun. Java is a language I want to learn so making a game is a great start. I'm having problem with my if statement however.
This is an example of whats happening. This is only a few hours into the project so I know it needs a lot of cleanup and could probably be enhanced a lot but as I go through the Java tutorials I'm updating and fixing things as I go, so please only focus on the problem I'm having which is:
When I attack I display the murloc health at the end to see that it is indeed going down, but with each new attack it resets to 10. So the ecurHlth is only changing in the if statement and going back to 10 after the statement ends, how can I make the if statement update the actual variable?
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Game
{
public static void main(String[] args) {
Scanner playIn = new Scanner(System.in);
int turn = 1+(int)(Math.random()*100);//will generate a random number from 1-100, if 50< Player goes first.
int miss = 1+(int)(Math.random()*100);
int eAtck = 1+(int)(Math.random()*6);
int plCuHlth = 25;
int ecurHlth = 10;
String charName;
System.out.println("Please name your brave warrior");
charName = playIn.nextLine();
WarriorClass Ontulmora = new WarriorClass();
Ontulmora.changeName(charName);
Ontulmora.introShow();
MurlocClass Murky = new MurlocClass();
int fballAtck = 6;
int meleeAtck = 3;
if(miss>=85){
fballAtck = 0;
}else
fballAtck = 6;
System.out.println("You are strolling down the road towards Orgrimmar when an angry Murloc blocks the path, it's clear he will not budge. Time for a fight !");
System.out.println("Press ENTER to continue");
String blankone = playIn.nextLine();
int chAtck0 = 0;
if(turn>=50)
{
System.out.println("You get the first attack against the Murloc, please choose an attack. Type 1 for melee attack or 2 for fireball. Fireball has a higher chance of missing");
String chAtck = playIn.nextLine();
chAtck0 = Integer.parseInt(chAtck);
if(chAtck0==1)
{
ecurHlth = Murky.strHlth-meleeAtck;
}
else{
if(fballAtck==0){
ecurHlth = Murky.strHlth-fballAtck;
System.out.println("Your fireball missed!");}
else
ecurHlth = Murky.strHlth-fballAtck;
System.out.println(ecurHlth);
if(ecurHlth==0){
System.out.println("You have defeated the angry murloc!");
}
}
}
else
{
System.out.println("The murloc got the jump on you and is attacking first !");
plCuHlth = eAtck-Ontulmora.statHlth;
System.out.print("The murloc slices you with his sharp claws !");
System.out.println("You aren't hurt badly, but a little angry now !");
if(Ontulmora.statHlth<=0){
System.out.println("You have died, Game Over, Try Again, you suck and smell bad!");
}
}
if(turn>=50)
{
System.out.println("Please choose your next attack. Type 1 for melee attack or 2 for fireball. Fireball has a higher chance of missing");
String chAtck = playIn.nextLine();
chAtck0 = Integer.parseInt(chAtck);
if(chAtck0==1)
{
ecurHlth = Murky.strHlth-meleeAtck;
}
else{
if(fballAtck==0){
ecurHlth = Murky.strHlth-fballAtck;
System.out.println("Your fireball missed!");}
else
ecurHlth = Murky.strHlth-fballAtck;
System.out.println(Murky.ecurHlth);
if(ecurHlth==0){
System.out.println("You have defeated the angry murloc!");
}
}
}
else
{
plCuHlth = eAtck-Ontulmora.statHlth;
System.out.print("The murloc slices you with his sharp claws !");
System.out.println("You aren't hurt badly, but a little angry now !");
if(Ontulmora.statHlth<=0){
System.out.println("You have died, Game Over, Try Again, you suck and smell bad!");
}