Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- static Scanner i = new Scanner(System.in);
- static String name, option;
- static String items[] = {"[P]otion", "[D]agger"};
- static int hp, hpMax, coins, potionCount;
- static int price[] = {25, 50};
- static boolean area, potion, dagger;
- public static void main(String[] args) {
- hp = 10;
- hpMax = 10;
- area = true;
- potion = false;
- dagger = false;
- coins = 500;
- potionCount = 0;
- System.out.println("Welcome to DragonWorld");
- System.out.print("Name: ");
- name = i.nextLine();
- home();
- }
- public static void home(){
- System.out.println("\nYou are in your home.");
- System.out.println("Options: [E]xit, [R]est, [I]nventory");
- option = i.nextLine().toLowerCase();
- while(area == true){
- if(option.equals("e")){
- town();
- }else if(option.equals("r")){
- if(hp < 10){
- hp = hpMax;
- System.out.println("\nYou rested well!");
- option = i.nextLine().toLowerCase();
- }else{
- System.out.println("\nYou don't feel like resting.");
- option = i.nextLine().toLowerCase();
- }
- }else if(option.equals("i")){
- System.out.println("\nName: " + name + "\nHealth: " + hp + "/" + hpMax + "\nCoins: " + coins + "\n");
- System.out.println("Inventory:");
- if(potion == false && dagger == false){
- System.out.println("Empty");
- }else{
- if(potion == true){
- System.out.println("[P]otion" + " x" + potionCount);
- }
- if(dagger == true){
- System.out.println("[D]agger");
- }
- }
- option = i.nextLine().toLowerCase();
- }else{
- option = i.nextLine().toLowerCase();
- }
- }
- }
- public static void town(){
- System.out.println("\nYou are in the town.");
- System.out.println("Options: [H]ome, [S]hop, [F]orest");
- option = i.nextLine().toLowerCase();
- while(area == true){
- if(option.equals("h")){
- home();
- }else if(option.equals("s")){
- shop();
- }else if(option.equals("f")){
- //forest();
- }else{
- option = i.nextLine().toLowerCase();
- }
- }
- }
- public static void shop(){
- System.out.println("\nYou are in the shop.");
- System.out.println("Options: [B]uy, [E]xit");
- option = i.nextLine().toLowerCase();
- while(area == true){
- if(option.equals("b")){
- System.out.println("\nShop keeper: Hello, how can I help you?\nYou have " + coins + " coins.\n");
- System.out.println("\nItems\t\tPrice");
- for(int x = 0; x < items.length && x < price.length; x++){
- System.out.println(items[x] + "\t" + price[x]);
- }
- System.out.println("[E]xit");
- option = i.nextLine().toLowerCase();
- while(area == true){
- if(option.equals("p")){
- if(coins >= 25){
- coins -= 25;
- System.out.println("\nYou bought a potion.");
- option = i.nextLine().toLowerCase();
- potionCount++;
- potion = true;
- }else{
- System.out.println("\nNot enough money!");
- option = i.nextLine().toLowerCase();
- }
- }else if(option.equals("d")){
- if(dagger == true){
- System.out.println("\nYou already have a dagger!");
- option = i.nextLine().toLowerCase();
- }else if(coins >= 50){
- coins -=50;
- System.out.println("\nYou bought a dagger");
- option = i.nextLine().toLowerCase();
- dagger = true;
- }else{
- System.out.println("\nNot enough money!");
- option = i.nextLine().toLowerCase();
- }
- }else if(option.equals("e")){
- town();
- }else{
- option = i.nextLine().toLowerCase();
- }
- }
- }else if(option.equals("e")){
- town();
- }else{
- option = i.nextLine().toLowerCase();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment