dsun

Untitled

Jan 25th, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.29 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Random;
  3.  
  4. class game{
  5.  
  6. static Scanner jscan = new Scanner(System.in);
  7. static Random rand = new Random();
  8. static String choices;
  9. static boolean home = false;
  10. static boolean shop = false;
  11. static boolean outside = false;
  12. static boolean forest = false;
  13. static boolean combat = false;
  14. static boolean buy = false;
  15. static int dmg;
  16. static int health = 20;
  17. static String name;
  18. static int exp = 0;
  19. static int totalExp = 0;
  20. static int coinsDrop;
  21. static int coins = 0;
  22. static int lvl = 1;
  23. static int totalHealth = 20;
  24. static boolean bossFight = false;
  25. static boolean forest2 = false;
  26. static boolean fight = false;
  27. static boolean bossDead = false;
  28.  
  29. public static void main(String[] args){
  30.  
  31. System.out.println("\nGOBLIN FOREST\n");
  32. System.out.print("Name: ");
  33. name = jscan.nextLine();
  34. home();
  35. }
  36.  
  37. public static void outside(){
  38. System.out.println("Location: Town");
  39. System.out.println("Options: Home, Shop, Forest, Talk");
  40. choices = jscan.nextLine().toLowerCase();
  41.  
  42. while(outside == false){
  43. if(choices.equals("home")){
  44. home();
  45. }else if(choices.equals("shop")){
  46. shop();
  47. }else if(choices.equals("forest")){
  48. forest();
  49. }else if(choices.equals("talk")){
  50. System.out.println("\nWoman: Please help us! The goblins won't stop robbing us!");
  51. System.out.println("Woman: Kill the goblin king and end this!\n");
  52. outside();
  53. }else{
  54. choices = jscan.nextLine().toLowerCase();
  55. }
  56. }
  57. }
  58.  
  59. public static void sleep(){
  60.  
  61. if(health <= 10){
  62. health = totalHealth;
  63. System.out.println("\nYou slept well!");
  64. }else{
  65. System.out.println("\nYou don't feel like sleeping right now.");
  66. }
  67. home();
  68. }
  69.  
  70. public static void home(){
  71. System.out.println("\nLocation: Home");
  72. System.out.println("Options: Leave, Sleep, Character");
  73. choices = jscan.nextLine().toLowerCase();
  74.  
  75. while(home == false){
  76. if(choices.equals("leave")){
  77. outside();
  78. }else if(choices.equals("sleep")){
  79. sleep();
  80. }else if(choices.equals("character")){
  81. System.out.println("Name: " + name + ", Health: " + health + "/" + totalHealth + ", Coins: " + coins + ", Exp points: " + totalExp + ", Level: " + lvl);
  82. choices = jscan.nextLine().toLowerCase();
  83. }else{
  84. choices = jscan.nextLine().toLowerCase();
  85. }
  86. }
  87. }
  88.  
  89. public static void shop(){
  90. System.out.println("\nLocation: Shop");
  91. System.out.println("Options: Buy, Leave, Talk");
  92. choices = jscan.nextLine().toLowerCase();
  93.  
  94. while(shop == false){
  95. if(choices.equals("leave")){
  96. outside();
  97. }else if(choices.equals("buy")){
  98. buy();
  99. }else if(choices.equals("talk")){
  100. System.out.println("\nShop keeper: I wouldn't go near the goblin king!");
  101. System.out.println("Shop keeper: That thing can do 150 damage!");
  102. shop();
  103. }else{
  104. choices = jscan.nextLine().toLowerCase();
  105. }
  106. }
  107. }
  108.  
  109. public static void forest(){
  110. System.out.println("\nLocation: Forest");
  111. System.out.println("Options: Back, Kill, Deeper");
  112. choices = jscan.nextLine().toLowerCase();
  113.  
  114. while(forest == false){
  115. if(choices.equals("back")){
  116. outside();
  117. }else if(choices.equals("kill")){
  118. goblin();
  119. }else if(choices.equals("deeper")){
  120. forest2();
  121. }else{
  122. choices = jscan.nextLine().toLowerCase();
  123. }
  124. }
  125. }
  126.  
  127. public static void goblin(){
  128. System.out.println("\nYou spot a goblin! (Level 1)");
  129. System.out.println("Options: Fight, Run");
  130. choices = jscan.nextLine().toLowerCase();
  131.  
  132. while(combat == false){
  133. if(choices.equals("fight")){
  134. combatSystem();
  135. }else if(choices.equals("run")){
  136. System.out.println("\nYou ran away!");
  137. forest();
  138. }else{
  139. choices = jscan.nextLine().toLowerCase();
  140. }
  141. }
  142. }
  143.  
  144. public static void combatSystem(){
  145. dmg = rand.nextInt(6);
  146. health = health - dmg;
  147. coinsDrop = 2+rand.nextInt(11);
  148.  
  149. if(health <= 0){
  150. System.out.println("\nYou died!");
  151. System.out.println("You lost the coins.");
  152. health = totalHealth;
  153. coins = coins - coins;
  154. home();
  155. }else if(health > 0){
  156. System.out.println("\nYou killed the goblin!");
  157. System.out.println("It drops " + coinsDrop + " coins!");
  158. System.out.println("You have " + health + " health left.");
  159. totalExp += 10;
  160. exp += 10;
  161. coins = coins + coinsDrop;
  162. level();
  163. forest();
  164. }
  165. }
  166.  
  167. public static void buy(){
  168. System.out.println("\nShop keeper: Hello!");
  169. System.out.println("Options: Health Potion (50 coins), Leave");
  170. System.out.println("You have " + coins + " coins.");
  171. choices = jscan.nextLine().toLowerCase();
  172.  
  173. while(buy == false){
  174.  
  175. if(choices.equals("leave")){
  176. outside();
  177. }else if(choices.equals("health potion")){
  178.  
  179. if(coins < 50){
  180. System.out.println("\nNot enough coins!");
  181. shop();
  182. }else if(coins >= 50){
  183. System.out.println("\nYou bought the item.");
  184. coins = coins - 50;
  185. System.out.println("\nYou drink the potion... Health increased by 5!");
  186. totalHealth = totalHealth + 5;
  187. health = health + 5;
  188. shop();
  189. }
  190. }else{
  191. choices = jscan.nextLine().toLowerCase();
  192. }
  193. }
  194. }
  195.  
  196. public static void level(){
  197. if(exp == 50){
  198. lvl = lvl + 1;
  199. System.out.println("\nYou are now level " + lvl + "!");
  200. totalHealth = totalHealth + 10;
  201. exp = -50;
  202. }
  203. }
  204.  
  205. public static void forest2(){
  206. System.out.println("\nLocation: Deeper Forest");
  207. System.out.println("Options: Back, Forward");
  208. choices = jscan.nextLine().toLowerCase();
  209.  
  210. while(forest2 == false){
  211. if(choices.equals("back")){
  212. goblin();
  213. }else if(choices.equals("forward")){
  214. bossFight();
  215. }else{
  216. choices = jscan.nextLine().toLowerCase();
  217. }
  218. }
  219. }
  220.  
  221. public static void goblinKing(){
  222. dmg = 50+rand.nextInt(100);
  223. health = health - dmg;
  224. System.out.println("The Goblin King hits you for "+ dmg + " damage!");
  225. System.out.println("You have " + health + " health left!");
  226.  
  227. while(bossDead == false){
  228.  
  229. if(health <= 0){
  230. System.out.println("\nYou died!");
  231. System.out.println("You lost the coins.");
  232. health = totalHealth;
  233. coins = coins - coins;
  234. home();
  235. }else if(health > 0){
  236. System.out.println("\nYou defeated the Goblin King!");
  237. bossDead = true;
  238. fight = true;
  239. theEnd();
  240. }
  241. }
  242. }
  243.  
  244. public static void theEnd(){
  245. System.out.println("\nYou go back to the town with the goblin king's head...");
  246. System.out.println("Later you're known as King " + name + ".");
  247. System.out.println("\nThe End");
  248. System.out.println("Thank you for playing!\n");
  249. home = true;
  250. shop = true;
  251. outside = true;
  252. forest = true;
  253. combat = true;
  254. forest2 = true;
  255. buy = true;
  256. bossFight = true;
  257.  
  258. }
  259.  
  260. public static void bossFight(){
  261. System.out.println("\nYou see the goblin king! (Level 20)");
  262. System.out.println("Options: Fight, Run");
  263. choices = jscan.nextLine().toLowerCase();
  264.  
  265. while(fight == false){
  266.  
  267. if(choices.equals("run")){
  268. System.out.println("\nYou ran away!");
  269. System.out.println("\nGoblin King: Come back, stupid human!");
  270. forest2();
  271. }else if(choices.equals("fight")){
  272. System.out.println("\nGoblin King: Stupid human wants to fight me?!");
  273. goblinKing();
  274. }else{
  275. choices = jscan.nextLine().toLowerCase();
  276. }
  277. }
  278. }
  279. }
Advertisement
Add Comment
Please, Sign In to add comment