jeudi 24 décembre 2015

Rng Kind broken?

Okay guys so bear with me, i need to add a health bar but before i add a health bar i need to get it working correctly.

The Problem: When i run it and it rolls it will land on a number and select a hit, when it determines the hit it runs through multiple types of hits instead of just the one. Try running it if you would. Hopefully the comments help.

What ive tried: I have tried fine combing through everything but after about 2 hours of tweaking and no avail of finding the solution i have turned to here....

Imports: import javax.swing.JOptionPane; import java.util.Random;

Declaring Values:

    int life = 100; //Your life
    int life2 = 100; //Enemy life
    Random chance = new Random();



 while (life >= 0 && life2 >= 0){ //loop
int hitchance = chance.nextInt(100)+1; 
System.out.println(hitchance); //Your roll
if (hitchance <= 20 ){//Miss
    JOptionPane.showMessageDialog(null, "You have missed your opponent like a fool.\nYour Opponent has "+life2+" health remaining.");

}
if (hitchance >= 21 && hitchance <= 34){//Wiff
    int Wiff = chance.nextInt(10)+1;
    life = life-Wiff;
    JOptionPane.showMessageDialog(null, "You have stubbed your toe. Idiot.\nYou have "+life+" health remaining." +Wiff);

}
if (hitchance >= 35 && hitchance <= 74){//Regular Hit
    int regHit = chance.nextInt(20)+1;
    life2 = life2-regHit;
    JOptionPane.showMessageDialog(null, "You have hit your opponent for "+regHit+" damage!\nThey have "+life2+" health remaining.");

}
if (hitchance >= 75 && hitchance <= 90){//CritHit
    int critHit = chance.nextInt(40)+1;
    life2 = life2-critHit;
    JOptionPane.showMessageDialog(null, "You have dealt critical damage! "+critHit+"\nThey have "+life2+" health reamining.");

}
if (hitchance >= 91 && hitchance <= 100) {//Fatality.      
    JOptionPane.showMessageDialog(null, "Fatality!\nYou stabbed your opponent in the foot,\ndrug your knife throught"
            + "his belly,\nand impaled his head on your knife!");
    System.exit(0);

}

int hitchance2 = chance.nextInt(100)+1;
System.out.println(hitchance2); //Enemy roll
if (hitchance2 <= 20 ){//Miss
    JOptionPane.showMessageDialog(null, "Your opponent has missed you.\nYou have "+life+" health remaining.");

}
if (hitchance2 >= 21 && hitchance <= 34){//Wiff
    int Wiff = chance.nextInt(10)+1;
    life2 = life2-Wiff;
    JOptionPane.showMessageDialog(null, "Your enemy has stubbed his toe. Idiot.\nThey have "+life2+" health remaining." +Wiff+" Damage dealt.");

}
if (hitchance2 >= 35 && hitchance <= 74){//Regular Hit
    int regHit = chance.nextInt(20)+1;
    life = life-regHit;
    JOptionPane.showMessageDialog(null, "Your opponent has hit you for "+regHit+" damage!\nYou have "+life+" health remaining.");

}
if (hitchance2 >= 75 && hitchance <= 90){//CritHit
    int critHit = chance.nextInt(40)+1;
    life = life-critHit;
    JOptionPane.showMessageDialog(null, "Your opponent has dealt critical damage! "+critHit+"\nYou have "+life+" health reamining.");

}
if (hitchance2 >= 91 && hitchance2 <= 100) {//Fatality.      
    JOptionPane.showMessageDialog(null, "Fatality!\nYour opponent stabbed you in the foot,\ndrug their knife through"
            + "your belly,\nand impaled your head on his knife!");
    System.exit(0);

}
}
}
}




Aucun commentaire:

Enregistrer un commentaire