UrbanTwitch
09-26-2009, 04:03 AM
OK so, run this in TextPad or something (compile and run)
/** Simple Battle Class
DAN
**/
import java.util.*;
import java.io.*;
import java.util.Random;
public class oldBATTLE {
public static void main(String[] args){
battle();
}
public static void battleDone(){
System.out.println("Battle has finished.");
}
public static void battle(){
Random diceRoller = new Random();
int count = 0;
int monhp = 100;
int numb = 100;
int enem = 100;
while (monhp > 1 || numb > 1) {
int nit = diceRoller.nextInt(20);
int otherx = diceRoller.nextInt(20);
int nf = monhp-nit;
int nx = numb-otherx;
if (nx <= 0 ) {
nx = 0;
System.out.println("You killed the monster! It took "+count+" tries. Your HP left " +nf);
}
if (nf <= 0) {
nf = 0; System.out.println("You died! It took "+count+" tries. Monster's HP left "+nx);
}
System.out.println("MONSTER hit for "+nit+"\nYOUR Old HP: "+monhp+"\nYOUR New HP: " + nf +"\n----\n");
System.out.println("YOU hit for "+otherx+"\nMONSTER's Old HP: "+numb+"\nMONSTER's New HP: " + nx+"\n----\n");
monhp = nf;
numb = nx;
count++;
if (nf <= 0 || nx <= 0) {
battleDone();
break;
}
}
if (monhp <= 0) {
System.out.println("Your Final HP "+ numb+". You killed the monster! It took "+count+" times for you to kill it.");
}
if (numb <= 0) {
System.out.println("Monster's Final HP "+ monhp+". You died! It took "+count+" times to defeat you.");
}
}
}
You will see that even if my Hp (numb) reaches zero.. the monster will hit me back one last time THEN it will stop (since my hp reached) zero.
The same thing goes for monster but only vice versa.
The problem is that when either mine or monster's HP is at 0 then there should be the message saying like...
MONSTER hit you for 19
Old HP: 12
New HP: 0
You Hit for.. etc
Get what I am saying? Since my HP is 0.. I should be dead and the battle should be done...
help?
/** Simple Battle Class
DAN
**/
import java.util.*;
import java.io.*;
import java.util.Random;
public class oldBATTLE {
public static void main(String[] args){
battle();
}
public static void battleDone(){
System.out.println("Battle has finished.");
}
public static void battle(){
Random diceRoller = new Random();
int count = 0;
int monhp = 100;
int numb = 100;
int enem = 100;
while (monhp > 1 || numb > 1) {
int nit = diceRoller.nextInt(20);
int otherx = diceRoller.nextInt(20);
int nf = monhp-nit;
int nx = numb-otherx;
if (nx <= 0 ) {
nx = 0;
System.out.println("You killed the monster! It took "+count+" tries. Your HP left " +nf);
}
if (nf <= 0) {
nf = 0; System.out.println("You died! It took "+count+" tries. Monster's HP left "+nx);
}
System.out.println("MONSTER hit for "+nit+"\nYOUR Old HP: "+monhp+"\nYOUR New HP: " + nf +"\n----\n");
System.out.println("YOU hit for "+otherx+"\nMONSTER's Old HP: "+numb+"\nMONSTER's New HP: " + nx+"\n----\n");
monhp = nf;
numb = nx;
count++;
if (nf <= 0 || nx <= 0) {
battleDone();
break;
}
}
if (monhp <= 0) {
System.out.println("Your Final HP "+ numb+". You killed the monster! It took "+count+" times for you to kill it.");
}
if (numb <= 0) {
System.out.println("Monster's Final HP "+ monhp+". You died! It took "+count+" times to defeat you.");
}
}
}
You will see that even if my Hp (numb) reaches zero.. the monster will hit me back one last time THEN it will stop (since my hp reached) zero.
The same thing goes for monster but only vice versa.
The problem is that when either mine or monster's HP is at 0 then there should be the message saying like...
MONSTER hit you for 19
Old HP: 12
New HP: 0
You Hit for.. etc
Get what I am saying? Since my HP is 0.. I should be dead and the battle should be done...
help?