dsun

cmd game in progress

Feb 3rd, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.25 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5. static Scanner i = new Scanner(System.in);
  6. static String name, option;
  7. static String items[] = {"[P]otion", "[D]agger", "[T]orch\t"};
  8. static int hp, hpMax, lvl, coins, potionCount;
  9. static int price[] = {25, 50, 250};
  10. static boolean area, potion, dagger, torch;
  11.  
  12. public static void main(String[] args) {
  13. hp = 10;
  14. hpMax = 10;
  15. lvl = 1;
  16. coins = 350;
  17. potionCount = 0;
  18. area = true;
  19. potion = false;
  20. dagger = false;
  21. torch = false;
  22.  
  23. System.out.println("Welcome to DragonWorld");
  24. System.out.print("Name: ");
  25. name = i.nextLine();
  26. home();
  27. }
  28.  
  29. public static void home(){
  30. System.out.println("\nYou are in your home.");
  31. System.out.println("Options: [E]xit, [R]est, [I]nventory, [S]tats");
  32. option = i.nextLine().toLowerCase();
  33.  
  34. while(area == true){
  35.  
  36. if(option.equals("e")){
  37. town();
  38. }else if(option.equals("r")){
  39. if(hp < 10){
  40. hp = hpMax;
  41. System.out.println("\nYou rested well!");
  42. option = i.nextLine().toLowerCase();
  43. }else{
  44. System.out.println("\nYou don't feel like resting.");
  45. option = i.nextLine().toLowerCase();
  46. }
  47. }else if(option.equals("i")){
  48. System.out.println("\nInventory:");
  49. if(potion == false && dagger == false && torch == false){
  50. System.out.println("Empty");
  51. option = i.nextLine().toLowerCase();
  52. }else{
  53. if(potion == true){
  54. System.out.println(items[0] + " x" + potionCount);
  55. }
  56.  
  57. if(dagger == true){
  58. System.out.println(items[1]);
  59. }
  60.  
  61. if(torch == true){
  62. System.out.println(items[2]);
  63. }
  64. option = i.nextLine().toLowerCase();
  65. }
  66. }else if(option.equals("s")){
  67. System.out.println("\nName: " + name + "\nHealth: " + hp + "/" + hpMax + "\nCoins: " + coins + "\n");
  68. option = i.nextLine().toLowerCase();
  69. }else{
  70. option = i.nextLine().toLowerCase();
  71. }
  72. }
  73. }
  74.  
  75. public static void town(){
  76. System.out.println("\nYou are in the town.");
  77. System.out.println("Options: [H]ome, [S]hop, [F]orest");
  78. option = i.nextLine().toLowerCase();
  79.  
  80. while(area == true){
  81.  
  82. if(option.equals("h")){
  83. home();
  84. }else if(option.equals("s")){
  85. shop();
  86. }else if(option.equals("f")){
  87. forest();
  88. }else{
  89. option = i.nextLine().toLowerCase();
  90. }
  91. }
  92. }
  93.  
  94. public static void shop(){
  95. System.out.println("\nYou are in the shop.");
  96. System.out.println("Options: [B]uy, [E]xit");
  97. option = i.nextLine().toLowerCase();
  98.  
  99. while(area == true){
  100.  
  101. if(option.equals("b")){
  102. System.out.println("\nShop keeper: Hello, how can I help you?\nYou have " + coins + " coins.");
  103. System.out.println("\nItems\t\tPrice");
  104.  
  105. for(int x = 0; x < items.length && x < price.length; x++){
  106. System.out.println(items[x] + "\t" + price[x]);
  107. }
  108. System.out.println("[E]xit");
  109. option = i.nextLine().toLowerCase();
  110.  
  111. while(area == true){
  112.  
  113. if(option.equals("p")){
  114. if(coins >= 25){
  115. coins -= 25;
  116. System.out.println("\nYou buy a potion.");
  117. option = i.nextLine().toLowerCase();
  118. potionCount++;
  119. potion = true;
  120.  
  121. }else{
  122. System.out.println("\nNot enough money!");
  123. option = i.nextLine().toLowerCase();
  124. }
  125.  
  126. }else if(option.equals("d")){
  127. if(dagger == true){
  128. System.out.println("\nYou already have a dagger!");
  129. option = i.nextLine().toLowerCase();
  130. }else if(coins >= 50){
  131. coins -= 50;
  132. System.out.println("\nYou buy the dagger.");
  133. option = i.nextLine().toLowerCase();
  134. dagger = true;
  135. }else{
  136. System.out.println("\nNot enough money!");
  137. option = i.nextLine().toLowerCase();
  138. }
  139.  
  140. }else if(option.equals("t")){
  141. if(torch == true){
  142. System.out.println("\nYou already have a torch!");
  143. option = i.nextLine().toLowerCase();
  144. }else if(coins >= 250){
  145. coins -= 250;
  146. System.out.println("\nYou buy the torch.");
  147. option = i.nextLine().toLowerCase();
  148. torch = true;
  149. }else{
  150. System.out.println("\nNot enough money!");
  151. option = i.nextLine().toLowerCase();
  152. }
  153. }else if(option.equals("e")){
  154. town();
  155. }else{
  156. option = i.nextLine().toLowerCase();
  157. }
  158. }
  159.  
  160. }else if(option.equals("e")){
  161. town();
  162. }else{
  163. option = i.nextLine().toLowerCase();
  164. }
  165. }
  166. }
  167.  
  168. public static void forest(){
  169. System.out.println("\nYou are in the forest.");
  170. System.out.println("Options: [L]eft, [R]ight, [D]eeper, [B]ack");
  171. option = i.nextLine().toLowerCase();
  172.  
  173. while(area == true){
  174.  
  175. if(option.equals("l")){
  176. System.out.println("\nYou went to the left.");
  177. System.out.println("Options: [R]ight");
  178. option = i.nextLine().toLowerCase();
  179.  
  180. while(area == true){
  181.  
  182. if(option.equals("r")){
  183. forest();
  184. }else{
  185. option = i.nextLine().toLowerCase();
  186. }
  187. }
  188.  
  189. }else if(option.equals("r")){
  190. System.out.println("\nYou went to the right.");
  191. System.out.println("Options: [L]eft");
  192. option = i.nextLine().toLowerCase();
  193.  
  194. while(area == true){
  195.  
  196. if(option.equals("l")){
  197. forest();
  198. }else{
  199. option = i.nextLine().toLowerCase();
  200. }
  201. }
  202.  
  203. }else if(option.equals("d")){
  204. System.out.println("\nYou are deep in the forest.");
  205. System.out.println("You see a cave.");
  206. System.out.println("Options: [E]nter, [B]ack");
  207. option = i.nextLine().toLowerCase();
  208.  
  209. while(area == true){
  210.  
  211. if(option.equals("e")){
  212.  
  213. if(torch == true){
  214. cave();
  215. }else{
  216. System.out.println("\nIt's too dark to see!");
  217. option = i.nextLine().toLowerCase();
  218. }
  219.  
  220. }else if(option.equals("b")){
  221. forest();
  222. }else{
  223. option = i.nextLine().toLowerCase();
  224. }
  225. }
  226.  
  227. }else if(option.equals("b")){
  228. town();
  229. }else{
  230. option = i.nextLine().toLowerCase();
  231. }
  232. }
  233. }
  234.  
  235. public static void cave(){
  236. System.out.println("\nYou use the torch.");
  237. System.out.println("\nYou are in the cave.");
  238. System.out.println("Options: [F]orward, [B]ackward");
  239. option = i.nextLine().toLowerCase();
  240.  
  241.  
  242. }
  243. }
Advertisement
Add Comment
Please, Sign In to add comment