Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.57 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,
  107. // playermaxATT, playerDEF, "wolf");
  108. System.out.println("");
  109. System.out.println("Good Job out there " + name + "!");
  110. System.out.println("You gained better stats by killing your first enemy!");
  111. // gain stats
  112. playerHP = playerHP + 50;
  113. playerminATT = playerminATT + 10;
  114. playermaxATT = playermaxATT + 15;
  115. playerDEF = playerDEF + 8;
  116.  
  117. System.out.println("");
  118. System.out.println("Now is no time to rest, " + name + "!");
  119. System.out.println("There's a giant ape attacking the villagers ahead! Go kill it and defend the villagers!");
  120. // call the attackMonster method for giantape
  121. attackMonster(giantape[0], giantape[1], giantape[2], playerHP, playerminATT,
  122. playermaxATT, playerDEF, "Giant Ape");
  123. System.out.println("");
  124. System.out.println("You saved the villagers, " + name + "!");
  125. System.out.println("You will need these stats for the final boss battle but first, you need a better weapon!");
  126. playerHP = playerHP + 200;
  127. playerminATT = playerminATT + 30;
  128. playermaxATT = playermaxATT + 50;
  129. playerDEF = playerDEF + 12;
  130. System.out.println("Head over to the blacksmith and he can give you a way stronger weapon; however, it will be random!");
  131. randomItem(c);
  132. }
  133.  
  134. // attack any type of monster method
  135. public static void attackMonster(int monsterHP, int monsterATT, int monsterDEF, int playerHP, int minAttack, int maxAttack,
  136. int playerDEF, String monsterName) {
  137. Scanner sc = new Scanner(System.in);
  138. // attacking system
  139. System.out.println("Type \"a\" to attack or \"d\" to defend!");
  140. Random rand = new Random();
  141. String action = "";
  142. while (monsterHP > 0) {
  143. int pattack = rand.nextInt((maxAttack - minAttack) + 1) + minAttack;
  144. action = sc.next();
  145. if (action.equalsIgnoreCase("a")) {
  146. monsterHP = monsterHP - (pattack - monsterDEF);
  147. if (monsterHP <= 0) {
  148. System.out.println("You hit the " + monsterName + " for " + pattack + " damage! " + monsterName + " HP now at "
  149. + 0);
  150. }
  151. else {
  152. System.out.println("You hit the " + monsterName + " for " + pattack + " damage! " + monsterName + " HP now at "
  153. + monsterHP);
  154. System.out.println("The " + monsterName + " hit back for " + (monsterATT - playerDEF) + "! You are now at "
  155. + (playerHP -= (monsterATT - playerDEF)) + "HP");
  156. System.out.println("");
  157. }
  158.  
  159. }
  160. if (action.equalsIgnoreCase("d")) {
  161. int pdefend = rand.nextInt(3);
  162. if (pdefend >= 1) {
  163. System.out.println("You defended against the " + monsterName + ". You took no damage!");
  164. }
  165. else {
  166. System.out.println("The " + monsterName + " went through your block and hit you for " + (monsterATT - playerDEF)
  167. + "! You are now at " + (playerHP - (monsterATT - playerDEF)) + "HP");
  168. }
  169. }
  170. if (monsterHP < 0 || monsterHP == 0) {
  171. System.out.println("");
  172. System.out.println("You have defeated the " + monsterName + "!");
  173. }
  174. if (playerHP <= 0) {
  175. System.out.println("You Lose...");
  176. }
  177. }
  178. }
  179.  
  180. public static void randomItem(String c) {
  181. Scanner sc = new Scanner(System.in);
  182. Random rand = new Random();
  183. System.out.println("Welcome to the Blacksmith! I heard you need a new weapon and you have come to the right place!");
  184. System.out.println("It will be random but it will be stronger than your current weapon!");
  185. int randomNum = rand.nextInt(100);
  186. boolean picked = false;
  187. while (picked == false) {
  188. if (c.equalsIgnoreCase("w")) {
  189. if (randomNum <= 50) {
  190. System.out.println("You got the Dark Sword! +25 Attack!");
  191. playerminATT += 25;
  192. playermaxATT += 25;
  193. picked = true;
  194. }
  195. else {
  196. System.out.println("You got the Holy Excalibur! +30 Attack!");
  197. playerminATT += 30;
  198. playermaxATT += 30;
  199. picked = true;
  200. }
  201. }
  202. else if (c.equalsIgnoreCase("m")) {
  203. if (randomNum <= 50) {
  204. System.out.println("You got the Dark Staff! +25 Attack!");
  205. playerminATT += 25;
  206. playermaxATT += 25;
  207. picked = true;
  208. }
  209. else if (randomNum > 98) {
  210. System.out.println("You got the EXPROSION STAFF! +100 Attack!");
  211. playerminATT += 100;
  212. playermaxATT += 100;
  213. picked = true;
  214. }
  215. else {
  216. System.out.println("You got the Holy Staff! +30 Attack!");
  217. playerminATT += 30;
  218. playermaxATT += 30;
  219. picked = true;
  220. }
  221.  
  222. }
  223. else if (c.equalsIgnoreCase("as")) {
  224. if (randomNum <= 50) {
  225. System.out.println("You got the Dark Dual Daggers! +30 Attack!");
  226. playerminATT += 30;
  227. playermaxATT += 30;
  228. picked = true;
  229. }
  230. else {
  231. System.out.println("You got the Holy Dual Daggers! +25 Attack!");
  232. playerminATT += 25;
  233. playermaxATT += 25;
  234. picked = true;
  235. }
  236. }
  237. else if (c.equalsIgnoreCase("ar")) {
  238. if (randomNum <= 50) {
  239. System.out.println("You got the Dark Bow! +25 Attack!");
  240. playerminATT += 25;
  241. playermaxATT += 25;
  242. picked = true;
  243. }
  244. else if (randomNum > 98) {
  245. System.out.println("You got Phantom Hecate II! +100 Attack!");
  246. playerminATT += 100;
  247. playermaxATT += 100;
  248. picked = true;
  249. }
  250. else {
  251. System.out.println("You got the Holy Bow! +30 Attack!");
  252. playerminATT += 30;
  253. playermaxATT += 30;
  254. picked = true;
  255. }
  256.  
  257. }
  258. }
  259.  
  260. }
  261.  
  262. // final boss battle method
  263. public static void bossFight(int monsterHP, int monsterATT, int monsterDEF, int playerHP, int minAttack, int maxAttack, int playerDEF,
  264. String monsterName) {
  265. Scanner sc = new Scanner(System.in);
  266. Random rand = new Random();
  267. System.out.println("Type \"a\" to attack or \"d\" to defend!");
  268. String action = "";
  269. while (monsterHP > 0) {
  270. int pattack = rand.nextInt((maxAttack - minAttack) + 1) + minAttack;
  271. action = sc.next();
  272. if (action.equalsIgnoreCase("a")) {
  273. monsterHP = monsterHP - (pattack - monsterDEF);
  274. if (monsterHP <= 0) {
  275. System.out.println("You hit the " + monsterName + " for " + pattack + " damage!" + monsterName + " HP now at "
  276. + 0);
  277. }
  278. else {
  279. System.out.println("You hit the " + monsterName + " for " + pattack + " damage" + monsterName + " HP now at "
  280. + monsterHP);
  281. System.out.println("The " + monsterName + " hit back for " + (monsterATT - playerDEF) + "! You are now at "
  282. + (playerHP -= (monsterATT - playerDEF)) + "HP");
  283. System.out.println("");
  284. }
  285.  
  286. }
  287. if (action.equalsIgnoreCase("d")) {
  288. int pdefend = rand.nextInt(3);
  289. if (pdefend >= 1) {
  290. System.out.println("You defended against the " + monsterName + ". You took no damage!");
  291. }
  292. else {
  293. System.out.println("The " + monsterName + " went through your block and hit you for " + (monsterATT - playerDEF)
  294. + "! You are now at " + (playerHP - (monsterATT - playerDEF)) + "HP");
  295. }
  296. }
  297. if (monsterHP < 0 || monsterHP == 0) {
  298. System.out.println("");
  299. System.out.println("You have defeated the " + monsterName + "!");
  300. }
  301. if (playerHP <= 0) {
  302. System.out.println("You Lose...");
  303. }
  304. }
  305. }
  306. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement