Advertisement
Guest User

MenuLibrary class

a guest
Dec 8th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.70 KB | None | 0 0
  1. package com.tutorial.main;
  2.  
  3. import java.awt.FontFormatException;
  4. import java.io.File;
  5. import java.io.IOException;
  6. import java.util.Random;
  7.  
  8. import javax.sound.sampled.AudioInputStream;
  9. import javax.sound.sampled.AudioSystem;
  10. import javax.sound.sampled.Clip;
  11. import javax.sound.sampled.LineUnavailableException;
  12. import javax.sound.sampled.UnsupportedAudioFileException;
  13.  
  14. //One instance of this class will be made. That class will have as variables...every piece of menu data, for easy,
  15. //object oriented retrieval. Yes.
  16. public class MenuLibrary {
  17. public Menu resultMenu;
  18.  
  19. AudioInputStream stream;
  20. Clip clip;
  21. BackGroundSound cityNoise;
  22. File filePathSound = new File("").getAbsoluteFile();
  23.  
  24. public MoneyEffect moneyEffectML;
  25. private Random r;
  26. private String invTitle = "Inventory";
  27. private String invPrompt = "";
  28. private String[][] invOptions = {};
  29. private ChoiceProcessorInterface invProcessor;
  30. //private ID inventoryMenuType = ID.InventoryMenu;
  31. public MenuDataArchive invArchive;
  32.  
  33. private String mainMenuPrompt = ""; //this is replaced by the logo image
  34. private String[][] mainMenuOptions = {
  35. {"Begin", "mainMenuBegin"},
  36. {"Instructions", "mainMenuInstructions"},
  37. {"Quit", "mainMenuQuit"} };
  38. private ChoiceProcessorInterface mainMenuProcessor;
  39. public MenuDataArchive mainMenuArchive;
  40.  
  41. private String creditDeniedPrompt = "You swipe your credit card and the register flashes \"DENIED\". " +
  42. " Looks like you won't be buying anything today.";
  43. private String[][] creditDeniedOptions = { {"Okay", "leave"} };
  44. private ChoiceProcessorInterface creditDeniedProcessor;
  45. public MenuDataArchive creditDeniedArchive;
  46.  
  47. private String burgerTitle = "McSpanky's Burgers";
  48. private String burgerPrompt = "It smells like fast food and grease in here. But it's cheap, and they're hiring.";
  49. private String[][] burgerOptions = { {"Buy a Meal ($4.99)", "buyBurgerFood"},
  50. {"Apply for a Job", "applyBurgerJob"},
  51. {"Leave", "leaveBurger"} };
  52. private ChoiceProcessorInterface burgerProcessor;
  53. public MenuDataArchive burgerArchive;
  54.  
  55. private String burger0Prompt = "The fast food isn't very filling.";
  56. private String[][] burger0Options = { {"Okay", "burger0Leave"} };
  57. private ChoiceProcessorInterface burger0Processor;
  58. public MenuDataArchive burger0Archive;
  59.  
  60. private String burger1Prompt = "After an interview with the manager, you're handed your schedule for the first week."
  61. + " Not exactly convenient, but you suppose you can make time. (9-5 on weekdays)";
  62. private String[][] burger1Options = { {"Happy to McServe you, sir.", "startBurgerJob"} };
  63. private ChoiceProcessorInterface burger1Processor;
  64. public MenuDataArchive burger1Archive;
  65.  
  66. private String burger2Title = "Welcome McWorker!";
  67. private String burger2Prompt = "Make sure you sign in at your assigned shift time, 9-5 on weekdays";
  68. private String[][] burger2Options = { {"Sign in to shift", "signIn"}, {"Buy a Meal ($3.50 with employee discount)", "buyBurgerFood"},
  69. {"Quit Job", "quit"}, {"Exit Menu", "burger2Leave"}};
  70. private ChoiceProcessorInterface burger2Processor;
  71. public MenuDataArchive burger2Archive;
  72.  
  73. private String burgerSignOut = "Good job finishing your shift! Your wallet is happy but your health certainly isn't";
  74. private String[][] burgerSOOptions = { {"Exit", "exitBurger"} };
  75. private ChoiceProcessorInterface burgerSOProcessor;
  76. public MenuDataArchive burgerSOArchive;
  77.  
  78. private String burgerOffTitle = "Off-shift menu";
  79. private String burgerOffPrompt = "You're off your shift! Use your employee discount to buy a burger";
  80. private String[][] burgerOffOptions = { {"Buy a Meal ($3.50)", "buyBurgerFood"}, {"Quit Job", "quitBurgerJob"}, {"Okay", "burgerOffLeave"}};
  81. private ChoiceProcessorInterface burgerOffProcessor;
  82. public MenuDataArchive burgerOffArchive;
  83.  
  84. private String burgerFiredTitle = "McSpanky's Burgers";
  85. private String burgerFPrompt = "It smells like fast food and grease in here. But it's cheap. You cannot work for a place that you've been fired from";
  86. private String[][] burgerFOptions = { {"Buy a Meal ($4.99)", "buyBurgerFood"},
  87. {"Leave", "leaveBurger"} };
  88. private ChoiceProcessorInterface burgerFProcessor;
  89. public MenuDataArchive burgerFArchive;
  90.  
  91. private String apartmentPrompt = "It's your apartment.";
  92. private String[][] apartmentOptions = { {"Sleep", "sleepApartment"}, {"Leave", "leave"} };
  93. private ChoiceProcessorInterface apartmentProcessor;
  94. public MenuDataArchive apartmentTopArchive;
  95.  
  96. public static SleepEffect sleepEffect;
  97.  
  98. private String apartmentTitle = "Your Apartment";
  99. private String apartment0Prompt = "You wake up, feeling not quite as rested as you'd like.";
  100. private String[][] apartment0Options = { {"Leave apartment", "leave"} };
  101. private ChoiceProcessorInterface apartment0Processor;
  102. public MenuDataArchive apartment0Archive;
  103. //apartment logic variables
  104. private int nextMorning;
  105. private int timeSlept;
  106.  
  107. public MenuDataArchive apartmentArchive;
  108. private String collegeTitle = "S.U. Community College";
  109. private String collegePrompt = "The local University's admissions office. They have pamphlets that detail the costs of "
  110. + "attendance. It will not be cheap.";
  111. private String[][] collegeOptions = { {"Pay Tuition($10,000)", "payTuition"}, {"Leave", "leave"} };
  112. private ChoiceProcessorInterface collegeProcessor;
  113. public MenuDataArchive collegeArchive;
  114.  
  115. private String college0Prompt = "As you sign the paperwork, you feel hope for the first time in a long time. You believe"
  116. + " things are going to get better.";
  117. private String[][] college0Options = { {"Thanks for Playing!", "leave"} };
  118. private ChoiceProcessorInterface college0Processor;
  119. public MenuDataArchive college0Archive;
  120.  
  121. private String walmartTitle = "Wolmart";
  122. private String walmartPrompt = "The hum of fluorescent light bulbs and off white paint tone are the first things you"
  123. + " notice as you walk in, but they fade into the background as you browse the aisles.";
  124. private String[][] walmartOptions = {
  125. {"Buy 1 day of groceries ($10)", "buy1Grocery"},
  126. {"Buy 7 days of groceries ($40)", "buy7Grocery"},
  127. {"Buy a Bike", "buyBike"},
  128. {"Leave", "leave"}
  129. };
  130.  
  131. private ChoiceProcessorInterface walmartProcessor;
  132. public MenuDataArchive walmartArchive;
  133.  
  134. private String hospitalTitle = "M.D. Anderson Clinic";
  135. private String hospitalPrompt = "It's the hospital reception room.";
  136. private String[][] hospitalOptions = { {"Check Up ($500/2 Hours)", "checkUp"}, {"Leave", "leave"} };
  137. private ChoiceProcessorInterface hospitalProcessor;
  138. public MenuDataArchive hospitalArchive;
  139.  
  140. private String hospital0Prompt = "You feel much better after your checkup.";
  141. private String[][] hospital0Options = { {"Leave", "leave"} };
  142. private ChoiceProcessorInterface hospital0Processor;
  143. public MenuDataArchive hospital0Archive;
  144.  
  145. private String eventFindMoneyPrompt = "You find a few coins on the ground.";
  146. private String[][] eventFindMoneyOptions = { {"How Lucky!", "leave"} };
  147. private ChoiceProcessorInterface eventFindMoneyProcessor;
  148. public MenuDataArchive eventFindMoneyArchive;
  149.  
  150. private String eventCollapsePrompt = "You feel really tired. Really tired. You're going to lay down for a second. Just a quick second.";
  151. private String[][] eventCollapseOptions = { {"A quick rest...", "collapse"} };
  152. private ChoiceProcessorInterface eventCollapseProcessor;
  153. public MenuDataArchive eventCollapseArchive;
  154.  
  155. private String eventCollapse0Prompt = "Your whole body is stiff. You fell asleep outside. And didn't you have more money on you yesterday?";
  156. private String[][] eventCollapse0Options = { {"Try to get more sleep next time.", "leave"} };
  157. private ChoiceProcessorInterface eventCollapse0Processor;
  158. public MenuDataArchive eventCollapse0Archive;
  159.  
  160. private String eventCollapse0NoMoneyPrompt = "Your whole body is stiff. You fell asleep outside.";
  161. private String[][] eventCollapse0NoMoneyOptions = { {"Try to get more sleep next time.", "leave"} };
  162. private ChoiceProcessorInterface eventCollapse0NoMoneyProcessor;
  163. public MenuDataArchive eventCollapse0NoMoneyArchive;
  164.  
  165. private String eventStrikesPrompt = "Oops! You're late to work (2 hrs past shift start). You recieved a strike!"
  166. + "You get 3 strikes at a job before you will be fired! Be careful!";
  167. private String[][] eventStrikesOptions = { {"Understood", "exitStrikes"} };
  168. private ChoiceProcessorInterface eventStrikesProcessor;
  169. public MenuDataArchive eventStrikesArchive;
  170.  
  171. private String kickedOutPrompt = "As soon as you walk in, you're practically chased out by an employee. They make a rude comment about the state"
  172. + " of your clothes before shutting the door in your face.";
  173. private String[][] kickedOutOptions = { {"Leave", "leave"} };
  174. private ChoiceProcessorInterface kickedOutProcessor;
  175. public MenuDataArchive kickedOutArchive;
  176.  
  177. MenuLibrary() {
  178. r = new Random();
  179.  
  180. this.invArchive = new MenuDataArchive(invPrompt, invOptions, invProcessor, ID.InventoryMenu, invTitle);
  181. this.mainMenuProcessor = (String choiceIDPr) -> {
  182. System.out.println("choice ID = " + choiceIDPr);
  183. switch (choiceIDPr) {
  184. case "mainMenuBegin":
  185. try {
  186. Game.thisGame.gameMapSetup();
  187. } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
  188. // TODO Auto-generated catch block
  189. e.printStackTrace();
  190. }
  191. Game.mainMenuOpen = false;
  192. Game.gameState = Game.STATES.Playing;
  193. Game.handler.removeObject(Game.mainMenu);
  194. Game.thisGame.removeKeyListener(Game.mainMenu);
  195. HUD.hungerFullnessDelayedX = 200;
  196.  
  197. try {
  198. stream = AudioSystem.getAudioInputStream(PlayerInput.class.getResource("cityAmbience.wav"));
  199. clip = AudioSystem.getClip();
  200.  
  201. cityNoise = new BackGroundSound((long) 0.0, clip, "?", stream, filePathSound);
  202.  
  203. cityNoise.play();
  204. } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e1) {
  205. // TODO Auto-generated catch block
  206. e1.printStackTrace();
  207. }
  208.  
  209. break;
  210. case "mainMenuInstructions":
  211. System.out.println("GAME INSTRUCTIONS DEBUG");
  212. break;
  213. case "mainMenuQuit":
  214. System.out.println("GAME QUIT DEBUG");
  215. System.exit(1);
  216. break;
  217. }
  218. };
  219.  
  220. mainMenuArchive = new MenuDataArchive(mainMenuPrompt, mainMenuOptions, mainMenuProcessor, ID.MainMenu, null);
  221.  
  222. this.creditDeniedProcessor = (String choiceIDPr) -> {
  223. switch (choiceIDPr) {
  224. case "leave":
  225. closeResultMenu();
  226. break;
  227. }
  228. };
  229.  
  230. creditDeniedArchive = new MenuDataArchive(creditDeniedPrompt, creditDeniedOptions, creditDeniedProcessor, ID.ResultMenu, null);
  231. //=====================================================================================================================
  232.  
  233. this.burgerProcessor = (String choiceIDPr) -> {
  234. switch (choiceIDPr) {
  235. case "buyBurgerFood" :
  236. if (Finance.tryBuy(4.99)) {
  237. try {
  238. resultMenu = new Menu(burger0Archive);
  239. } catch (FontFormatException | IOException e) {
  240. // TODO Auto-generated catch block
  241. e.printStackTrace();
  242. }
  243. makeResultMenu();
  244. closeOldMenu();
  245. HUD.hunger += 10;
  246. } else {
  247. //play sound
  248. System.out.println("No money.");
  249. }
  250.  
  251. break;
  252. case "applyBurgerJob" :
  253. try {
  254. resultMenu = new Menu(burger1Archive);
  255.  
  256. } catch (FontFormatException | IOException e) {
  257. e.printStackTrace();
  258. }
  259. makeResultMenu();
  260. closeOldMenu();
  261. break;
  262. case "leaveBurger" :
  263. closeOldMenu();
  264. closeResultMenu();
  265. break;
  266. }
  267. };
  268.  
  269. this.burger0Processor = (String choiceIDPr) -> {
  270. switch (choiceIDPr) {
  271. case "burger0Leave" :
  272. closeResultMenu();
  273. break;
  274. }
  275. };
  276.  
  277. this.burger1Processor = (String choiceIDPr) -> {
  278. switch (choiceIDPr) {
  279. case "startBurgerJob" :
  280. System.out.println("starting burger job");
  281. closeResultMenu();
  282. Game.jobFunction.jobList.get(0).setHasJob(true);
  283. break;
  284. }
  285. };
  286.  
  287. this.burger2Processor = (String choiceIDPr) -> {
  288. switch (choiceIDPr) {
  289. case "signIn" :
  290. System.out.println("signing into job");
  291.  
  292. if (Game.jobFunction.jobList.get(0).onJob()) {
  293. int fivePM = (int) ((17 * 60 * HUD.gameSlowFactor) + ((HUD.day - 1) * 1440 * HUD.gameSlowFactor));
  294. double timeWorked = fivePM - HUD.rawTimeElapsed;
  295. double pay = (timeWorked * 8.5) / (60 * HUD.gameSlowFactor);
  296. HUD.rawTimeElapsed = fivePM; //timelapses to 5pm
  297. System.out.println("Signed out of job");
  298. try {
  299. resultMenu = new Menu(burgerSOArchive);
  300. } catch (FontFormatException e) {
  301. // TODO Auto-generated catch block
  302. e.printStackTrace();
  303. } catch (IOException e) {
  304. // TODO Auto-generated catch block
  305. e.printStackTrace();
  306. }
  307. Game.moneyChangeCause = "Worked at Job";
  308. HUD.money += pay;//pay should be dependent on how many hours worked
  309. HUD.hunger -= (HUD.METABOLISM / HUD.gameSlowFactor) * timeWorked;
  310. HUD.energy -= (HUD.ENERGY_LOSS / HUD.gameSlowFactor) * timeWorked;
  311. makeResultMenu(); //shows a menu after timelapse
  312. closeOldMenu();
  313.  
  314. }
  315. break;
  316. case "buyBurgerFood" :
  317. if (Finance.tryBuy(3.50)) {
  318. try {
  319. resultMenu = new Menu(burger0Archive);
  320. } catch (FontFormatException | IOException e) {
  321. // TODO Auto-generated catch block
  322. e.printStackTrace();
  323. }
  324. makeResultMenu();
  325. closeOldMenu();
  326. HUD.hunger += 10;
  327. } else {
  328. //play sound
  329. System.out.println("No money.");
  330. }
  331.  
  332. break;
  333. case "quit" :
  334. System.out.println("quit job");
  335. closeOldMenu();
  336. closeResultMenu();
  337. //for now, future: lead back to old menu & give quit message
  338. break;
  339. case "burger2Leave" :
  340. closeOldMenu();
  341. closeResultMenu();
  342. break;
  343. }
  344. };
  345.  
  346. this.burgerSOProcessor = (String choiceIDPr) -> {
  347. switch (choiceIDPr) {
  348. case "exitBurger" :
  349. closeResultMenu();
  350. break;
  351. }
  352. };
  353.  
  354. this.burgerOffProcessor = (String choiceIDPr) -> {
  355. switch (choiceIDPr) {
  356. case "buyBurgerFood" :
  357. if (Finance.tryBuy(3.50)) {
  358. try {
  359. resultMenu = new Menu(burger0Archive);
  360. } catch (FontFormatException | IOException e) {
  361. // TODO Auto-generated catch block
  362. e.printStackTrace();
  363. }
  364. makeResultMenu();
  365. closeOldMenu();
  366. HUD.hunger += 10;
  367. } else {
  368. //play sound
  369. System.out.println("No money.");
  370. }
  371. break;
  372. case "burgerOffLeave" :
  373. closeOldMenu();
  374. closeResultMenu();
  375. break;
  376. case "quitBurgerJob" :
  377. closeOldMenu();
  378. closeResultMenu();
  379. break; //temporarily until quitting system is ok.
  380. }
  381.  
  382. };
  383.  
  384. this.burgerFProcessor = (String choiceIDPr) -> {
  385. switch (choiceIDPr) {
  386. case "buyBurgerFood" :
  387. if (Finance.tryBuy(4.99)) {
  388. try {
  389. resultMenu = new Menu(burger0Archive);
  390. } catch (FontFormatException | IOException e) {
  391. // TODO Auto-generated catch block
  392. e.printStackTrace();
  393. }
  394. makeResultMenu();
  395. closeOldMenu();
  396. HUD.hunger += 10;
  397. } else {
  398. //play sound
  399. System.out.println("No money.");
  400. }
  401.  
  402. break;
  403.  
  404. case "leaveBurger" :
  405. closeOldMenu();
  406. closeResultMenu();
  407. break;
  408. }
  409. };
  410.  
  411. burger0Archive = new MenuDataArchive(burger0Prompt, burger0Options, burger0Processor, ID.ResultMenu, null);
  412. burger1Archive = new MenuDataArchive(burger1Prompt, burger1Options, burger1Processor, ID.ResultMenu, null);
  413. burgerSOArchive = new MenuDataArchive(burgerSignOut, burgerSOOptions, burgerSOProcessor, ID.ResultMenu, null);
  414. burger2Archive = new MenuDataArchive(burger2Prompt, burger2Options, burger2Processor, ID.ChoiceMenu, burger2Title);
  415. burgerOffArchive = new MenuDataArchive(burgerOffPrompt, burgerOffOptions, burgerOffProcessor, ID.ChoiceMenu, burgerOffTitle);
  416. burgerArchive = new MenuDataArchive(burgerPrompt, burgerOptions, burgerProcessor, ID.ChoiceMenu, burgerTitle);
  417. burgerFArchive = new MenuDataArchive(burgerFPrompt, burgerFOptions, burgerFProcessor, ID.ChoiceMenu, burgerFiredTitle);
  418.  
  419.  
  420.  
  421. this.apartmentProcessor = (String choiceIDPr) -> {
  422. switch (choiceIDPr) {
  423. case "sleepApartment" :
  424. try {
  425. cityNoise.stop();
  426. } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
  427. e.printStackTrace();
  428. }
  429. try {
  430. resultMenu = new Menu(apartment0Archive);
  431. } catch (FontFormatException | IOException e) {
  432. e.printStackTrace();
  433. }
  434. sleepEffect = new SleepEffect(0, 0, ID.SleepEffect);
  435. Game.handler.addObject(sleepEffect);
  436. Game.gameState = Game.STATES.Sleeping;
  437. if (HUD.hoursSinceMidnight > 6) {
  438. nextMorning = (int) ((8 * 60 * HUD.gameSlowFactor) + (HUD.day * 1440 * HUD.gameSlowFactor) - 1);
  439. } else {
  440. nextMorning = (int) ((8 * 60 * HUD.gameSlowFactor) + ((HUD.day - 1) * 1440 * HUD.gameSlowFactor) - 1);
  441. }
  442. //player wakes up at 7:59 AM so they have time to make their 8 AM rent payment
  443. timeSlept = (int) (nextMorning - HUD.rawTimeElapsed);
  444. HUD.energy += SleepEffect.getEnergyRestored();
  445. HUD.rawTimeElapsed = nextMorning; //set gameTime to the next morning
  446. makeResultMenu();
  447. closeOldMenu();
  448. break;
  449. case "leave" :
  450. closeOldMenu();
  451. break;
  452. }
  453. };
  454.  
  455.  
  456.  
  457. this.apartment0Processor = (String choiceIDPr) -> {
  458. switch (choiceIDPr) {
  459. case "leave" :
  460. HUD.hungerLoss = (float) (timeSlept * (HUD.METABOLISM / HUD.gameSlowFactor) / 2);
  461. HUD.health -= (HUD.hungerPain * timeSlept) / 6;
  462. HUD.hunger -= (double) HUD.hungerLoss;
  463. Inventory.dirtyClothes();
  464. closeResultMenu();
  465. try {
  466. cityNoise.play();
  467. } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
  468. // TODO Auto-generated catch block
  469. e.printStackTrace();
  470. }
  471. break;
  472. }
  473. };
  474.  
  475. apartmentArchive = new MenuDataArchive(apartmentPrompt, apartmentOptions, apartmentProcessor, ID.ChoiceMenu, apartmentTitle);
  476. apartment0Archive = new MenuDataArchive(apartment0Prompt, apartment0Options, apartment0Processor, ID.ResultMenu, null);
  477.  
  478. this.collegeProcessor = (String choiceIDPr) -> {
  479. switch (choiceIDPr) {
  480. case "payTuition" :
  481. System.out.println("TUITION");
  482. try {
  483. resultMenu = new Menu(college0Archive);
  484. } catch (FontFormatException | IOException e) {
  485. // TODO Auto-generated catch block
  486. e.printStackTrace();
  487. }
  488. makeResultMenu();
  489. closeOldMenu();
  490. break;
  491. case "leave":
  492. closeOldMenu();
  493. break;
  494. }
  495. };
  496.  
  497. collegeArchive = new MenuDataArchive(collegePrompt, collegeOptions, collegeProcessor, ID.ChoiceMenu, collegeTitle);
  498.  
  499. this.college0Processor = (String choiceIDPr) -> {
  500. switch (choiceIDPr) {
  501. case "leave" :
  502. closeResultMenu();
  503. break;
  504. }
  505. };
  506.  
  507. college0Archive = new MenuDataArchive(college0Prompt, college0Options, college0Processor, ID.ResultMenu, null);
  508.  
  509. this.walmartProcessor = (String choiceIDPr) -> {
  510. switch(choiceIDPr) {
  511. case "buy1Grocery":
  512. if (Finance.tryBuy(10.00)) {
  513. HUD.hunger += 25; //placeholder
  514. closeOldMenu();
  515. } else {
  516. //play sound
  517. }
  518. break;
  519. case "buy7Grocery":
  520. if (Finance.tryBuy(40.00)) {
  521. HUD.hunger += 100;
  522. closeOldMenu();
  523. } else {
  524. //play sound
  525. }
  526.  
  527. break;
  528. case "buyBike":
  529. if (Finance.tryBuy(100.00)) {
  530. Inventory.hasBike = true;
  531. //HUD.bike = true;
  532. closeOldMenu();
  533. } else {
  534. //play sound
  535. }
  536.  
  537. break;
  538. case "leave":
  539. closeOldMenu();
  540. break;
  541. }
  542. };
  543.  
  544. walmartArchive = new MenuDataArchive(walmartPrompt, walmartOptions, walmartProcessor, ID.ChoiceMenu, walmartTitle);
  545.  
  546. this.hospitalProcessor = (String choiceIDPr) -> {
  547. switch (choiceIDPr) {
  548. case "checkUp":
  549. if (Finance.tryBuy(500.00)) {
  550. HUD.health = 100;
  551. HUD.rawTimeElapsed += 2 * 60 * HUD.gameSlowFactor; //takes one hour to complete
  552. try {
  553. resultMenu = new Menu(hospital0Archive);
  554. } catch (FontFormatException | IOException e) {
  555. // TODO Auto-generated catch block
  556. e.printStackTrace();
  557. }
  558. makeResultMenu();
  559. closeOldMenu();
  560. } else {
  561. //play sound
  562. }
  563.  
  564. break;
  565. case "leave":
  566. closeOldMenu();
  567. break;
  568. }
  569. };
  570.  
  571. hospitalArchive = new MenuDataArchive(hospitalPrompt, hospitalOptions, hospitalProcessor, ID.ChoiceMenu, hospitalTitle);
  572.  
  573. this.hospital0Processor = (String choiceIDPr) -> {
  574. switch (choiceIDPr) {
  575. case "leave" :
  576. closeResultMenu();
  577. break;
  578. }
  579. };
  580.  
  581. hospital0Archive = new MenuDataArchive(hospital0Prompt, hospital0Options, hospital0Processor, ID.ResultMenu, null);
  582.  
  583. eventFindMoneyProcessor = (String choiceIDPr) -> {
  584. switch (choiceIDPr) {
  585. case "leave":
  586. double rng = r.nextInt(100);
  587. double foundMoney = rng / 100;
  588. if (foundMoney == 0) {
  589. foundMoney = .01;
  590. }
  591. HUD.money += foundMoney;
  592. closeEvent();
  593. break;
  594. }
  595. };
  596.  
  597. eventFindMoneyArchive = new MenuDataArchive(eventFindMoneyPrompt, eventFindMoneyOptions,
  598. eventFindMoneyProcessor, ID.ResultMenu, null);
  599.  
  600. this.eventStrikesProcessor = (String choiceIDPr) -> {
  601. switch (choiceIDPr) {
  602. case "exitStrikes" :
  603. closeEvent();
  604. break;
  605. }
  606. };
  607.  
  608. eventStrikesArchive = new MenuDataArchive(eventStrikesPrompt, eventStrikesOptions,
  609. eventStrikesProcessor, ID.ResultMenu, null);
  610.  
  611. eventCollapseProcessor = (String choiceIDPr) -> {
  612. switch (choiceIDPr) {
  613. case "collapse":
  614. try {
  615. cityNoise.stop();
  616. } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
  617. e.printStackTrace();
  618. }
  619. if ((HUD.money > 0)) { //if you have any money, make the result menu where you lose money
  620. try {
  621. resultMenu = new Menu(eventCollapse0Archive);
  622. } catch (FontFormatException | IOException e) {
  623. e.printStackTrace();
  624. }
  625. } else {
  626. try { //else make the result menu where you lose moeny
  627. resultMenu = new Menu(eventCollapse0NoMoneyArchive);
  628. } catch (FontFormatException | IOException e) {
  629. e.printStackTrace();
  630. }
  631. }
  632. sleepEffect = new SleepEffect(0, 0, ID.SleepEffect);
  633. Game.handler.addObject(sleepEffect);
  634. Game.gameState = Game.STATES.Sleeping;
  635. if (HUD.hoursSinceMidnight > 6) {
  636. nextMorning = (int) ((8 * 60 * HUD.gameSlowFactor) + (HUD.day * 1440 * HUD.gameSlowFactor) - 1);
  637. } else {
  638. nextMorning = (int) ((8 * 60 * HUD.gameSlowFactor) + ((HUD.day - 1) * 1440 * HUD.gameSlowFactor) - 1);
  639. }
  640.  
  641. //player wakes up at 7:59 AM so they have time to make their 8 AM rent payment
  642. timeSlept = (int) (nextMorning - HUD.rawTimeElapsed);
  643. HUD.energy += SleepEffect.getEnergyRestored();
  644. HUD.rawTimeElapsed = nextMorning; //set gameTime to the next morning
  645. makeResultMenu();
  646. closeEvent();
  647. System.out.println("oh boy i cant wait to make result menu");
  648.  
  649.  
  650. break;
  651. }
  652. };
  653.  
  654. eventCollapseArchive = new MenuDataArchive(eventCollapsePrompt, eventCollapseOptions,
  655. eventCollapseProcessor, ID.ResultMenu, null);
  656.  
  657. eventCollapse0Processor = (String choiceIDPr) -> {
  658. switch (choiceIDPr) {
  659. case "leave":
  660. HUD.hungerLoss = (float) (timeSlept * (HUD.METABOLISM / HUD.gameSlowFactor) / 2);
  661. HUD.health -= (HUD.hungerPain * timeSlept) / 6;
  662. HUD.hunger -= (double) HUD.hungerLoss;
  663. HUD.money -= HUD.money / 2; //lose half your money
  664. Game.moneyChangeCause = "Stolen";
  665. //moneyEffectML = new MoneyEffect(10, 85, ID.MoneyEffect, -HUD.money / 2);
  666. System.out.println(moneyEffectML + " = moneyEffectML");
  667. Inventory.dirtyClothes();
  668. System.out.println("Wake up from Collapse Menu");
  669. try {
  670. stream = AudioSystem.getAudioInputStream(PlayerInput.class.getResource("cityAmbience.wav"));
  671. clip = AudioSystem.getClip();
  672.  
  673. cityNoise = new BackGroundSound((long) 0.0, clip, "?", stream, filePathSound);
  674.  
  675. cityNoise.play();
  676. } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e1) {
  677. // TODO Auto-generated catch block
  678. e1.printStackTrace();
  679. }
  680. closeResultMenu();
  681. System.out.println(moneyEffectML + " = moneyEffectML");
  682. break;
  683. }
  684. };
  685.  
  686. eventCollapse0Archive = new MenuDataArchive(eventCollapse0Prompt, eventCollapse0Options,
  687. eventCollapse0Processor, ID.ResultMenu, null);
  688.  
  689. eventCollapse0NoMoneyProcessor = (String choiceIDPr) -> {
  690. switch (choiceIDPr) {
  691. case "leave":
  692. HUD.hungerLoss = (float) (timeSlept * (HUD.METABOLISM / HUD.gameSlowFactor) / 2);
  693. HUD.health -= (HUD.hungerPain * timeSlept) / 6;
  694. HUD.hunger -= (double) HUD.hungerLoss;
  695. Inventory.dirtyClothes();
  696. System.out.println("Wake up from Collapse Menu");
  697. try {
  698. stream = AudioSystem.getAudioInputStream(PlayerInput.class.getResource("cityAmbience.wav"));
  699. clip = AudioSystem.getClip();
  700.  
  701. cityNoise = new BackGroundSound((long) 0.0, clip, "?", stream, filePathSound);
  702.  
  703. cityNoise.play();
  704. } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e1) {
  705. // TODO Auto-generated catch block
  706. e1.printStackTrace();
  707. }
  708. closeResultMenu();
  709. break;
  710. }
  711. };
  712.  
  713. eventCollapse0NoMoneyArchive = new MenuDataArchive(eventCollapse0NoMoneyPrompt, eventCollapse0NoMoneyOptions,
  714. eventCollapse0NoMoneyProcessor, ID.ResultMenu, null);
  715.  
  716. kickedOutProcessor = (choiceIDPr) -> {
  717. switch (choiceIDPr) {
  718. case "leave":
  719. closeOldMenu();
  720. break;
  721. }
  722.  
  723. };
  724.  
  725. kickedOutArchive = new MenuDataArchive(kickedOutPrompt, kickedOutOptions, kickedOutProcessor, ID.ResultMenu, null);
  726.  
  727. } // END OF BOX CONSTRUCTOR
  728.  
  729. public void closeResultMenu() {
  730. Game.thisGame.removeKeyListener(resultMenu);
  731. Game.handler.removeObject(resultMenu);
  732. resultMenu = null;
  733. Game.gameState = Game.STATES.Playing;
  734.  
  735. }
  736. public void closeOldMenu() {
  737. Game.handler.removeObject(Game.activeListener.getBuildingMenu());
  738. Game.thisGame.removeKeyListener(Game.activeListener.getBuildingMenu());
  739. if (resultMenu == null) {
  740. Game.gameState = Game.STATES.Playing;
  741. }
  742. }
  743. public void makeResultMenu() {
  744. Game.handler.addObject(resultMenu);
  745. Game.thisGame.addKeyListener(resultMenu);
  746. }
  747.  
  748. public void closeEvent() {
  749. Game.handler.removeObject(Game.eventMaker.eventMenu);
  750. Game.thisGame.removeKeyListener(Game.eventMaker.eventMenu);
  751. if (resultMenu == null) {
  752. Game.gameState = Game.STATES.Playing;
  753. }
  754. Game.eventMaker.eventMenu = null;
  755. }
  756. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement