Okay so I am making a program that fights a cpu, but everytime it rolls a miss first then a fatality, ill break down my code so it makes it easier for you guys to help out.
Imports: import javax.swing.JOptionPane; import java.util.Random;
Setting up ints and the rng that determines the type of hits: int life = 100; //Your life int life2 = 100; //Enemy life Random chance = new Random(); int rand = chance.nextInt(1)+100;
The types of hits and what they should do respectively: `while (life >= 0 && life2 >= 0){
if (rand >= 20 ){//Miss
JOptionPane.showMessageDialog(null, "You have missed your opponent like a fool.\nYour Opponent has "+life2+" remaining.");
}
if (rand <= 21 && rand >= 34){//Wiff
int Wiff = chance.nextInt(10)+1;
life = life-Wiff;
JOptionPane.showMessageDialog(null, "You have stubbed your toe. Idiot.\nYou have "+life+" remaining."+Wiff);
}
if (rand <= 35 && rand >= 74){//Regular Hit
int regHit = chance.nextInt(20)+1;
life2 = life2-regHit;
JOptionPane.showMessageDialog(null, "You have hit your opponent!"+regHit);
}
if (rand <= 74 && rand >= 90){//CritHit
int critHit = chance.nextInt(40)+1;
life2 = life2-critHit;
JOptionPane.showMessageDialog(null, "You have dealt critical damage!"+critHit);
}
else {//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);
}
}
} } ` I'm willing to try anything, i am in desperate need to finish this guys, thanks for all help.
Aucun commentaire:
Enregistrer un commentaire