Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. package textGame;
  2.  
  3. import java.util.Random;
  4. import java.util.Scanner;
  5.  
  6. public class main {
  7. public static void main(String[] args) {
  8.  
  9. // System objects
  10. Scanner in = new Scanner(System.in);
  11. Random rand = new Random();
  12.  
  13. // Game Variables
  14. String[] enemies = { "Skeleton", "Zombie", "Warrior", "Assassin"};
  15. int maxEnemyHealth = 75;
  16. int enemyAttackDamage = 25;
  17.  
  18. // Player Variables
  19. int health = 100;
  20. int attackDamage = 50;
  21. int numHealthPotions = 3;
  22. int healthPotionHealAmount = 30;
  23. int healthPotionDropChance = 50; // Percent
  24.  
  25. boolean running = true;
  26.  
  27. System.out.println("Welcome to the Dungeon!");
  28.  
  29. GAME:
  30. while(running) {
  31. System.out.println("-----------------------------------------------");
  32.  
  33. int enemyHealth = rand.nextInt(maxEnemyHealth);
  34. String enemy = enemies[rand.nextInt(enemies.length)];
  35. System.out.println("\t# " + enemy + " has appeared! #\n");
  36.  
  37. while(enemyHealth > 0) {
  38. System.out.println("\tYour HP:" + health);
  39. System.out.println("\t" + enemy + "'s HP: " + enemyHealth);
  40. System.out.println("\n\tWhat would you like to do?");
  41. System.out.println("\t1. Attack");
  42. System.out.println("\t2. Drink health potion");
  43. System.out.println("\t3. Run!");
  44.  
  45. String input = in.nextLine();
  46. if(input.equals("1")) {
  47. int damageDealt = rand.nextInt(attackDamage);
  48. int damageTaken = rand.nextInt(enemyAttackDamage);
  49.  
  50. enemyHealth -= damageDealt;
  51. health -= damageTaken;
  52.  
  53. System.out.println("\t> You strike the " + enemy + " for " + damageDealt + " damage.");
  54. System.out.println("\t> You recieve " + damageTaken + " in retaliation!");
  55.  
  56. if(health < 1) {
  57. System.out.println("\t> You have taken too much damage, you are too weak to go on!");
  58. break;
  59. }
  60. }
  61. else if(input.equals("2")) {
  62. if(numHealthPotions > 0) {
  63. health += healthPotionHealAmount;
  64. numHealthPotions--;
  65. System.out.println("\t> You drink a health potion, healing yourself for " + healthPotionHealAmount + "."
  66. + "\n\t> You now have " + health + " HP."
  67. + "\n\t> You have " + numHealthPotions + " health potions left.\n");
  68.  
  69. }
  70.  
  71.  
  72. else {
  73. System.out.println("\t> You have no health potions left! Defeat an enemy for a chance to get one.");
  74. }
  75. }
  76.  
  77.  
  78. else if(input.equals("3")) {
  79. System.out.println("\tYou have run away from the " + enemy + "!");
  80. continue GAME;
  81. }
  82. else {
  83. System.out.println("\tInvalid command.");
  84. }
  85. }
  86. }
  87.  
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement