dsun

Untitled

Feb 3rd, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 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"};
  8. static int hp, hpMax, coins, potionCount;
  9. static int price[] = {25, 50};
  10. static boolean area, potion, dagger;
  11.  
  12. public static void main(String[] args) {
  13. hp = 10;
  14. hpMax = 10;
  15. area = true;
  16. potion = false;
  17. dagger = false;
  18. coins = 500;
  19. potionCount = 0;
  20.  
  21. System.out.println("Welcome to DragonWorld");
  22. System.out.print("Name: ");
  23. name = i.nextLine();
  24. home();
  25. }
  26.  
  27. public static void home(){
  28. System.out.println("\nYou are in your home.");
  29. System.out.println("Options: [E]xit, [R]est, [I]nventory");
  30. option = i.nextLine().toLowerCase();
  31.  
  32. while(area == true){
  33.  
  34. if(option.equals("e")){
  35. town();
  36. }else if(option.equals("r")){
  37.  
  38. if(hp < 10){
  39. hp = hpMax;
  40. System.out.println("\nYou rested well!");
  41. option = i.nextLine().toLowerCase();
  42. }else{
  43. System.out.println("\nYou don't feel like resting.");
  44. option = i.nextLine().toLowerCase();
  45. }
  46.  
  47. }else if(option.equals("i")){
  48. System.out.println("\nName: " + name + "\nHealth: " + hp + "/" + hpMax + "\nCoins: " + coins + "\n");
  49. System.out.println("Inventory:");
  50.  
  51. if(potion == false && dagger == false){
  52. System.out.println("Empty");
  53. }else{
  54. if(potion == true){
  55. System.out.println("[P]otion" + " x" + potionCount);
  56. }
  57.  
  58. if(dagger == true){
  59. System.out.println("[D]agger");
  60. }
  61. }
  62.  
  63. option = i.nextLine().toLowerCase();
  64. }else{
  65. option = i.nextLine().toLowerCase();
  66. }
  67. }
  68.  
  69. }
  70.  
  71. public static void town(){
  72. System.out.println("\nYou are in the town.");
  73. System.out.println("Options: [H]ome, [S]hop, [F]orest");
  74. option = i.nextLine().toLowerCase();
  75.  
  76. while(area == true){
  77.  
  78. if(option.equals("h")){
  79. home();
  80. }else if(option.equals("s")){
  81. shop();
  82. }else if(option.equals("f")){
  83. //forest();
  84. }else{
  85. option = i.nextLine().toLowerCase();
  86. }
  87.  
  88. }
  89.  
  90. }
  91.  
  92. public static void shop(){
  93. System.out.println("\nYou are in the shop.");
  94. System.out.println("Options: [B]uy, [E]xit");
  95. option = i.nextLine().toLowerCase();
  96.  
  97. while(area == true){
  98.  
  99. if(option.equals("b")){
  100. System.out.println("\nShop keeper: Hello, how can I help you?\nYou have " + coins + " coins.\n");
  101. System.out.println("\nItems\t\tPrice");
  102.  
  103. for(int x = 0; x < items.length && x < price.length; x++){
  104. System.out.println(items[x] + "\t" + price[x]);
  105. }
  106. System.out.println("[E]xit");
  107. option = i.nextLine().toLowerCase();
  108.  
  109. while(area == true){
  110.  
  111. if(option.equals("p")){
  112. if(coins >= 25){
  113. coins -= 25;
  114. System.out.println("\nYou bought a potion.");
  115. option = i.nextLine().toLowerCase();
  116. potionCount++;
  117. potion = true;
  118.  
  119. }else{
  120. System.out.println("\nNot enough money!");
  121. option = i.nextLine().toLowerCase();
  122. }
  123.  
  124. }else if(option.equals("d")){
  125. if(dagger == true){
  126. System.out.println("\nYou already have a dagger!");
  127. option = i.nextLine().toLowerCase();
  128. }else if(coins >= 50){
  129. coins -=50;
  130. System.out.println("\nYou bought a dagger");
  131. option = i.nextLine().toLowerCase();
  132. dagger = true;
  133. }else{
  134. System.out.println("\nNot enough money!");
  135. option = i.nextLine().toLowerCase();
  136. }
  137.  
  138. }else if(option.equals("e")){
  139. town();
  140. }else{
  141. option = i.nextLine().toLowerCase();
  142. }
  143. }
  144.  
  145. }else if(option.equals("e")){
  146. town();
  147. }else{
  148. option = i.nextLine().toLowerCase();
  149. }
  150. }
  151. }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment