Advertisement
Guest User

RPG

a guest
May 28th, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.20 KB | None | 0 0
  1. import java.awt.Graphics;
  2. import javax.swing.JPanel;
  3. import java.util.Scanner;
  4. import java.awt.Color;
  5. import java.io.File;
  6. import java.io.IOException;
  7. import javax.imageio.ImageIO;
  8. import java.awt.image.BufferedImage;
  9. import java.awt.*;
  10. import java.lang.*;
  11. import javax.swing.*;
  12. import java.io.Writer;
  13. import java.util.concurrent.ThreadLocalRandom;
  14. //////////////////////////////
  15. import java.awt.event.KeyEvent;
  16. import java.awt.event.KeyListener;
  17. import java.awt.event.*;
  18. //////////////////////////////
  19. public class RPG extends JPanel{ //implements KeyListener{
  20. public static String name;
  21. public static String profession;
  22. public static String weapon;
  23. public static int Phealth = 200;
  24. public static int Pdamage;
  25. public static int Pspeed;
  26. public static int Pcrit;
  27. //WEAPONS//
  28. public static int axeDamage;
  29. public static int axeSpeed;
  30. public static int axeCritChance;
  31. public static String axePhrase;
  32. //--//
  33. public static int bowDamage;
  34. public static int bowSpeed;
  35. public static int bowCritChance;
  36. public static String bowPhrase;
  37. //--//
  38. public static int fistDamage;
  39. public static int fistSpeed;
  40. public static int fistCritChance;
  41. public static String fistPhrase;
  42. //--//
  43. //BASE ENEMIES//
  44. public static int damage;
  45. public static int speed;
  46. public static int crit;
  47. public static int Enemyhealth;
  48. //--//
  49. public static Items its = new Items();
  50. public static void main(String[] args){
  51. LoopTester();
  52. }
  53.  
  54.  
  55. public static void LoopTester(){
  56. boolean contin = false;
  57. while(contin == false){
  58. Scanner typing = new Scanner(System.in);
  59. System.out.println("Would You Like To Start? Y/N");
  60.  
  61. String scan = typing.nextLine();
  62. if(scan.equalsIgnoreCase("y")){ contin = true; runIntro(); }
  63. else if(contin = false);
  64. }
  65. }
  66.  
  67.  
  68.  
  69.  
  70.  
  71. public static void runIntro(){
  72. its.GrantHealthPack();
  73. Scanner typing = new Scanner(System.in);
  74. Print("Input Name!");
  75. name = typing.nextLine();
  76. System.out.println("Now it is time to fight for glory!");
  77. System.out.println("Now " + name + " you must take on one foe in battle before proving yourself worthy to his highness! DO YOU ACCEPT MY QUEST! Y/N");
  78. String YN = typing.nextLine();
  79. if(YN.equalsIgnoreCase("y")) { }
  80. else{Print("Now " + name + " you must take on one foe in battle before proving yourself worthy to his highness! DO YOU ACCEPT MY QUEST! Y/N"); YN = typing.nextLine(); }
  81. Print("What Weapon Shall You weild!");
  82. Print("Axe,Bow,Fists");
  83. weapon = typing.nextLine();
  84. if(weapon.equalsIgnoreCase("Axe")){ WeaponIndex(); Print(axePhrase); System.out.println("Damage: " + axeDamage + " Speed: " + axeSpeed + " CritChance: " + axeCritChance);Pdamage = axeDamage;Pspeed = axeSpeed;Pcrit = axeCritChance;}
  85. else if(weapon.equalsIgnoreCase("Bow")){ WeaponIndex(); Print(bowPhrase); System.out.println("Damage: " + bowDamage + " Speed: " + bowSpeed + " CritChance: " + bowCritChance);Pdamage = bowDamage;Pspeed = bowSpeed;Pcrit = bowCritChance;}
  86. else if(weapon.equalsIgnoreCase("fists")){ WeaponIndex(); Print(fistPhrase); System.out.println("Damage: " + fistDamage + " Speed: " + fistSpeed + " CritChance: " + fistCritChance);Pdamage = bowDamage;Pspeed = bowSpeed;Pcrit = bowCritChance;}
  87. else{Print("What Weapon Shall You weild!");Print("Axe,Bow,Fists");weapon = typing.nextLine();}
  88. firstFight();
  89. Print("Well done! You have completed your first quest!");
  90. System.out.println("It is time for you to see the king " + name);
  91. System.out.println("So what profession were you before becoming a warrior?");
  92. profession = typing.nextLine();
  93. PrintExclam(profession + " Really! I would have never thought!");
  94. System.out.println("Something funny about " + profession + "... even " + profession + "'s cant steal my place next to the king!");
  95. System.out.println("I fight to the death! I shall not see the day you enter the kings court!");
  96. Print("Player recieved weapon powerup! <");
  97. Pdamage = Pdamage+5;
  98. System.out.println("Damage: " + Pdamage);
  99. fightIntroMechanics();
  100. System.out.println("I shall not see the day, for i have passed. many lifetimes shall pass and NO ONE will remember you...");
  101. Print("Player recieved healthpack!");
  102. its.GrantHealthPack();
  103. Print("Player recieved grenade!");
  104. its.GrantGrenade();
  105. mainGame();
  106.  
  107. }
  108.  
  109.  
  110. public static void mainGame(){
  111. Scanner typing = new Scanner(System.in);
  112. Print("Player's " + weapon + " granted +3 damage and +1 speed!");
  113. Pdamage = Pdamage+3;
  114. Pspeed = Pspeed+1;
  115. Print("You meet a man on the side of the road do you talk(T) or walk past him(W)");
  116. String ans = typing.nextLine();
  117. if(ans.equalsIgnoreCase("t")){ dialogTraver(); }
  118. else{}
  119. Print("you apprach a hill about 100 yards out, you have to decide on a forest or up the hill. Your not sure what is up the hill but the forest has been documented a low risk area.");
  120. System.out.println("Do you A: Go Forest(F)?");
  121. System.out.println("Or B: Go Hill(H)?");
  122. ans = typing.nextLine();
  123. if(ans.equalsIgnoreCase("F")){ forestStory(); }
  124. else if(ans.equalsIgnoreCase("H")){ Print("you found no one on your way to the top, it was a peacfull walk, but no benafits have come your way except the silence and peace in your mind."); }
  125. else{Print("you apprach a hill about 100 yards out, you have to decide on a forest or up the hill. Your not sure what is up the hill but the forest has been documented a low risk area.");
  126. System.out.println("Do you A: Go Forest(F)?");
  127. System.out.println("Or B: Go Hill(H)?");
  128. ans = typing.nextLine();}
  129.  
  130.  
  131.  
  132. }
  133. //Forest Story-Branchoff includes +3 Damage buff and + 2 crit chance, or an offer to change weapon//
  134. public static void forestStory(){
  135.  
  136. Print("As you walk in the forest a rumble comees from behind, you noptice the entrance from which you came is on longer there, you keep walking and the bright forest you saw from the outside turns into a dark and eerie place, as if it was night.");
  137. Print("Suddenly, you get startled but only by a fluffy little bunny, it seems innocent at first until it warps right in front of you in a beast only the darkesat mind could conjour, your worst nightmare. Brought upon yourself by your own imagination");
  138. fight("nightmare");
  139.  
  140.  
  141. }
  142.  
  143.  
  144.  
  145. public static void dialogTraver(){
  146. if(randomRoll()==1){
  147.  
  148. Print("The traveler was evil!");
  149. fight("basicLV2");
  150.  
  151. }
  152. else{ Print("turns out the man is just a normal everyday hiker out on a stroll!");}
  153.  
  154.  
  155. }
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166. ////FIGHT SCENES////
  167. public static void firstFight(){
  168. boolean fighting = true;
  169. EnemyIndex("basic");
  170. Scanner typing = new Scanner(System.in);
  171. while(fighting==true){
  172. if(Enemyhealth<0){fighting = false; Print("you won!");}
  173. if(Phealth<0){ Print("You Died! Ressurecting..."); Ressurect();}
  174. Print("Strike(S),Dodge(D),Check Health(C), or Use Item(U)?");
  175. String Ans = typing.nextLine();
  176. if(Ans.equalsIgnoreCase("S")){if(randomCrits()==1){Enemyhealth = Enemyhealth-(Pdamage*Pcrit);}else if(randomCrits()==2){}else if(randomCrits()==3){Enemyhealth = (Enemyhealth-Pdamage);Print("> The Enemy was damaged: " + Pdamage);}}
  177. else if(Ans.equalsIgnoreCase("C")){checkHealth();}
  178. else if(Ans.equalsIgnoreCase("u")){useItems();}
  179. else{ if(randomRoll()==1){Print("> No Damage Taken");}else{Print("> Player Took " + damage + " Damage!"); Phealth = (Phealth - damage);}
  180. if(Enemyhealth<0){fighting = false; Print("> You won!");}
  181. }
  182.  
  183. }
  184.  
  185.  
  186. }
  187.  
  188. public static void fightIntroMechanics(){
  189. boolean fighting = true;
  190. EnemyIndex("boss1");
  191. Scanner typing = new Scanner(System.in);
  192. while(fighting==true){
  193. if(Enemyhealth<0){fighting = false; Print("you won!");}
  194. if(Phealth<0){ Print("You Died! Ressurecting..."); Ressurect();}
  195. Print("Strike(S),Dodge(D),Check Health(C), or Use Item(U)?");
  196. String Ans = typing.nextLine();
  197. if(Ans.equalsIgnoreCase("S")){if(randomCrits()==1){Enemyhealth = Enemyhealth-(Pdamage*Pcrit);}else if(randomCrits()==2){}else if(randomCrits()==3){Enemyhealth = (Enemyhealth-Pdamage);Print("> The Enemy was damaged: " + Pdamage);}}
  198. else if(Ans.equalsIgnoreCase("C")){checkHealth();}
  199. else if(Ans.equalsIgnoreCase("u")){useItems();}
  200. else{ if(randomRoll()==1){Print("> No Damage Taken");}else{Print("> Player Took " + damage + " Damage!"); Phealth = (Phealth - damage);}
  201. if(Enemyhealth<0){fighting = false; Print("> You won!");}
  202. }
  203.  
  204. }
  205.  
  206.  
  207. }
  208. public static void fight(String enemyIndexType){
  209. boolean fighting = true;
  210. EnemyIndex(enemyIndexType);
  211. Scanner typing = new Scanner(System.in);
  212. while(fighting==true){
  213. if(Enemyhealth<0){fighting = false; Print("you won!");}
  214. if(Phealth<0){ Print("You Died! Ressurecting..."); Ressurect();}
  215. Print("Strike(S),Dodge(D),Check Health(C), or Use Item(U)?");
  216. String Ans = typing.nextLine();
  217. if(Ans.equalsIgnoreCase("hhh")){Print("Pdamage: " + Pdamage + ", Pspeed: " + Pspeed + ", Pcrit: " + Pcrit);}
  218. else if(Ans.equalsIgnoreCase("S")){if(randomCrits()==1){Enemyhealth = Enemyhealth-(Pdamage*Pcrit);}else if(randomCrits()==2){}else if(randomCrits()==3){Enemyhealth = (Enemyhealth-Pdamage);Print("> The Enemy was damaged: " + Pdamage);}if(Enemyhealth<0){fighting = false; Print("> You won!");}}
  219. else if(Ans.equalsIgnoreCase("C")){checkHealth();}
  220. else if(Ans.equalsIgnoreCase("u")){useItems();}
  221. else{ if(randomRoll()==1){Print("> No Damage Taken");}else{Print("> Player Took " + damage + " Damage!"); Phealth = (Phealth - damage);}
  222. if(Enemyhealth<1){fighting = false; Print("you won!");}
  223. }
  224.  
  225. }
  226. }
  227. ////END OF FIGHT SCENES////
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234. ////BASIC MECHANICS////
  235. public static void useItems(){
  236. Scanner typing = new Scanner(System.in);
  237. System.out.println("> Which item: "); System.out.println("Healthpack(" + its.healthPackAmount + ") Grendade("+ its.grenades + ")"); String anse = typing.nextLine(); if(anse.equalsIgnoreCase("healthpack")){ its.useHealthPack();} else if(anse.equalsIgnoreCase("Grenade")){Items.UseGrenade();}
  238. }
  239. //}
  240.  
  241. public static void Ressurect(){
  242.  
  243. System.out.println("Gathering life shards...");
  244. System.out.println("Extracting life force from goat...");
  245. System.out.println("Reconstructing soul, and inserting life force...");
  246. System.out.println("Inserting life into beggining of fight!");
  247. Phealth = 120;
  248. }
  249. public static void checkHealth(){
  250. //Scanner typing = new Scanner(System.in);
  251. //System.out.println("Check health? Y/N");
  252. //String healthCheck = typing.nextLine();
  253. //if(healthCheck.equalsIgnoreCase("Y")){
  254. Print("Your health is: " + Phealth);
  255. Print("Your enemie's health is: " + Enemyhealth);
  256. //}
  257. //else{}
  258.  
  259. }
  260.  
  261. public static int randomCrits(){
  262. int secRan = Phealth/22+((Pspeed/100)*Phealth);
  263. int raN = ThreadLocalRandom.current().nextInt(1, 8 + 1);
  264. int critDamage = Pcrit+Pdamage;
  265. if((Pcrit*raN)+secRan >= 115){System.out.println("> CRIT! " + critDamage + " damage done!"); return 1;}
  266. if((Pcrit*raN)+secRan < 30){System.out.println("> You got hit! You took " + damage + " amount of damage!");Phealth = Phealth-damage;return 2;}
  267. else{return 3;}
  268. }
  269. public static int randomRoll(){
  270. int raN = ThreadLocalRandom.current().nextInt(1, 11 + 1);
  271. int rollChance = (int)raN*Pspeed;
  272. if(rollChance>130){return 1;}
  273. else{return 2;}
  274.  
  275. }
  276. ////END OF BASIC MECHANICS////
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288. ////INDEX SECTION////
  289. public static void EnemyIndex(String EnemyType){
  290. if(EnemyType.equalsIgnoreCase("basic")){
  291. int raN = ThreadLocalRandom.current().nextInt(2, 6 + 1);
  292. damage = Pdamage*(raN*1);
  293. speed = Pspeed*(raN*1);
  294. crit = Pcrit*(raN*1);
  295. Enemyhealth = 120;
  296. }
  297. else if(EnemyType.equalsIgnoreCase("boss1")){
  298. int raN = ThreadLocalRandom.current().nextInt(2, 7 + 1);
  299. damage = Pdamage*(raN*1);
  300. speed = Pspeed*(raN*1);
  301. crit = Pcrit*(raN*1);
  302. Enemyhealth = 320;
  303.  
  304. }
  305. else if(EnemyType.equalsIgnoreCase("basicLV2")){
  306.  
  307. int raN = ThreadLocalRandom.current().nextInt(2, 6 + 1);
  308. damage = Pdamage*(raN*2);
  309. speed = Pspeed*(raN*2);
  310. crit = Pcrit*(raN*2);
  311. Enemyhealth = 200;
  312.  
  313. }
  314. else if(EnemyType.equalsIgnoreCase("nightmare")){
  315.  
  316. int raN = ThreadLocalRandom.current().nextInt(4, 7 + 1);
  317.  
  318. //Should be equal to players stats + some//
  319.  
  320. damage = Pdamage + (2*raN);
  321. speed = Pspeed + (2 + raN);
  322. crit = Pcrit + (2 + raN);
  323. Enemyhealth = Phealth + (Phealth/raN);
  324.  
  325. }
  326. }
  327.  
  328.  
  329.  
  330. public static void WeaponIndex(){
  331. int raN = ThreadLocalRandom.current().nextInt(2, 6 + 1);
  332. //AXE//
  333. axeDamage = 9*raN;
  334. axeSpeed = 2*raN;
  335. axeCritChance = 4*raN;
  336. axePhrase = "You Have wielded the trusty axe, its very nslow but sure to pack a huge punch!";
  337. //BOW/
  338. bowDamage = 6*raN;
  339. bowSpeed = 5*raN;
  340. bowCritChance = 3*raN;
  341. bowPhrase = "The Trust bow, besat for great accuracy but a bit lacking in damage, overall a great choice in any archers hands";
  342. //FISTS//
  343. fistDamage = 2*raN;
  344. fistSpeed = 9*raN;
  345. fistCritChance = 2*raN;
  346. fistPhrase = "Your good ole' hands, the thing you know best. although they cant pack a lot of damage, they make up in speed!";
  347. }
  348. ////END OF INDEX SECTION////
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368. ////PRINT SECTION////
  369. public static void Print(String s){
  370.  
  371. //System.out.println("");
  372. System.out.println("> "+s);
  373. //System.out.println("");
  374.  
  375. }
  376.  
  377. public static void PrintExclam(String s){
  378.  
  379. //System.out.println("");
  380. System.out.println(">>>>>>>"+" " + s + " " +"<<<<<<");
  381. }
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423. //(IN CASE I WANT KEY LISTENER)//
  424. /*public void keyTyped(KeyEvent e){int key = e.getKeyCode();
  425.  
  426.  
  427. if(key = KeyEvent.
  428.  
  429. }
  430. public void keyPressed(KeyEvent e){}
  431. public void keyReleased(KeyEvent e){}*/
  432. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement