MORE dice fun!
import java.util.Random;
public class diceWars {
public static void main(String[] args) {
Random dice = new Random();
int playerRoll;
int npcRoll;
int npcHealth = 5;
int playerHealth = 5;
while (playerHealth > 0) {
playerRoll =dice.nextInt(20)+1;
npcRoll =dice.nextInt(20)+1;
System.out.println("Player rolls a " +playerRoll);
System.out.println("Npc rolls a " +npcRoll);
if (playerRoll > npcRoll) {
npcHealth = --npcHealth;
System.out.println("Player scores direct and the enemy has " + npcHealth + " points remaining\n");
}
else if (npcRoll > playerRoll) {
playerHealth = --playerHealth;
System.out.println("Player takes a hit and has " + playerHealth + " points left!\n");
}
else if (playerRoll == npcRoll) {
System.out.println("Tied, roll again\n");
}
if (playerHealth == 0) {
System.out.println("Player has died\n");
break;
}
if (npcHealth == 0) {
System.out.println("congrats, you have defeated the enemy!");
break;
}
}
}
}
No comments:
Post a Comment