Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.38 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class CPTTextRPG {
  4. // intializes class and will assign stats later to this
  5. static int[] cclass = { 0, 0, 0, 0 };
  6. // defines stats as variables for easy access
  7. // global variables to access in methods
  8. static int playerHP = cclass[0];
  9. static int playerminATT = cclass[1];
  10. static int playermaxATT = cclass[2];
  11. static int playerDEF = cclass[3];
  12.  
  13. public static void main(String[] args) {
  14. Scanner sc = new Scanner(System.in);
  15. Random rand = new Random();
  16. String name = "";
  17.  
  18. // action
  19. String action = "";
  20.  
  21. // list of monsters/enemies
  22. int[] wolf = { 100, 15, 0 };
  23. int[] giantape = { 200, 25, 8 };
  24.  
  25. // hp,minATT,maxATT,defense
  26. int[] warrior = { 250, 20, 30, 10 };
  27. int[] mage = { 150, 15, 25, 4 };
  28. int[] assassin = { 165, 20, 35, 7 };
  29. int[] archer = { 140, 15, 30, 6 };
  30.  
  31. // intro
  32. System.out.println("Welcome to The Legend of Heroes!");
  33. System.out.println("A Text-Based RPG game!");
  34. // player name and class picker
  35. System.out.println("");
  36. System.out.println("May I ask your name squire?");
  37. name = sc.nextLine();
  38. System.out.println("Sounds great, " + name + "!");
  39.  
  40. System.out.println(
  41. "Now, choose a class! Pick between Warrior(\"w\"), Mage(\"m\"), Assassin(\"as\"), or Archer(\"ar\")");
  42. String c = sc.nextLine();
  43.  
  44. // warrior
  45. boolean picked = false;
  46. while (picked == false) {
  47. if (c.equalsIgnoreCase("w")) {
  48. cclass = warrior;
  49. System.out.println("Great pick, " + name + "! You chose the Warrior class.");
  50. System.out.println("Here are your stats:");
  51. System.out.println("HP: " + cclass[0]);
  52. System.out.println("ATT Range: " + cclass[1] + "-" + cclass[2]);
  53. System.out.println("DEF: " + cclass[3]);
  54. System.out.println("I have given you a sword to use!");
  55. System.out.println("");
  56. picked = true;
  57. }
  58. // mage
  59. else if (c.equalsIgnoreCase("m")) {
  60. cclass = mage;
  61. System.out.println("Great pick, " + name + "! You chose the Mage class.");
  62. System.out.println("Here are your stats:");
  63. System.out.println("HP: " + cclass[0]);
  64. System.out.println("ATT Range: " + cclass[1] + "-" + cclass[2]);
  65. System.out.println("DEF: " + cclass[3]);
  66. System.out.println("I have given you a staff to use!");
  67. System.out.println("");
  68. picked = true;
  69. }
  70. // assassin
  71. else if (c.equalsIgnoreCase("as")) {
  72. cclass = assassin;
  73. System.out.println("Great pick, " + name + "! You chose the Assassin class.");
  74. System.out.println("Here are your stats:");
  75. System.out.println("HP: " + cclass[0]);
  76. System.out.println("ATT Range: " + cclass[1] + "-" + cclass[2]);
  77. System.out.println("DEF: " + cclass[3]);
  78. System.out.println("I have given you dual daggers to use!");
  79. System.out.println("");
  80. picked = true;
  81. }
  82. // archer
  83. else if (c.equalsIgnoreCase("ar")) {
  84. cclass = archer;
  85. System.out.println("Great pick, " + name + "! You chose the Archer class.");
  86. System.out.println("Here are your stats:");
  87. System.out.println("HP: " + cclass[0]);
  88. System.out.println("ATT Range: " + cclass[1] + "-" + cclass[2]);
  89. System.out.println("DEF: " + cclass[3]);
  90. System.out.println("I have given you a bow to use!");
  91. System.out.println("");
  92. picked = true;
  93. }
  94. else {
  95. System.out.println("Wrong input!");
  96. System.out.println("Choose again!");
  97. c = sc.nextLine();
  98. }
  99. }
  100.  
  101. // Start Adventure
  102. System.out.println("Look in the distance, a wolf!");
  103. System.out.println("Kill it to gain better stats!");
  104.  
  105. // call the attackMonster method for wolf
  106. attackMonster(wolf[0], wolf[1], wolf[2], playerHP, playerminATT, playermaxATT, playerDEF, "Wolf");
  107. System.out.println("");
  108. System.out.println("Good Job out there " + name + "!");
  109. System.out.println("You gained better stats by killing your first enemy!");
  110. // gain stats
  111. playerHP = playerHP + 50;
  112. playerminATT = playerminATT + 10;
  113. playermaxATT = playermaxATT + 15;
  114. playerDEF = playerDEF + 8;
  115.  
  116. System.out.println("");
  117. System.out.println("Now is no time to rest, " + name + "!");
  118. System.out.println("There's a giant ape attacking the villagers ahead! Go kill it and defend the villagers!");
  119. // call the attackMonster method for giantape
  120. attackMonster(giantape[0], giantape[1], giantape[2], playerHP, playerminATT, playermaxATT, playerDEF, "Giant Ape");
  121. System.out.println("");
  122. System.out.println("You saved the villagers, " + name + "!");
  123. System.out.println("You will need these stats for the final boss battle but first, you need a better weapon!");
  124. playerHP = playerHP + 200;
  125. playerminATT = playerminATT + 30;
  126. playermaxATT = playermaxATT + 50;
  127. playerDEF = playerDEF + 12;
  128. System.out.println("Head over to the blacksmith and he can give you a way stronger weapon; however, it will be random!");
  129. randomItem(c);
  130. }
  131.  
  132. // attack any type of monster method
  133. public static void attackMonster(int monsterHP, int monsterATT, int monsterDEF, int playerHP, int minAttack, int maxAttack,
  134. int playerDEF, String monsterName) {
  135. Scanner sc = new Scanner(System.in);
  136. // attacking system
  137. System.out.println("Type \"a\" to attack or \"d\" to defend!");
  138. Random rand = new Random();
  139. String action = "";
  140. while (monsterHP > 0) {
  141. int pattack = rand.nextInt((maxAttack - minAttack) + 1) + minAttack;
  142. action = sc.next();
  143. if (action.equalsIgnoreCase("a")) {
  144. monsterHP = monsterHP - (pattack - monsterDEF);
  145. if (monsterHP <= 0) {
  146. System.out.println("You hit the " + monsterName + " for " + pattack + " damage! " + monsterName + " HP now at "
  147. + 0);
  148. }
  149. else {
  150. System.out.println("You hit the " + monsterName + " for " + pattack + " damage! " + monsterName + " HP now at "
  151. + monsterHP);
  152. System.out.println("The " + monsterName + " hit back for " + (monsterATT - playerDEF) + "! You are now at "
  153. + (playerHP -= (monsterATT - playerDEF)) + "HP");
  154. System.out.println("");
  155. }
  156.  
  157. }
  158. if (action.equalsIgnoreCase("d")) {
  159. int pdefend = rand.nextInt(3);
  160. if (pdefend >= 1) {
  161. System.out.println("You defended against the " + monsterName + ". You took no damage!");
  162. }
  163. else {
  164. System.out.println("The " + monsterName + " went through your block and hit you for " + (monsterATT - playerDEF)
  165. + "! You are now at " + (playerHP - (monsterATT - playerDEF)) + "HP");
  166. }
  167. }
  168. if (monsterHP < 0 || monsterHP == 0) {
  169. System.out.println("");
  170. System.out.println("You have defeated the " + monsterName + "!");
  171. }
  172. if (playerHP <= 0) {
  173. System.out.println("You Lose...");
  174. }
  175. }
  176. }
  177.  
  178. public static void randomItem(String c) {
  179. Scanner sc = new Scanner(System.in);
  180. Random rand = new Random();
  181. System.out.println("Welcome to the Blacksmith! I heard you need a new weapon and you have come to the right place!");
  182. System.out.println("It will be random but it will be stronger than your current weapon!");
  183. int randomNum = rand.nextInt(100);
  184. boolean picked = false;
  185. while (picked == false) {
  186. if (c.equalsIgnoreCase("w")) {
  187. if (randomNum <= 50) {
  188. System.out.println("You got the Dark Sword! +25 Attack!");
  189. playerminATT += 25;
  190. playermaxATT += 25;
  191. picked = true;
  192. }
  193. else {
  194. System.out.println("You got the Holy Excalibur! +30 Attack!");
  195. playerminATT += 30;
  196. playermaxATT += 30;
  197. picked = true;
  198. }
  199. }
  200. else if (c.equalsIgnoreCase("m")) {
  201. if (randomNum <= 50) {
  202. System.out.println("You got the Dark Staff! +25 Attack!");
  203. playerminATT += 25;
  204. playermaxATT += 25;
  205. picked = true;
  206. }
  207. else if (randomNum > 98) {
  208. System.out.println("You got the EXPROSION STAFF! +100 Attack!");
  209. playerminATT += 100;
  210. playermaxATT += 100;
  211. picked = true;
  212. }
  213. else {
  214. System.out.println("You got the Holy Staff! +30 Attack!");
  215. playerminATT += 30;
  216. playermaxATT += 30;
  217. picked = true;
  218. }
  219.  
  220. }
  221. else if (c.equalsIgnoreCase("as")) {
  222. if (randomNum <= 50) {
  223. System.out.println("You got the Dark Dual Daggers! +30 Attack!");
  224. playerminATT += 30;
  225. playermaxATT += 30;
  226. picked = true;
  227. }
  228. else {
  229. System.out.println("You got the Holy Dual Daggers! +25 Attack!");
  230. playerminATT += 25;
  231. playermaxATT += 25;
  232. picked = true;
  233. }
  234. }
  235. else if (c.equalsIgnoreCase("ar")) {
  236. if (randomNum <= 50) {
  237. System.out.println("You got the Dark Bow! +25 Attack!");
  238. playerminATT += 25;
  239. playermaxATT += 25;
  240. picked = true;
  241. }
  242. else if (randomNum > 98) {
  243. System.out.println("You got Phantom Hecate II! +100 Attack!");
  244. playerminATT += 100;
  245. playermaxATT += 100;
  246. picked = true;
  247. }
  248. else {
  249. System.out.println("You got the Holy Bow! +30 Attack!");
  250. playerminATT += 30;
  251. playermaxATT += 30;
  252. picked = true;
  253. }
  254.  
  255. }
  256. }
  257.  
  258. }
  259.  
  260. // final boss battle method
  261. public static void bossFight(int monsterHP, int monsterATT, int monsterDEF, int playerHP, int minAttack, int maxAttack, int playerDEF,
  262. String monsterName) {
  263. Scanner sc = new Scanner(System.in);
  264. Random rand = new Random();
  265. System.out.println("Type \"a\" to attack or \"d\" to defend!");
  266. String action = "";
  267. while (monsterHP > 0) {
  268. int pattack = rand.nextInt((maxAttack - minAttack) + 1) + minAttack;
  269. action = sc.next();
  270. if (action.equalsIgnoreCase("a")) {
  271. monsterHP = monsterHP - (pattack - monsterDEF);
  272. if (monsterHP <= 0) {
  273. System.out.println("You hit the " + monsterName + " for " + pattack + " damage!" + monsterName + " HP now at "
  274. + 0);
  275. }
  276. else {
  277. System.out.println("You hit the " + monsterName + " for " + pattack + " damage" + monsterName + " HP now at "
  278. + monsterHP);
  279. System.out.println("The " + monsterName + " hit back for " + (monsterATT - playerDEF) + "! You are now at "
  280. + (playerHP -= (monsterATT - playerDEF)) + "HP");
  281. System.out.println("");
  282. }
  283.  
  284. }
  285. if (action.equalsIgnoreCase("d")) {
  286. int pdefend = rand.nextInt(3);
  287. if (pdefend >= 1) {
  288. System.out.println("You defended against the " + monsterName + ". You took no damage!");
  289. }
  290. else {
  291. System.out.println("The " + monsterName + " went through your block and hit you for " + (monsterATT - playerDEF)
  292. + "! You are now at " + (playerHP - (monsterATT - playerDEF)) + "HP");
  293. }
  294. }
  295. if (monsterHP < 0 || monsterHP == 0) {
  296. System.out.println("");
  297. System.out.println("You have defeated the " + monsterName + "!");
  298. }
  299. if (playerHP <= 0) {
  300. System.out.println("You Lose...");
  301. }
  302. }
  303. }
  304. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement