Advertisement
Guest User

Untitled

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