Advertisement
Guest User

Untitled

a guest
May 24th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.05 KB | None | 0 0
  1. package com.company;
  2.  
  3. /**Programmer:Victoria Gao
  4. *
  5. *Class: ICS3U1
  6. *
  7. *Culminating activity: Game
  8. **/
  9. import java.io.*;
  10. import java.util.*;
  11. class Main
  12. {
  13.  
  14. public static void start () //Start to first village
  15. {
  16. try
  17. {
  18. Scanner s = new Scanner(System.in);
  19. FileWriter fr = new FileWriter ("player.txt");
  20. PrintWriter pw = new PrintWriter (fr);
  21. System.out.println ("You find yourself lying in the middle of a forest, foliage as far as the eye can see." +
  22. " The Wishstone... It's all you can remember. The treasure with the power to grant your deepest desire." +
  23. "A name surfaces from your memory: this is what people know you as.");
  24. String name = s.next (); //Get player's name
  25. System.out.println ("Your name is " + name + ". Is this correct? Press 'N' to retype.");
  26. String confirm = s.next ();
  27. while (confirm.equals("n") || confirm.equals("N")) //Confirm name
  28. {
  29. clr ();
  30. System.out.println ("A name surfaces from your memory: this is what people know you as.");
  31. name = s.next ();
  32. System.out.println ("Your name is " + name + ". Is this correct? Y/N");
  33. confirm = s.next ();
  34. }
  35. pw.println ('1' + name); //Writes name to player file
  36. System.out.println ("You crawl to a nearby pond and peer in. You don't recognize your features, \nbut at a glance your features speak of:" + //Race selection
  37. "\n1. Human - A basic species that may seem ordinary when compared to others but possess the potential to become so much more. " +
  38. "This potential is their greatest strength. Their curiosity allows them to be highly adaptable. " +
  39. "Their unyielding spirit and strong lifeforce make a difficult enemy but a valuable friend." +
  40. "\n2. Dwarf - As exceptional engineers and artisans, Dwarves can create nearly anything as long as they have the right materials for the job. " +
  41. "They grow beards starting from age 17 and decorate them with pieces of metal to serve as reminders of milestones and accomplishments. " +
  42. "They are resistant to the heart of their forces and can carry several times their own weight. " +
  43. "Rarely, one is born among them with the ability to bend metal to their will. " +
  44. "\n3. Harpy - Skilled archers with wings and/or arms. They may also have beaks in place of mouths but typically have a human torso." +
  45. " Their hollow skeletons make them faster and lighter that they seem, and they are able to shoot you full of feathers. " +
  46. "Their feet are like second hands and are immune to disease and the effects of high altitude. " +
  47. "\n4. Griffyn - A regal and religious species with a lion’s legs and an eagle's wings. They follow a strict code of honor and will not strike a weaponless foe." +
  48. " Their eyes are as sharp as an eagle's and their strength can carry twice their weight even in flight. Their noble roar strikes fear and awe in all who hear it. " +
  49. "They are immune to changes in air quality. Male Gryffins follow Leonius, valiant Lion God of protection and strength and pride and honor. " +
  50. "They believe that Leonius favors those who fight for protection of his people and others. Female Griffyns follow Avania, Leonius’ mate. " +
  51. "She is known as the Avian Goddess of insight and healing and guidance and spirit. They believe that Avania favors those who care for the wounded. " +
  52. "It is through these two deities that the Griffyns believe they were born. ");
  53. int species = s.nextInt ();
  54. if (species == 1) //Writes selected species to player file. This influences how NPCs interact with them.
  55. pw.println ("2 Human");
  56. if (species == 2)
  57. pw.println ("2 Dwarf");
  58. if (species == 3)
  59. pw.println ("2 Harpy");
  60. if (species == 4)
  61. pw.println ("2 Griffyn");
  62. System.out.println ("You're carrying a weapon:" + //Class(buff) selection
  63. "\n1. Sword(Warrior) - Strong and heavy-hitting. They're the front lines of any \narmy." +
  64. "\n2. Bow(Hunter) - Swift and sure. They're skilled at archery." +
  65. "\n3. Staff(Sorcerer) - Smart and powerful. They use the power of magic to fight" +
  66. "\n4. Daggers(Rogue) - Stealthy and agile. They're hard to hit and strike \naccurately.");
  67. int specialty = s.nextInt ();
  68. if (specialty == 1) //Writes class to player file, along with their stats.
  69. {
  70. pw.println ("3 Warrior");
  71. pw.println ("150 HP");
  72. pw.println ("5 DEF");
  73. pw.println ("4 ATK");
  74. pw.println ("1 INT");
  75. pw.println ("2 AGL");
  76. pw.println ("3 PRE");
  77. invAdd ();
  78. invEdit ("0", 1);
  79. }
  80. if (specialty == 2)
  81. {
  82. pw.println ("3 Hunter");
  83. pw.println ("120 HP");
  84. pw.println ("2 DEF");
  85. pw.println ("3 ATK");
  86. pw.println ("3 INT");
  87. pw.println ("5 AGL");
  88. pw.println ("6 PRE");
  89. invEdit ("5", 1);
  90. }
  91. if (specialty == 3)
  92. {
  93. pw.println ("3 Sorcerer");
  94. pw.println ("80 HP");
  95. pw.println ("1 DEF");
  96. pw.println ("4 ATK");
  97. pw.println ("6 INT");
  98. pw.println ("3 AGL");
  99. pw.println ("2 PRE");
  100. invEdit ("10", 1);
  101. }
  102. if (specialty == 4)
  103. {
  104. pw.println ("3 Rogue");
  105. pw.println ("100 HP");
  106. pw.println ("2 DEF");
  107. pw.println ("2 ATK");
  108. pw.println ("3 INT");
  109. pw.println ("6 AGL");
  110. pw.println ("5 PRE");
  111. invEdit ("15", 1);
  112. }
  113. System.out.println ("Cupping your hands, you lift water to your mouth and struggle to stand up. \nA cloth bag leans against a nearby tree. \n1. Look in the bag.\n2. Leave it.");
  114. int bag = s.nextInt ();
  115. if (bag == 1)
  116. {
  117. System.out.println ("There's an unlit torch. There are five glowing shards that hurt your eyes when \nyou look at them. " +
  118. "A name for them makes its way into your head: Soul shards. \nPerhaps when you have enough of them you can use them for something...");
  119. pw.println ("Torch x1");
  120. pw.println ("Soul Shard x5");
  121. }
  122. if (bag == 2)
  123. {
  124. System.out.println ("You reconsider. What's in that bag may be the difference beteen life and death..." +
  125. "\n1. Look in the bag.\n2. Leave.");
  126. bag = s.nextInt ();
  127. if (bag == 1)
  128. {
  129. System.out.println ("There's an unlit torch. There are five glowing shards that hurt you eyes when you look at them. " +
  130. "A name for them makes its way into your head: Soul shards. Perhaps when you have enough of them you can use them for something...");
  131. pw.println ("Torch 1");
  132. pw.println ("Soul Shard 5");
  133. }
  134. if (bag == 2)
  135. System.out.println ("You weigh your options and decide it isn't worth it to look inside. It could be a trap.\n>Continue...");
  136. try{
  137. Thread.sleep(500);
  138. }
  139. catch (Exception e){}
  140. }
  141. System.out.println ("You hear noises nearby, perhaps the sound of a small mammal enjoying its food. \nIt would make a good meal for later." +
  142. "\n1. Fight\n2. Spare it");
  143. int critter1 = s.nextInt ();
  144. if (critter1 == 1)
  145. {
  146. System.out.println ("You try to sneak up on it from behind, but it notices you.");
  147. critterFight (1);
  148. }
  149. if (critter1 == 2)
  150. {
  151. double chance = roll (5);
  152. if (chance == 1)
  153. {
  154. System.out.println ("The critter hears you walking and jumps at you, angry that you disturbed its meal.");
  155. critterFight (1);
  156. }
  157. else
  158. {
  159. System.out.println ("The critter hears you walking and runs away, chittering as it does so.");
  160. }
  161. }
  162. String noise[] = {
  163. "screech",
  164. "scream",
  165. "howl",
  166. "roar"
  167. };
  168. String object[] = {
  169. "tree",
  170. "bush",
  171. "rock",
  172. "patch of grass",
  173. "burrow",
  174. };
  175. String adj[] = {
  176. "rickety old",
  177. "sketchy",
  178. "flimsy-looking",
  179. "dilapidated"
  180. };
  181. int sound;
  182. int thing;
  183. int desc;
  184. for (int i = 0 ; i < 5 ; i++)
  185. {
  186. double rand = roll (6);
  187. if (rand == 1)
  188. {
  189. sound = (int) roll (3);
  190. thing = (int) roll (4);
  191. System.out.println ("You stumble along what you think is a path. A loud " + noise [sound] + " can be heard from a nearby " + object [thing]);
  192. }
  193. if (rand == 2)
  194. {
  195. sound = (int) roll (3);
  196. System.out.println ("A piercing " + noise [sound] + " gives you a mini heart-attack. You being to walk faster, hoping that you never meet whatever made that sound.");
  197. }
  198. if (rand == 3)
  199. {
  200. thing = (int) roll (4);
  201. System.out.println ("Something leaps at you from a " + object [thing]);
  202. }
  203. if (rand == 4)
  204. {
  205. System.out.println ("You see something moving in the distance.");
  206. }
  207. if (rand == 5)
  208. {
  209. System.out.println ("The 'path' you've been following suddenly ends. Oh, look. Something has been waiting for you at the end.");
  210. }
  211. if (rand == 6)
  212. {
  213. desc = (int) roll (3);
  214. System.out.println ("You cross a " + adj [desc] + " bridge. It sways with each step, which is totally not scary...");
  215. }
  216. }
  217. System.out.println ("There's a village up ahead. You can't remember much about it.");
  218. double vilType = roll (4);
  219. pw.close ();
  220. village (vilType);
  221. paths ();
  222. }
  223. catch (java.io.IOException e)
  224. {
  225. }
  226. }
  227.  
  228.  
  229. public static void paths ()
  230. {
  231. System.out.println ("Arc 2: The Journey");
  232. }
  233.  
  234.  
  235. public static void village (double vilType)
  236. {
  237.  
  238. Scanner s = new Scanner (System.in);
  239. int choose1;
  240. int choose2;
  241. if (vilType == 1)
  242. {
  243. System.out.println ("As you get closer, the sounds of a blacksmith can be heard, loud metallic banging resonating through the air. You can buy equipment here.");
  244. System.out.println ("1. Shop\n2. Leave");
  245. choose1 = s.nextInt ();
  246. if (choose1 == 1)
  247. {
  248. clr();
  249. //insert blacksmith shop graphic/anim
  250. System.out.println("\"Welcome to my shop!\"");
  251. System.out.println("You see various deadly objects scattered around his shop. They can be sorted into three categories.");
  252. System.out.println("1. Armor\n2. Weapons\n3. Consumables");
  253. choose2 = s.nextInt();
  254. if (choose2 == 1)
  255. {
  256. System.out.println("\"Ah, yes. A good choice.\"");
  257. System.out.println("There is one set of armor available.");
  258. System.out.println("1. Leather Armor ()");
  259. }
  260. if (choose2 == 2)
  261. {
  262. System.out.println("\"My weapons are of highest quality.\"");
  263. System.out.println("There are four weapons available.");
  264. System.out.println("1. Decent Sword");
  265. System.out.println("1. Decent Staff");
  266. System.out.println("1. Decent Bow");
  267. System.out.println("1. Decent Daggers");
  268. }
  269. if (choose2 == 3)
  270. {
  271.  
  272. }
  273. }
  274. if (choose1 == 2)
  275. {
  276.  
  277. }
  278. }
  279. if (vilType == 2)
  280. {
  281. System.out.println ("The village is lively, the aroma of delectable food in the air. Merchants display their fresh produce in front of their stores. You can fill up on food here.");
  282. System.out.println ("1. Shop\n2. Leave");
  283. choose1 = s.nextInt ();
  284. if (choose1 == 1)
  285. {
  286.  
  287. }
  288. if (choose1 == 2)
  289. {
  290.  
  291. }
  292. }
  293. if (vilType == 3)
  294. {
  295. System.out.println ("There is magic all around you. Children run around chasing each other with flames in their hands. You can buy potions here.");
  296. System.out.println ("1. Shop\n2. Leave");
  297. choose1 = s.nextInt ();
  298. if (choose1 == 1)
  299. {
  300.  
  301. }
  302. if (choose1 == 2)
  303. {
  304.  
  305. }
  306. }
  307. if (vilType == 4)
  308. {
  309. System.out.println ("No one is here. Objects lay scattered around. Loot here is plentiful but so are the monsters.");
  310. System.out.println ("1. Explore\n2. Leave");
  311. choose1 = s.nextInt ();
  312. if (choose1 == 1)
  313. {
  314.  
  315. }
  316. if (choose1 == 2)
  317. {
  318.  
  319. }
  320. }
  321. return;
  322. }
  323.  
  324.  
  325. public static double roll (int face)
  326. {
  327. return Math.floor (Math.random () * face) + 1;
  328. }
  329.  
  330.  
  331. public static void critterFight (int num)
  332. {
  333. //FileReader fr = new FileReader ("");
  334. }
  335.  
  336.  
  337. public static void monsterFight (int num)
  338. {
  339.  
  340. }
  341.  
  342. public static void bossFight (int num)
  343. {
  344.  
  345. }
  346.  
  347. public static void invAdd ()
  348. {
  349. try
  350. {
  351. FileWriter fw = new FileWriter ("inventory.txt");
  352. PrintWriter pw = new PrintWriter (fw);
  353. for (int i = 0 ; i < 72 ; i++)
  354. {
  355. pw.println (i + ", 0");
  356. }
  357. pw.close ();
  358. }
  359. catch (java.io.IOException e)
  360. {
  361. }
  362. }
  363.  
  364.  
  365. public static void invEdit (String itemID, int quantity)
  366. {
  367. try
  368. {
  369. FileReader fr = new FileReader ("inventory.txt");
  370. FileWriter fw = new FileWriter ("inventory.txt");
  371. BufferedReader br = new BufferedReader (fr);
  372. PrintWriter pw = new PrintWriter (fw);
  373. for (int i = 0 ; i < 72 ; i++)
  374. {
  375. String item = br.readLine (); //reads next line
  376. String itemarray[] = item.split (", "); //separates itemid and quantity
  377. if (itemID.equals (itemarray [0])) // if the itemid = item added
  378. {
  379. itemarray [1] += quantity; //add # to quantity
  380. pw.println(i + ", " + itemarray [1]);
  381. }
  382. else{
  383. pw.println(item);
  384. }
  385. }
  386. }
  387. catch (java.io.IOException e)
  388. {
  389. }
  390. }
  391.  
  392. public static void clr (){
  393. System.out.println("--------------------------------------------------------------------------------");
  394. }
  395.  
  396.  
  397. public static void main (String[] args)
  398. {
  399. Scanner s = new Scanner (System.in);
  400. System.out.println ("********************************************************************************");
  401. System.out.println ("* *");
  402. System.out.println ("* The Last Wish *");
  403. System.out.println ("* ~ *");
  404. System.out.println ("* A Text-Based RPG *");
  405. System.out.println ("* *");
  406. System.out.println ("********************************************************************************");
  407. System.out.println ("\n 1. Start Game 2.Exit Game \n");
  408. int sel = s.nextInt ();
  409. do
  410. {
  411. if (sel == 1)
  412. {
  413. clr();
  414. start ();
  415. }
  416. if (sel == 2)
  417. System.exit (0);
  418. else
  419. {
  420. System.out.println ("Invalid selection. Please select either 1 or 2.");
  421. sel = s.nextInt ();
  422. }
  423. }
  424. while (sel != 1 && sel != 2);
  425.  
  426. }
  427.  
  428.  
  429. /*Pseudocode
  430. - Fighting method
  431. - Loot method
  432. - Storing character info method
  433. - Method for each arc
  434. Assets
  435. - Monster select
  436. - Player files
  437. */
  438.  
  439.  
  440.  
  441. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement