Advertisement
Guest User

Untitled

a guest
May 2nd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.19 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Game
  5. {
  6. private static boolean fromAdmin = false;
  7. public static void main(String args[])
  8. {
  9. SOP("Welcome to RPG V1, please choose an option from the list below.");
  10. delayOneSecond();
  11. SOP("1. Start the game");
  12. SOP("2. Quit the game (Already?)");
  13. SOP("3. Administrator Account");
  14. initialMenu(fromAdmin);
  15. }
  16.  
  17. public static void initialMenu(boolean fromAdmin)
  18. {
  19. if(fromAdmin)
  20. {
  21. SOP("1. Start the game");
  22. SOP("2. Quit the game (Already?)");
  23. SOP("3. Administrator Account");
  24. }
  25.  
  26. Scanner myScan = new Scanner(System.in);
  27. int choice = myScan.nextInt();
  28. switch(choice)
  29. {
  30. case 1:
  31. basicInfo();
  32. break;
  33. case 2:
  34. return;
  35. case 3:
  36. admin(fromAdmin);
  37. }
  38. }
  39.  
  40. public static void admin(boolean fromAdmin)
  41. {
  42. fromAdmin = true;
  43. boolean goodUser = false;
  44. String password;
  45. Scanner admin = new Scanner(System.in);
  46.  
  47. System.out.println("Admin Login");
  48. System.out.println("Username: ");
  49. String username = admin.next();
  50. if(username.compareTo("advil0") == 0)
  51. {
  52. goodUser = true;
  53. }
  54. else
  55. {
  56. goodUser = false;
  57. }
  58.  
  59. if(goodUser)
  60. {
  61. System.out.println("Password: ");
  62. password = admin.next();
  63. }
  64. else
  65. {
  66. return;
  67. }
  68.  
  69. if(password.compareTo("herman") == 0)
  70. {
  71.  
  72. }
  73. else
  74. {
  75. return;
  76. }
  77.  
  78. SOP("Admin Menu");
  79. SOP("1. Return to game menu");
  80. SOP("2. Quit");
  81.  
  82. int adminChoice = admin.nextInt();
  83. switch(adminChoice)
  84. {
  85. case 1:
  86. initialMenu(fromAdmin);
  87. break;
  88. case 2:
  89. fastQuit();
  90. }
  91.  
  92. delayThreeSeconds();
  93. fastQuit();
  94. }
  95.  
  96. public static void basicInfo()
  97. {
  98. boolean goodInfo = false;
  99. Scanner myScan2 = new Scanner(System.in);
  100. SOP("Please choose a name for your character");
  101. String name = myScan2.next();
  102. SOP("How old is your character?");
  103. int age = myScan2.nextInt();
  104.  
  105. while(!goodInfo)
  106. {
  107. SOP("Are you a male or female?");
  108. String sex = myScan2.next();
  109. if( sex.compareTo("male") == 0 | sex.compareTo("Male") == 0 )
  110. {
  111. goodInfo = true;
  112. startGame();
  113. }
  114. if( sex.compareTo("female") == 0 | sex.compareTo("Female") == 0 )
  115. {
  116. goodInfo = true;
  117. startGame();
  118. }
  119. else
  120. {
  121. SOP("You can only enter male or female, try again.");
  122. delayOneSecond();
  123. goodInfo = false;
  124. }
  125. }
  126.  
  127. }
  128.  
  129. public static void startGame()
  130. {
  131. ArrayList al = new ArrayList();
  132.  
  133.  
  134. SOP("You have recieved your first item!");
  135. delayOneSecond();
  136. SOP("*A baseball bat appears out of nowhere, you pick it up");
  137. delayOneSecond();
  138. SOP("Gained 1 (Baseball Bat)");
  139. al.add("Baseball Bat");
  140. delayOneSecond();
  141. SOP( "Current inventory: " + al );
  142. gameMenu();
  143. }
  144.  
  145. public static void gameMenu()
  146. {
  147. Scanner gameMenu = new Scanner(System.in);
  148. boolean done = false;
  149. int charLevel = 1;
  150. int health = 100;
  151. int xp = 0;
  152.  
  153. if(done)
  154. {
  155. SOP("Test");
  156. }
  157. ArrayList al = new ArrayList();
  158. al.add("Baseball Bat");
  159. while(!done)
  160. {
  161.  
  162. if( xp > 20 )
  163. {
  164. charLevel++;
  165. SOP("You have gained a level!");
  166. }
  167.  
  168. SOP("Choose an option.");
  169. SOP("1. Attack a monster");
  170. SOP("2. Sleep and restore Health");
  171. SOP("3. Go to the general store to buy items");
  172. SOP("4. Quit game");
  173. SOP("5. Save Game");
  174. SOP("6. Save and Quit");
  175.  
  176. int menu = gameMenu.nextInt();
  177. switch(menu)
  178. {
  179. case 1:
  180. attackMonster(health,xp);
  181. break;
  182. case 2:
  183. sleep(health);
  184. break;
  185. case 3:
  186. generalStore(al);
  187. break;
  188. case 4:
  189. quitGame();
  190. case 5:
  191. saveGame();
  192. break;
  193. case 6:
  194. saveAndQuit();
  195. case 7:
  196. fastQuit();
  197. }
  198. if( charLevel == 10 )
  199. {
  200. done = true;
  201. }
  202. }
  203. }
  204.  
  205. public static void saveAndQuit()
  206. {
  207. saveGame();
  208. quitGame();
  209. }
  210.  
  211. public static void saveGame()
  212. {
  213. SOP("Saving...");
  214. delayThreeSeconds();
  215.  
  216. boolean success = true;
  217.  
  218. if(success)
  219. {
  220. SOP("Save successful!");
  221. }
  222.  
  223. if(!success)
  224. {
  225. SOP("Save unsuccessful, try again later.");
  226. }
  227.  
  228. delayOneSecond();
  229. return;
  230. }
  231.  
  232. public static void quitGame()
  233. {
  234. SOP("Quitting...");
  235. delayOneSecond();
  236. System.exit(0);
  237. }
  238.  
  239. public static void fastQuit()
  240. {
  241. SOP("Fast quitting...");
  242. delayOneSecond();
  243. System.exit(0);
  244. }
  245.  
  246. public static void generalStore(ArrayList al)
  247. {
  248. Scanner itemBuyer = new Scanner(System.in);
  249. SOP("What would you like to buy?");
  250. SOP("1. Giant Running Weaboo");
  251. int item = itemBuyer.nextInt();
  252.  
  253. switch(item)
  254. {
  255. case 1:
  256. giantRunningWeaboo();
  257. break;
  258. default:
  259. SOP("Please choose a valid choice");
  260. break;
  261. }
  262.  
  263. return;
  264. }
  265.  
  266. public static void giantRunningWeaboo()
  267. {
  268. SOP("A great choice!");
  269. SOP("You have chosen the Giant Running Weaboo");
  270. delayOneSecond();
  271. SOP("Are you sure you want to purchase this item?");
  272. delayOneSecond();
  273. confirmPurchase();
  274. return;
  275. }
  276.  
  277. public static void confirmPurchase()
  278. {
  279. boolean pass = false;
  280. Scanner confirm = new Scanner(System.in);
  281. while(!pass)
  282. {
  283. SOP("Yes or No");
  284. String answer = confirm.next();
  285. if(answer.compareTo("Yes") == 0 | answer.compareTo("yes") == 0)
  286. {
  287. SOP("Congratulations!");
  288. delayOneSecond();
  289. SOP("This item has been added to your inventory!");
  290. delayTwoSeconds();
  291. pass = true;
  292. }
  293. if(answer.compareTo("No") == 0 | answer.compareTo("no") == 0)
  294. {
  295. SOP("Sorry for the bother");
  296. delayOneSecond();
  297. pass = true;
  298. }
  299. else
  300. {
  301. SOP("Make a valid choice please");
  302. }
  303. }
  304. return;
  305. }
  306.  
  307. public static void attackMonster(int health, int xp)
  308. {
  309. SOP("You have encountered a wild pig!");
  310. delayOneSecond();
  311. SOP("You hit it for 5 hitpoints");
  312. delayOneSecond();
  313. SOP("The pig lunges at you and hits for 20!");
  314. health = health - 20;
  315. delayOneSecond();
  316. SOP("You hit the pig for 5 more points and it dies!");
  317. delayOneSecond();
  318. SOP("You gained 5xp!");
  319. xp = xp + 5;
  320. delayOneSecond();
  321. SOP( "Current XP: " + xp );
  322. delayOneSecond();
  323. return;
  324. }
  325.  
  326. public static void delayOneSecond()
  327. {
  328. try {
  329. Thread.sleep(1000L);
  330. }
  331. catch (Exception e) {}
  332. }
  333.  
  334. public static void delayThreeSeconds()
  335. {
  336. try {
  337. Thread.sleep(3000L);
  338. }
  339. catch (Exception e) {}
  340. }
  341.  
  342. public static void delayTwoSeconds()
  343. {
  344. try {
  345. Thread.sleep(2000L);
  346. }
  347. catch (Exception e) {}
  348. }
  349.  
  350. public static void delayFiveSeconds()
  351. {
  352. try {
  353. Thread.sleep(5000L);
  354. }
  355. catch (Exception e) {}
  356. }
  357.  
  358. public static int sleep(int health)
  359. {
  360. SOP("You walk into your house, lay down on the bed and get a good nights rest.");
  361. health = 100;
  362. return health;
  363. }
  364.  
  365. public static void SOP(String s)
  366. {
  367. System.out.println(s);
  368. }
  369. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement