Guest User

Untitled

a guest
Mar 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.20 KB | None | 0 0
  1. package text.based.adventure;
  2.  
  3. import java.util.*;
  4.  
  5. public class TextBasedAdventure {
  6.  
  7. public static String Name;
  8. public static int HP;
  9. public static int maxHP;
  10. public static int xp;
  11. public static int atk;
  12. public static int def;
  13. public static int lvl;
  14. public static int potion;
  15. static Random rand = new Random( );
  16. static Scanner UI = new Scanner(System.in);
  17. public static int dam = rand.nextInt(6)+ 1;
  18. public static int heal = rand.nextInt(6)+ 1;
  19.  
  20. public static void room2(){
  21.  
  22. }
  23.  
  24.  
  25. public static void StartRoom() throws InterruptedException{
  26. String input;
  27.  
  28. System.out.println("The room is dark and gloomy, it reeks of dead corpses and rotten food,");
  29. System.out.println("You look behind you, the skeleton you recently killed and the damaged map are on the floor");
  30. System.out.println("the only choice no is to move forward");
  31. System.out.println("avail commands: forward, heal");
  32. input = UI.nextLine();
  33. if(input.equals("heal")){
  34. potion = potion - 1;
  35. HP = maxHP;
  36. System.out.print("You are now at max HP, HP=" + HP);
  37. Thread.sleep(2000);
  38. StartRoom();
  39. }else if(input.equals("forward")){
  40. room2();
  41. }else{
  42. System.out.print("Please Choose A Valid Command");
  43. Thread.sleep(2000);
  44. StartRoom();
  45. }
  46. }
  47.  
  48.  
  49. public static void combatskel() throws InterruptedException{
  50. int skeldam = rand.nextInt(3)+ 1;
  51. String input;
  52. int hpskel;
  53. hpskel = 5;
  54. if(HP<=0){
  55. gameover();
  56.  
  57. }
  58. if(hpskel<=0){
  59. System.out.println("You Defeated A Skeleton");
  60. atk = atk + 1;
  61. def = def + 1;
  62. maxHP = maxHP + 1;
  63.  
  64. System.out.format("You Have Leveled Up! atk is now %d, def is now %d, HP is now %d", atk, def, HP);
  65. System.out.println("");
  66. return;
  67. }
  68. while (hpskel>0){
  69. input = UI.nextLine();
  70. if(input.equals("attack")){
  71. hpskel = hpskel - dam - atk;
  72. HP = HP - skeldam;
  73. System.out.format("You Have Been Hit, Your HP is %d", HP);
  74. System.out.println("");
  75. combatskel();
  76.  
  77.  
  78.  
  79. }else if(input.equals("heal")){
  80. if(potion<=0){
  81. System.out.println("You Do Not Have Enough Potions");
  82. combatskel();
  83.  
  84. }else{
  85. HP = HP + heal;
  86. System.out.println("You Have Been Healed");
  87. System.out.format("You Have Been Hit, Your HP is %d", HP);
  88. System.out.println("");
  89. HP = HP - skeldam;
  90. Thread.sleep(1200);
  91. System.out.format("You Have Been Hit, Your HP is %d", HP);
  92. System.out.println("");
  93. combatskel();
  94.  
  95. }
  96. }
  97. }
  98. }
  99.  
  100.  
  101.  
  102. public static void combatzombie() throws InterruptedException{
  103. System.out.println("You Have Encountered a zombie");
  104. int zombdam = rand.nextInt(3)+ 2;
  105. String input;
  106. int hpzomb;
  107. hpzomb = 7;
  108. if(HP<=0){
  109. gameover();
  110.  
  111. }
  112. if(hpzomb<=0){
  113. System.out.println("You Defeated A Zombie");
  114. atk = atk + 1;
  115. def = def + 1;
  116. maxHP = maxHP + 1;
  117. System.out.format("You Have Leveled Up! atk is now %d, def is now %d, HP is now %d", atk, def, HP);
  118. System.out.println("");
  119. return;
  120. }
  121. while (hpzomb>0){
  122. input = UI.nextLine();
  123. if(input.equals("attack")){
  124. hpzomb = hpzomb - dam - atk;
  125. HP = HP - zombdam;
  126. System.out.format("You Have Been Hit, Your HP is %d", HP);
  127. System.out.println("");
  128. combatzombie();
  129.  
  130.  
  131.  
  132. }else if(input.equals("heal")){
  133. if(potion<=0){
  134. System.out.println("You Do Not Have Enough Potions");
  135. combatzombie();
  136.  
  137. }else{
  138. HP = HP + heal;
  139. System.out.println("You Have Been Healed");
  140. System.out.format("You Have Been Hit, Your HP is %d", HP);
  141. System.out.println("");
  142. HP = HP - zombdam;
  143. Thread.sleep(1200);
  144. System.out.format("You Have Been Hit, Your HP is %d", HP);
  145. System.out.println("");
  146. combatzombie();
  147. }
  148.  
  149.  
  150.  
  151. }
  152.  
  153.  
  154.  
  155. }
  156.  
  157.  
  158.  
  159.  
  160. }
  161. public static void gameover() {
  162. System.out.println(Name + " Died!");
  163. System.out.println("GAME OVER!");
  164. System.exit(0); //terminates if lost
  165. }
  166.  
  167. /**
  168. * @param args the command line arguments
  169. * @throws java.lang.InterruptedException
  170. */
  171. public static void main(String[] args) throws InterruptedException {
  172. maxHP = 20;
  173. potion = 3;
  174.  
  175. System.out.println("Welcome To Dungeon Maze");
  176. System.out.println("Please Input Your Name ");
  177. Name = UI.nextLine();
  178. System.out.format("%s is a brave adventurer", Name);
  179. System.out.println("");
  180. Thread.sleep(3000);
  181. System.out.println("They were sent on a task to check on one of");
  182. Thread.sleep(3000);
  183. System.out.println("the sacred underground shrines of Port Nyanzaru,");
  184. Thread.sleep(3000);
  185. System.out.format("but when one of the skeletons knocked off the map %s had,", Name);
  186. System.out.println("");
  187. Thread.sleep(3000);
  188. System.out.println("they had no choice but to try and escape the dungeon");
  189. Thread.sleep(3000);
  190. System.out.println("ARE YOU READY BRAVE ADVENTURER");
  191. HP = maxHP;
  192. lvl = 1;
  193. def = 1;
  194. atk = 1;
  195. Thread.sleep(5000);
  196. StartRoom();
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203. }
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213. }
Add Comment
Please, Sign In to add comment