Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Random;
- class game{
- static Scanner jscan = new Scanner(System.in);
- static Random rand = new Random();
- static String choices;
- static boolean home = false;
- static boolean shop = false;
- static boolean outside = false;
- static boolean forest = false;
- static boolean combat = false;
- static boolean buy = false;
- static int dmg;
- static int health = 20;
- static String name;
- static int exp = 0;
- static int totalExp = 0;
- static int coinsDrop;
- static int coins = 0;
- static int lvl = 1;
- static int totalHealth = 20;
- static boolean bossFight = false;
- static boolean forest2 = false;
- static boolean fight = false;
- static boolean bossDead = false;
- public static void main(String[] args){
- System.out.println("\nGOBLIN FOREST\n");
- System.out.print("Name: ");
- name = jscan.nextLine();
- home();
- }
- public static void outside(){
- System.out.println("Location: Town");
- System.out.println("Options: Home, Shop, Forest, Talk");
- choices = jscan.nextLine().toLowerCase();
- while(outside == false){
- if(choices.equals("home")){
- home();
- }else if(choices.equals("shop")){
- shop();
- }else if(choices.equals("forest")){
- forest();
- }else if(choices.equals("talk")){
- System.out.println("\nWoman: Please help us! The goblins won't stop robbing us!");
- System.out.println("Woman: Kill the goblin king and end this!\n");
- outside();
- }else{
- choices = jscan.nextLine().toLowerCase();
- }
- }
- }
- public static void sleep(){
- if(health <= 10){
- health = totalHealth;
- System.out.println("\nYou slept well!");
- }else{
- System.out.println("\nYou don't feel like sleeping right now.");
- }
- home();
- }
- public static void home(){
- System.out.println("\nLocation: Home");
- System.out.println("Options: Leave, Sleep, Character");
- choices = jscan.nextLine().toLowerCase();
- while(home == false){
- if(choices.equals("leave")){
- outside();
- }else if(choices.equals("sleep")){
- sleep();
- }else if(choices.equals("character")){
- System.out.println("Name: " + name + ", Health: " + health + "/" + totalHealth + ", Coins: " + coins + ", Exp points: " + totalExp + ", Level: " + lvl);
- choices = jscan.nextLine().toLowerCase();
- }else{
- choices = jscan.nextLine().toLowerCase();
- }
- }
- }
- public static void shop(){
- System.out.println("\nLocation: Shop");
- System.out.println("Options: Buy, Leave, Talk");
- choices = jscan.nextLine().toLowerCase();
- while(shop == false){
- if(choices.equals("leave")){
- outside();
- }else if(choices.equals("buy")){
- buy();
- }else if(choices.equals("talk")){
- System.out.println("\nShop keeper: I wouldn't go near the goblin king!");
- System.out.println("Shop keeper: That thing can do 150 damage!");
- shop();
- }else{
- choices = jscan.nextLine().toLowerCase();
- }
- }
- }
- public static void forest(){
- System.out.println("\nLocation: Forest");
- System.out.println("Options: Back, Kill, Deeper");
- choices = jscan.nextLine().toLowerCase();
- while(forest == false){
- if(choices.equals("back")){
- outside();
- }else if(choices.equals("kill")){
- goblin();
- }else if(choices.equals("deeper")){
- forest2();
- }else{
- choices = jscan.nextLine().toLowerCase();
- }
- }
- }
- public static void goblin(){
- System.out.println("\nYou spot a goblin! (Level 1)");
- System.out.println("Options: Fight, Run");
- choices = jscan.nextLine().toLowerCase();
- while(combat == false){
- if(choices.equals("fight")){
- combatSystem();
- }else if(choices.equals("run")){
- System.out.println("\nYou ran away!");
- forest();
- }else{
- choices = jscan.nextLine().toLowerCase();
- }
- }
- }
- public static void combatSystem(){
- dmg = rand.nextInt(6);
- health = health - dmg;
- coinsDrop = 2+rand.nextInt(11);
- if(health <= 0){
- System.out.println("\nYou died!");
- System.out.println("You lost the coins.");
- health = totalHealth;
- coins = coins - coins;
- home();
- }else if(health > 0){
- System.out.println("\nYou killed the goblin!");
- System.out.println("It drops " + coinsDrop + " coins!");
- System.out.println("You have " + health + " health left.");
- totalExp += 10;
- exp += 10;
- coins = coins + coinsDrop;
- level();
- forest();
- }
- }
- public static void buy(){
- System.out.println("\nShop keeper: Hello!");
- System.out.println("Options: Health Potion (50 coins), Leave");
- System.out.println("You have " + coins + " coins.");
- choices = jscan.nextLine().toLowerCase();
- while(buy == false){
- if(choices.equals("leave")){
- outside();
- }else if(choices.equals("health potion")){
- if(coins < 50){
- System.out.println("\nNot enough coins!");
- shop();
- }else if(coins >= 50){
- System.out.println("\nYou bought the item.");
- coins = coins - 50;
- System.out.println("\nYou drink the potion... Health increased by 5!");
- totalHealth = totalHealth + 5;
- health = health + 5;
- shop();
- }
- }else{
- choices = jscan.nextLine().toLowerCase();
- }
- }
- }
- public static void level(){
- if(exp == 50){
- lvl = lvl + 1;
- System.out.println("\nYou are now level " + lvl + "!");
- totalHealth = totalHealth + 10;
- exp = -50;
- }
- }
- public static void forest2(){
- System.out.println("\nLocation: Deeper Forest");
- System.out.println("Options: Back, Forward");
- choices = jscan.nextLine().toLowerCase();
- while(forest2 == false){
- if(choices.equals("back")){
- goblin();
- }else if(choices.equals("forward")){
- bossFight();
- }else{
- choices = jscan.nextLine().toLowerCase();
- }
- }
- }
- public static void goblinKing(){
- dmg = 50+rand.nextInt(100);
- health = health - dmg;
- System.out.println("The Goblin King hits you for "+ dmg + " damage!");
- System.out.println("You have " + health + " health left!");
- while(bossDead == false){
- if(health <= 0){
- System.out.println("\nYou died!");
- System.out.println("You lost the coins.");
- health = totalHealth;
- coins = coins - coins;
- home();
- }else if(health > 0){
- System.out.println("\nYou defeated the Goblin King!");
- bossDead = true;
- fight = true;
- theEnd();
- }
- }
- }
- public static void theEnd(){
- System.out.println("\nYou go back to the town with the goblin king's head...");
- System.out.println("Later you're known as King " + name + ".");
- System.out.println("\nThe End");
- System.out.println("Thank you for playing!\n");
- home = true;
- shop = true;
- outside = true;
- forest = true;
- combat = true;
- forest2 = true;
- buy = true;
- bossFight = true;
- }
- public static void bossFight(){
- System.out.println("\nYou see the goblin king! (Level 20)");
- System.out.println("Options: Fight, Run");
- choices = jscan.nextLine().toLowerCase();
- while(fight == false){
- if(choices.equals("run")){
- System.out.println("\nYou ran away!");
- System.out.println("\nGoblin King: Come back, stupid human!");
- forest2();
- }else if(choices.equals("fight")){
- System.out.println("\nGoblin King: Stupid human wants to fight me?!");
- goblinKing();
- }else{
- choices = jscan.nextLine().toLowerCase();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment