Advertisement
Guest User

Untitled

a guest
Jun 13th, 2011
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.21 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class finalproject {
  4. public static void main(String[] args){
  5. int health = 1000;
  6. int money = 540;
  7. int sword = 0;
  8. int helmet = 0;
  9. int armor = 0;
  10. int ehealth = 0;
  11. int endgame = 0;
  12. while (endgame == 0) {
  13. String choice;
  14. Scanner user_in = new Scanner(System.in);
  15. int leavebattle = 0;
  16. int payloan = 0;
  17. //check for money below 0
  18. if (money < 0) {
  19. System.out.println("You had to take out a loan and now have to pay the bank $" + Math.abs(money) + ".");
  20. System.out.println("Fight to gain money to pay back loan?");
  21. choice = user_in.nextLine();
  22. //yes or no for paying loan
  23. if (choice.equals("yes")) {
  24. payloan++;
  25. }
  26. else if (choice.equals("no")) {
  27. System.out.println("Game Over");
  28. System.out.println("Press Enter to restart.");
  29. //reset ints to default for restart (health, money, amount of items)
  30. health = 1000;
  31. money = 540;
  32. sword = 0;
  33. helmet = 0;
  34. armor = 0;
  35. //end resetting ints for restart
  36. //press enter to restart
  37. Scanner sc = new Scanner(System.in);
  38. while(!sc.nextLine().equals(""));
  39. } //end yes or no for loan
  40. } //end money check
  41. //start of main
  42. System.out.println("Health=" + health);
  43. System.out.println("Money=$" + money);
  44. System.out.println("What do you want to do? Go to shop, inventory, fight, or sleep.");
  45. choice = user_in.nextLine();
  46. //main choices - fight
  47. if (choice.equals("fight")) {
  48. leavebattle = 0;
  49. int enemy = (int)(100.0 * Math.random()) + 1;
  50. if (enemy <= 10) {
  51. ehealth = 100;
  52. System.out.println("Enemy: Knight");
  53. System.out.println("Enemy health: " + ehealth);
  54. }
  55. else if ((enemy > 10) && (enemy <= 20)) {
  56. ehealth = 200;
  57. System.out.println("Enemy: White Knight");
  58. System.out.println("Enemy health: " + ehealth);
  59. }
  60. else if ((enemy > 20) && (enemy <= 30)) {
  61. ehealth = 300;
  62. System.out.println("Enemy: Giant Spider");
  63. System.out.println("Enemy health: " + ehealth);
  64. }
  65. else if ((enemy > 30) && (enemy <= 40)) {
  66. ehealth = 400;
  67. System.out.println("Enemy: Black Knight");
  68. System.out.println("Enemy health: " + ehealth);
  69. }
  70. else if ((enemy > 40) && (enemy <= 50)) {
  71. ehealth = 500;
  72. System.out.println("Enemy: \"The Thing\"");
  73. System.out.println("Enemy health: " + ehealth);
  74. }
  75. else if ((enemy > 50) && (enemy <= 60)) {
  76. ehealth = 600;
  77. System.out.println("Enemy: Ogre");
  78. System.out.println("Enemy health: " + ehealth);
  79. }
  80. else if ((enemy > 60) && (enemy <= 70)) {
  81. ehealth = 700;
  82. System.out.println("Enemy: \"The Creation\"");
  83. System.out.println("Enemy health: " + ehealth);
  84. }
  85. else if ((enemy > 70) && (enemy <= 80)) {
  86. ehealth = 800;
  87. System.out.println("Enemy: Beast");
  88. System.out.println("Enemy health: " + ehealth);
  89. }
  90. else if ((enemy > 80) && (enemy <= 90)) {
  91. ehealth = 900;
  92. System.out.println("Enemy: Dark Beast");
  93. System.out.println("Enemy health: " + ehealth);
  94. }
  95. else if ((enemy > 90) && (enemy <= 100)) {
  96. ehealth = 1001;
  97. System.out.println("Enemy: Dragon");
  98. System.out.println("Enemy health: " + ehealth);
  99. }
  100. System.out.println("Use sword or fist?");
  101. choice = user_in.nextLine();
  102. if (choice.equals("sword") && (sword >= 1)) {
  103. while (leavebattle == 0) {
  104. //begin random number for damage received
  105. if (armor == 0) {
  106. if (helmet == 0) {
  107. int fightnum = (int)(Math.random()*50+100);
  108. System.out.println("You receive " + fightnum + " damage and have " + (health - fightnum) + " health left.");
  109. health -= fightnum;
  110. }
  111. else if (helmet >= 1) {
  112. int fightnum2 = (int)(Math.random()*20+100);
  113. System.out.println("You receive " + fightnum2 + " damage and have " + (health - fightnum2) + " health left.");
  114. health -= fightnum2;
  115. }
  116. }
  117. else if (armor >= 1) {
  118. if (helmet == 0) {
  119. int fightnum3 = (int)(Math.random()*20+50);
  120. System.out.println("You receive " + fightnum3 + " damage and have " + (health - fightnum3) + " health left.");
  121. health -= fightnum3;
  122. }
  123. else if (helmet >= 1) {
  124. int fightnum4 = (int)(Math.random()*20+20);
  125. System.out.println("You receive " + fightnum4 + " damage and have " + (health - fightnum4) + " health left.");
  126. health -= fightnum4;
  127. }
  128. }
  129. //end damage received
  130. //begin damage given to enemy
  131. int playdmg = (int)(Math.random()*100+20);
  132. System.out.println("You deal " + playdmg + " damage and the enemy has " + (ehealth - playdmg) + " health left.");
  133. ehealth -= playdmg;
  134. //end damage given to enemy
  135. System.out.println("Press Enter to continue.");
  136. Scanner sd = new Scanner(System.in);
  137. while(!sd.nextLine().equals(""));
  138. if (health <= 0) {
  139. System.out.println("You have died. Restart?");
  140. choice = user_in.nextLine();
  141. if (choice.equals("yes")) {
  142. //reset ints to default for restart (health, money, amount of items)
  143. health = 1000;
  144. money = 540;
  145. sword = 0;
  146. helmet = 0;
  147. armor = 0;
  148. leavebattle = 1;
  149. //end resetting ints for restart
  150. //press enter to restart
  151. System.out.println("Press Enter to continue.");
  152. Scanner sc = new Scanner(System.in);
  153. while(!sc.nextLine().equals(""));
  154. }
  155. else if (choice.equals("no")) {
  156. System.out.println("Game Over");
  157. leavebattle++;
  158. endgame++;
  159. System.exit(0);
  160. }
  161. }
  162. else if (ehealth <= 0) {
  163. System.out.println("The enemy has died!");
  164. if (enemy <= 10) {
  165. int pay = (int)(Math.random()*10+110);
  166. money += pay;
  167. System.out.println("You receive $" + pay + " for killing Knight.");
  168. leavebattle = 1;
  169. }
  170. else if ((enemy > 10) && (enemy <= 20)) {
  171. int pay = (int)(Math.random()*20+120);
  172. money += pay;
  173. System.out.println("You receive $" + pay + " for killing White Knight.");
  174. leavebattle = 1;
  175. }
  176. else if ((enemy > 20) && (enemy <= 30)) {
  177. int pay = (int)(Math.random()*30+130);
  178. money += pay;
  179. System.out.println("You receive $" + pay + " for killing Giant Spider.");
  180. leavebattle = 1;
  181. }
  182. else if ((enemy > 30) && (enemy <= 40)) {
  183. int pay = (int)(Math.random()*40+140);
  184. money += pay;
  185. System.out.println("You receive $" + pay + " for killing Black Knight.");
  186. leavebattle = 1;
  187. }
  188. else if ((enemy > 40) && (enemy <= 50)) {
  189. int pay = (int)(Math.random()*50+150);
  190. money += pay;
  191. System.out.println("You receive $" + pay + " for killing \"The Thing\".");
  192. leavebattle = 1;
  193. }
  194. else if ((enemy > 50) && (enemy <= 60)) {
  195. int pay = (int)(Math.random()*60+160);
  196. money += pay;
  197. System.out.println("You receive $" + pay + " for killing Ogre.");
  198. leavebattle = 1;
  199. }
  200. else if ((enemy > 60) && (enemy <= 70)) {
  201. int pay = (int)(Math.random()*70+170);
  202. money += pay;
  203. System.out.println("You receive $" + pay + " for killing \"The Creation\".");
  204. leavebattle = 1;
  205. }
  206. else if ((enemy > 70) && (enemy <= 80)) {
  207. int pay = (int)(Math.random()*80+180);
  208. money += pay;
  209. System.out.println("You receive $" + pay + " for killing Beast.");
  210. leavebattle = 1;
  211. }
  212. else if ((enemy > 80) && (enemy <= 90)) {
  213. int pay = (int)(Math.random()*90+190);
  214. money += pay;
  215. System.out.println("You receive $" + pay + " for killing Dark Beast.");
  216. leavebattle = 1;
  217. }
  218. else if (enemy > 90) {
  219. int pay = (int)(Math.random()*100+200);
  220. money += pay;
  221. System.out.println("You receive $" + pay + " for killing Dragon.");
  222. System.out.println("Congratulations! You have defeated the strongest enemy!");
  223. leavebattle = 1;
  224. }
  225. }
  226. }
  227. }
  228. else if (choice.equals("sword") && (sword <= 0)) {
  229. System.out.println("You cannot fight with a sword. You must buy one in the shop first.");
  230. }
  231. else if (choice.equals("fist")) {
  232. leavebattle = 0;
  233. while (leavebattle == 0) {
  234. //begin random number for damage received
  235. if (armor == 0) {
  236. if (helmet == 0) {
  237. int fightnum5 = (int)(Math.random()*50+100);
  238. System.out.println("You receive " + fightnum5 + " damage and have " + (health - fightnum5) + " health left.");
  239. health -= fightnum5;
  240. }
  241. else if (helmet >= 1) {
  242. int fightnum6 = (int)(Math.random()*20+100);
  243. System.out.println("You receive " + fightnum6 + " damage and have " + (health - fightnum6) + " health left.");
  244. health -= fightnum6;
  245. }
  246. }
  247. else if (armor >= 1) {
  248. if (helmet == 0) {
  249. int fightnum7 = (int)(Math.random()*20+50);
  250. System.out.println("You receive " + fightnum7 + " damage and have " + (health - fightnum7) + " health left.");
  251. health -= fightnum7;
  252. }
  253. else if (helmet >= 1) {
  254. int fightnum8 = (int)(Math.random()*20+20);
  255. System.out.println("You receive " + fightnum8 + " damage and have " + (health - fightnum8) + " health left.");
  256. health -= fightnum8;
  257. }
  258. }
  259. //end damage received
  260. //begin damage given
  261. int playdmg2 = (int)(Math.random()*20+100);
  262. System.out.println("You deal " + playdmg2 + " damage and the enemy has " + (ehealth - playdmg2) + " health left.");
  263. ehealth -= playdmg2;
  264. //end damage given
  265. //press enter to continue
  266. System.out.println("Press Enter to continue.");
  267. Scanner se = new Scanner(System.in);
  268. while(!se.nextLine().equals(""));
  269. if (health <= 0) {
  270. System.out.println("You have died. Restart?");
  271. choice = user_in.nextLine();
  272. if (choice.equals("yes")) {
  273. //reset ints to default for restart (health, money, amount of items)
  274. health = 1000;
  275. money = 540;
  276. sword = 0;
  277. helmet = 0;
  278. armor = 0;
  279. leavebattle = 1;
  280. //end resetting ints for restart
  281. //press enter to restart
  282. System.out.println("Press Enter to continue.");
  283. Scanner sc = new Scanner(System.in);
  284. while(!sc.nextLine().equals(""));
  285. }
  286. else if (choice.equals("no")) {
  287. System.out.println("Game Over");
  288. leavebattle++;
  289. endgame++;
  290. System.exit(0);
  291. }
  292. }
  293. else if (ehealth <= 0) {
  294. System.out.println("The enemy has died!");
  295. if (enemy <= 10) {
  296. int pay = (int)(Math.random()*100+70);
  297. money += pay;
  298. System.out.println("You receive $" + pay + " for killing Knight.");
  299. leavebattle = 1;
  300. }
  301. else if ((enemy > 10) && (enemy <= 20)) {
  302. int pay = (int)(Math.random()*100+80);
  303. money += pay;
  304. System.out.println("You receive $" + pay + " for killing White Knight.");
  305. leavebattle = 1;
  306. }
  307. else if ((enemy > 20) && (enemy <= 30)) {
  308. int pay = (int)(Math.random()*100+90);
  309. money += pay;
  310. System.out.println("You receive $" + pay + " for killing Giant Spider.");
  311. leavebattle = 1;
  312. }
  313. else if ((enemy > 30) && (enemy <= 40)) {
  314. int pay = (int)(Math.random()*100+100);
  315. money += pay;
  316. System.out.println("You receive $" + pay + " for killing Black Knight.");
  317. leavebattle = 1;
  318. }
  319. else if ((enemy > 40) && (enemy <= 50)) {
  320. int pay = (int)(Math.random()*150+100);
  321. money += pay;
  322. System.out.println("You receive $" + pay + " for killing \"The Thing\".");
  323. leavebattle = 1;
  324. }
  325. else if ((enemy > 50) && (enemy <= 60)) {
  326. int pay = (int)(Math.random()*200+100);
  327. money += pay;
  328. System.out.println("You receive $" + pay + " for killing Ogre.");
  329. leavebattle = 1;
  330. }
  331. else if ((enemy > 60) && (enemy <= 70)) {
  332. int pay = (int)(Math.random()*250+100);
  333. money += pay;
  334. System.out.println("You receive $" + pay + " for killing \"The Creation\".");
  335. leavebattle = 1;
  336. }
  337. else if ((enemy > 70) && (enemy <= 80)) {
  338. int pay = (int)(Math.random()*300+100);
  339. money += pay;
  340. System.out.println("You receive $" + pay + " for killing Beast.");
  341. leavebattle = 1;
  342. }
  343. else if ((enemy > 80) && (enemy <= 90)) {
  344. int pay = (int)(Math.random()*350+100);
  345. money += pay;
  346. System.out.println("You receive $" + pay + " for killing Dark Beast.");
  347. leavebattle = 1;
  348. }
  349. else if (enemy > 90) {
  350. int pay = (int)(Math.random()*500+100);
  351. money += pay;
  352. System.out.println("You receive $" + pay + " for killing Dragon.");
  353. System.out.println("Congratulations! You have defeated the strongest enemy!");
  354. leavebattle = 1;
  355. }
  356. }
  357. }
  358. //int fightnum = (int)(Math.random()*50+100);
  359. //System.out.println("You receive " + fightnum + " damage.");
  360. //health -= fightnum;
  361. }
  362. }
  363. //end fight
  364. //main choices - shop
  365. else if (choice.equals("shop")) {
  366. if (payloan == 0) {
  367. if ((money <= 1000) && (money > 0)) {
  368. System.out.println("What do you want to buy?");
  369. System.out.println("Sword--$50");
  370. System.out.println("Helmet--$250");
  371. System.out.println("Armor--$550");
  372. choice = user_in.nextLine();
  373. //shop choices
  374. if (choice.equals("sword")) {
  375. money -= 50;
  376. System.out.println("You buy a sword, and you now have $"+ money +".");
  377. sword++;
  378. }
  379. else if (choice.equals("helmet")) {
  380. money -= 250;
  381. System.out.println("You buy a helmet, and you now have $"+ money +".");
  382. helmet++;
  383. }
  384. else if (choice.equals("armor")) {
  385. money -= 550;
  386. System.out.println("You buy a set of armor, and you now have $"+ money +".");
  387. armor++;
  388. }
  389. else {
  390. System.out.println(choice + " is not a valid choice.");
  391. }
  392. }
  393. else {
  394. System.out.println("You cannot buy anything else at this time.");
  395. }
  396. }
  397. else if (payloan > 0) {
  398. System.out.println("You must fight to pay back your loan first.");
  399. System.out.println("Hit Enter to continue.");
  400. Scanner sc = new Scanner(System.in);
  401. while(!sc.nextLine().equals(""));
  402. }
  403. }
  404. //end shop
  405. //main choices - sleep
  406. else if (choice.equals("sleep")) {
  407. if (payloan == 0) {
  408. if (health == 1000) {
  409. System.out.println("You have full health.");
  410. }
  411. else if (health < 1000) {
  412. health = 1000;
  413. System.out.println("Your health is fully restored.");
  414. }
  415. }
  416. else if (payloan > 0) {
  417. System.out.println("You must fight to pay back your loan first.");
  418. System.out.println("Hit Enter to continue.");
  419. Scanner sc = new Scanner(System.in);
  420. while(!sc.nextLine().equals(""));
  421. }
  422. }
  423. //end sleep
  424. //main choices - inventory
  425. else if (choice.equals("inventory")) {
  426. System.out.println("Swords: " + sword);
  427. System.out.println("Helmets: " + helmet);
  428. System.out.println("Sets of armor: " + armor);
  429. System.out.println("Press Enter to continue.");
  430. //press enter to continue
  431. Scanner sc = new Scanner(System.in);
  432. while(!sc.nextLine().equals(""));
  433. }
  434. //end inventory
  435. else {
  436. System.out.println(choice + " is not a valid choice.");
  437. }
  438. }
  439. }
  440. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement