dsun

CMD RPG (UNFINISHED)

Feb 4th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.97 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Random;
  3.  
  4. public class Main {
  5.  
  6. static Scanner i = new Scanner(System.in);
  7. static Random r = new Random();
  8. static String name, option;
  9. static String items[] = {"[P]otion", "[D]agger", "[T]orch\t"};
  10. static String mons[] = {"\nA wolf attacks you!\n", "\nA bear attacks you!\n", "\nA spider attacks you!\n", "\nA snake attacks you!\n", "\nA troll attacks you!\n"};
  11. public static int hp, hpMax, lvl, exp, totalExp, nextLvl, gold, goldDrop, potionCount, q_bearClawCount, monsterDrop, str, dmg, m_dmg, m_hp;
  12. static int price[] = {25, 50, 100};
  13. static boolean area, quest, fight, potion, dagger, torch, daggerEquipped, torchEquipped, q_bearClaw, questComplete;
  14.  
  15. public static void main(String[] args) throws InterruptedException {
  16.  
  17. hp = 10;
  18. hpMax = 10;
  19. lvl = 1;
  20. exp = 0;
  21. totalExp = 0;
  22. nextLvl = 35;
  23. gold = 0;
  24. potionCount = 0;
  25. q_bearClawCount = 0;
  26. str = 5;
  27. area = true;
  28. fight = true;
  29. potion = false;
  30. dagger = false;
  31. torch = false;
  32. daggerEquipped = false;
  33. torchEquipped = false;
  34. quest = false;
  35. q_bearClaw = false;
  36. questComplete = false;
  37.  
  38. System.out.println("DragonWorld\n");
  39. System.out.print("Name: ");
  40. name = i.nextLine();
  41. home();
  42. }
  43.  
  44. public static void home() throws InterruptedException{
  45. System.out.println("\nYou are in your home.");
  46. System.out.println("Options: [E]xit, [R]est, [I]nventory, [S]tats");
  47. option = i.nextLine().toLowerCase();
  48.  
  49. while(area == true){
  50.  
  51. if(option.equals("e")){
  52. town();
  53. }else if(option.equals("r")){
  54. if(hp < 5){
  55. hp = hpMax;
  56. System.out.println("\nYou rested well!");
  57. option = i.nextLine().toLowerCase();
  58. }else{
  59. System.out.println("\nYou don't feel like resting.");
  60. option = i.nextLine().toLowerCase();
  61. }
  62. }else if(option.equals("i")){
  63. System.out.println("\nInventory:\n" + gold + " gold");
  64. if(potion == false && dagger == false && torch == false){
  65. option = i.nextLine().toLowerCase();
  66. }else{
  67. if(potion == true){
  68. System.out.println(items[0] + " x" + potionCount);
  69. }
  70.  
  71. if(dagger == true){
  72. if(daggerEquipped == true){
  73. System.out.println(items[1] + " [Equipped]");
  74. }else{
  75. System.out.println(items[1]);
  76. }
  77.  
  78. }
  79.  
  80. if(torch == true){
  81. if(torchEquipped == true){
  82. System.out.println(items[2] + " [Equipped]");
  83. }else{
  84. System.out.println(items[2]);
  85. }
  86. }
  87. System.out.println("[E]xit");
  88. option = i.nextLine().toLowerCase();
  89.  
  90. while(area == true){
  91.  
  92. if(option.equals("p")){
  93. if(hp == hpMax){
  94. System.out.println("\nYou don't need to drink this right now.");
  95. }else{
  96. System.out.println("\nYou drink the potion... some HP was restored!");
  97. hp += 5;
  98. potionCount -= 1;
  99. if(hp > hpMax){
  100. hp = hpMax;
  101. }
  102. if(potionCount == 0){
  103. potion = false;
  104. }
  105.  
  106. home();
  107. }
  108. option = i.nextLine().toLowerCase();
  109. }else if(option.equals("d")){
  110. if(daggerEquipped == false){
  111. System.out.println("\nYou equip the dagger.");
  112. torchEquipped = false;
  113. daggerEquipped = true;
  114. str += 3;
  115. home();
  116. }else if(daggerEquipped == true){
  117. System.out.println("\nYou unequip the dagger.");
  118. daggerEquipped = false;
  119. str -= 3;
  120. home();
  121. }
  122.  
  123. }else if(option.equals("t")){
  124. if(torchEquipped == false && daggerEquipped == true){
  125. System.out.println("\nYou equip the torch.");
  126. str -= 3;
  127. daggerEquipped = false;
  128. torchEquipped = true;
  129. home();
  130. }else if(torchEquipped == true){
  131. System.out.println("\nYou unequip the torch.");
  132. torchEquipped = false;
  133. home();
  134. }else if(torchEquipped == false){
  135. System.out.println("\nYou equip the torch.");
  136. daggerEquipped = false;
  137. torchEquipped = true;
  138. home();
  139. }
  140. }else if(option.equals("e")){
  141. home();
  142. }else{
  143. option = i.nextLine().toLowerCase();
  144. }
  145.  
  146. }
  147. }
  148. }else if(option.equals("s")){
  149. System.out.println("\nName: " + name + "\nHP: " + hp + "/" + hpMax + "\nStrength: " + str + "\nLvl: " + lvl + "\nNext lvl at: " + exp + "/" + nextLvl + "\nTotal exp: " + totalExp);
  150. option = i.nextLine().toLowerCase();
  151. }else{
  152. option = i.nextLine().toLowerCase();
  153. }
  154. }
  155. }
  156.  
  157. public static void town() throws InterruptedException{
  158. System.out.println("\nYou are in the town.");
  159. System.out.println("Options: [H]ome, [S]hop, [F]orest");
  160. option = i.nextLine().toLowerCase();
  161.  
  162. while(area == true){
  163.  
  164. if(option.equals("h")){
  165. home();
  166. }else if(option.equals("s")){
  167. shop();
  168. }else if(option.equals("f")){
  169. forest();
  170. }else{
  171. option = i.nextLine().toLowerCase();
  172. }
  173. }
  174. }
  175.  
  176. public static void shop() throws InterruptedException{
  177. System.out.println("\nYou are in the shop.");
  178. System.out.println("Options: [B]uy, [E]xit");
  179. option = i.nextLine().toLowerCase();
  180.  
  181. while(area == true){
  182.  
  183. if(option.equals("b")){
  184. System.out.println("\nShop keeper: Hello, how can I help you?\nYou have " + gold + " gold.");
  185. System.out.println("\nItems\t\tPrice");
  186.  
  187. for(int x = 0; x < items.length && x < price.length; x++){
  188. System.out.println(items[x] + "\t" + price[x]);
  189. }
  190. System.out.println("[E]xit");
  191. option = i.nextLine().toLowerCase();
  192.  
  193. while(area == true){
  194.  
  195. if(option.equals("p")){
  196. if(gold >= 25){
  197. gold -= 25;
  198. System.out.println("\nYou buy a potion.");
  199. option = i.nextLine().toLowerCase();
  200. potionCount++;
  201. potion = true;
  202.  
  203. }else{
  204. System.out.println("\nNot enough money!");
  205. option = i.nextLine().toLowerCase();
  206. }
  207.  
  208. }else if(option.equals("d")){
  209. if(dagger == true){
  210. System.out.println("\nYou already have a dagger!");
  211. option = i.nextLine().toLowerCase();
  212. }else if(gold >= 50){
  213. gold -= 50;
  214. System.out.println("\nYou buy the dagger.");
  215. option = i.nextLine().toLowerCase();
  216. dagger = true;
  217. }else{
  218. System.out.println("\nNot enough money!");
  219. option = i.nextLine().toLowerCase();
  220. }
  221.  
  222. }else if(option.equals("t")){
  223. if(torch == true){
  224. System.out.println("\nYou already have a torch!");
  225. option = i.nextLine().toLowerCase();
  226. }else if(gold >= 100){
  227. gold -= 100;
  228. System.out.println("\nYou buy the torch.");
  229. option = i.nextLine().toLowerCase();
  230. torch = true;
  231. }else{
  232. System.out.println("\nNot enough money!");
  233. option = i.nextLine().toLowerCase();
  234. }
  235. }else if(option.equals("e")){
  236. town();
  237. }else{
  238. option = i.nextLine().toLowerCase();
  239. }
  240. }
  241.  
  242. }else if(option.equals("e")){
  243. town();
  244. }else{
  245. option = i.nextLine().toLowerCase();
  246. }
  247. }
  248. }
  249.  
  250. public static void forest() throws InterruptedException{
  251. System.out.println("\nYou are in the forest.");
  252. System.out.println("Options: [E]ast, [W]est, [N]orth, [S]outh");
  253. option = i.nextLine().toLowerCase();
  254.  
  255. while(area == true){
  256.  
  257. if(option.equals("e")){
  258. forestMonsters();
  259. System.out.println("\nYou went to the east.");
  260. System.out.println("You see a small house.");
  261. System.out.println("Options: [E]nter, [W]est");
  262. option = i.nextLine().toLowerCase();
  263.  
  264. while(area == true){
  265.  
  266. if(option.equals("w")){
  267. forestMonsters();
  268. forest();
  269. }else if(option.equals("e")){
  270. System.out.println("\nYou enter the small house.");
  271. System.out.println("You see an old woman.");
  272. System.out.println("Options: [T]alk, [E]xit");
  273. option = i.nextLine().toLowerCase();
  274.  
  275. while(area == true){
  276. if(option.equals("t")){
  277. if(quest == true && questComplete == false){
  278. if(q_bearClaw == true){
  279. q_bearClawCount = 0;
  280. System.out.println("\nOld Woman: Wonderful, thank you!");
  281. System.out.println("\nQuest Complete!\nReward: 50 gold");
  282. gold += 50;
  283. questComplete = true;
  284. forest();
  285. }else{
  286. System.out.println("\nOld Woman: Please bring me some bear claws.");
  287. forest();
  288. }
  289. }else if(quest == false){
  290. System.out.println("\nOld Woman: Hello, young one.");
  291. System.out.println("Old Woman: What brings you here?");
  292. System.out.println("Options: [Q]uest, [N]ever mind");
  293. option = i.nextLine().toLowerCase();
  294. while(quest == false){
  295. if(option.equals("q")){
  296. quest = true;
  297. System.out.println("\nOld Woman: Please bring me some bear claws.");
  298. forest();
  299. }else if(option.equals("n")){
  300. forest();
  301. }else{
  302. option = i.nextLine().toLowerCase();
  303. }
  304. }
  305. }else if(questComplete == true){
  306. System.out.println("\nOld Woman: I don't need help right now.");
  307. forest();
  308. }
  309. }else if(option.equals("e")){
  310. forest();
  311. }else{
  312. option = i.nextLine().toLowerCase();
  313. }
  314. }
  315. }else{
  316. option = i.nextLine().toLowerCase();
  317. }
  318. }
  319.  
  320. }else if(option.equals("w")){
  321. forestMonsters();
  322. System.out.println("\nYou went to the west.");
  323. System.out.println("Options: [E]ast");
  324. option = i.nextLine().toLowerCase();
  325.  
  326. while(area == true){
  327.  
  328. if(option.equals("e")){
  329. forestMonsters();
  330. forest();
  331. }else{
  332. option = i.nextLine().toLowerCase();
  333. }
  334. }
  335.  
  336. }else if(option.equals("n")){
  337. forestMonsters();
  338. System.out.println("\nYou went north.");
  339. System.out.println("You see a cave.");
  340. System.out.println("Options: [E]nter, [S]outh");
  341. option = i.nextLine().toLowerCase();
  342.  
  343. while(area == true){
  344.  
  345. if(option.equals("e")){
  346.  
  347. if(torchEquipped == true){
  348. cave();
  349. }else{
  350. System.out.println("\nIt's too dark to see!");
  351. option = i.nextLine().toLowerCase();
  352. }
  353.  
  354. }else if(option.equals("s")){
  355. forestMonsters();
  356. forest();
  357. }else{
  358. option = i.nextLine().toLowerCase();
  359. }
  360. }
  361.  
  362. }else if(option.equals("s")){
  363. forestMonsters();
  364. town();
  365. }else{
  366. option = i.nextLine().toLowerCase();
  367. }
  368. }
  369. }
  370.  
  371. public static void cave() throws InterruptedException{
  372. System.out.println("\nYou can now see thanks to the torch.");
  373. System.out.println("\nYou are in the cave.");
  374. System.out.println("Options: [F]orward, [B]ackward");
  375. System.out.println("\nUnder construction!");
  376. forest();
  377.  
  378.  
  379. }
  380.  
  381. public static void forestMonsters() throws InterruptedException{
  382. int fm = r.nextInt(5);
  383.  
  384. if(fm == 1){
  385. wolf();
  386. }else if(fm == 2){
  387. bear();
  388. }
  389. }
  390.  
  391. public static void caveMonsters(){
  392. int cm = r.nextInt(5);
  393.  
  394. if(cm == 1){
  395. //spider();
  396. }else if(cm == 2){
  397. //snake();
  398. }else if(cm == 3){
  399. //troll();
  400. }
  401. }
  402.  
  403. public static void lvlsystem(){
  404. totalExp += exp;
  405.  
  406. if(exp >= nextLvl){
  407. exp = 0;
  408. nextLvl *= 1.2;
  409. lvl++;
  410. hp += 3;
  411. hpMax += 3;
  412. str += 1;
  413. System.out.println("\nYou are now level " + lvl + "!");
  414. }
  415. }
  416.  
  417. public static void wolf() throws InterruptedException{
  418. fight = true;
  419. m_hp = 5;
  420. System.out.println(mons[0]);
  421.  
  422. while(fight == true){
  423. m_dmg = r.nextInt(2);
  424. goldDrop = 1+r.nextInt(5);
  425. monsterDrop = 1+r.nextInt(3);
  426. dmg = r.nextInt(str);
  427. dmg *= 0.5;
  428. System.out.println("Wolf (HP:" + m_hp + "/5) does " + m_dmg + " damage");
  429. hp -= m_dmg;
  430. System.out.println(name + " (HP:" + hp + "/" + hpMax + ") does " + dmg + " damage\n");
  431. m_hp -= dmg;
  432. Thread.sleep(1500);
  433.  
  434. if(m_hp <= 0){
  435. fight = false;
  436. System.out.println("You killed the wolf\nGained 15 exp\nDrops:\n" + goldDrop + " gold");
  437. if(monsterDrop == 1){
  438. System.out.println("Potion x1");
  439. potion = true;
  440. potionCount += 1;
  441. }
  442. gold += goldDrop;
  443. exp += 15;
  444. lvlsystem();
  445. }else if(hp <= 0){
  446. fight = false;
  447. System.out.println("\nYou died!");
  448. System.out.println("Lost some gold.");
  449. gold *= 0.5;
  450. hp = hpMax;
  451. home();
  452. }else if(hp <= 0 && m_hp <= 0){
  453. fight = false;
  454. System.out.println("\nYou died!");
  455. System.out.println("Lost some gold.");
  456. gold *= 0.5;
  457. hp = hpMax;
  458. home();
  459. }
  460. }
  461. }
  462.  
  463. public static void bear() throws InterruptedException{
  464. fight = true;
  465. m_hp = 7;
  466. System.out.println(mons[1]);
  467.  
  468. while(fight == true){
  469. m_dmg = r.nextInt(3);
  470. goldDrop = 1+r.nextInt(15);
  471. dmg = r.nextInt(str);
  472. dmg *= 0.5;
  473. System.out.println("Bear (HP:" + m_hp + "/7) does " + m_dmg + " damage");
  474. hp -= m_dmg;
  475. System.out.println(name + " (HP:" + hp + "/" + hpMax + ") does " + dmg + " damage\n");
  476. m_hp -= dmg;
  477. Thread.sleep(1500);
  478.  
  479. if(m_hp <= 0){
  480. fight = false;
  481. System.out.println("You killed the bear\nGained 25 exp\nDrops:\n" + goldDrop + " gold");
  482.  
  483. if(quest == true && q_bearClaw == false){
  484. if(q_bearClawCount == 3){
  485. System.out.println("\nI have the bear claws, I should go to the Old Woman now.");
  486. q_bearClaw = true;
  487. }else{
  488. q_bearClawCount++;
  489. System.out.println("Bear claw");
  490. }
  491. }
  492.  
  493. gold += goldDrop;
  494. exp += 25;
  495. lvlsystem();
  496. }else if(hp <= 0){
  497. fight = false;
  498. System.out.println("\nYou died!");
  499. System.out.println("Lost some gold.");
  500. gold *= 0.5;
  501. hp = hpMax;
  502. home();
  503. }else if(hp <= 0 && m_hp <= 0){
  504. fight = false;
  505. System.out.println("\nYou died!");
  506. System.out.println("Lost some gold.");
  507. gold *= 0.5;
  508. hp = hpMax;
  509. home();
  510. }
  511. }
  512. }
  513.  
  514. public static void spider(){
  515.  
  516. }
  517. }
Advertisement
Add Comment
Please, Sign In to add comment