Advertisement
ilianrusev

Dungeonest Dark

Feb 27th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.04 KB | None | 0 0
  1. package com.company;
  2.  
  3.  
  4. import java.util.Arrays;
  5. import java.util.Scanner;
  6.  
  7.  
  8. public class Main {
  9.  
  10.     public static void main(String[] args) {
  11.         Scanner scanner = new Scanner(System.in);
  12.  
  13.         int health = 100;
  14.         int maxHealth = 100;
  15.         int coins = 0;
  16.         String input = scanner.nextLine();
  17.         String[] rooms = input.split("[\\s+|]");
  18.         String[] roomsNumbers = input.split("[|]");
  19.         System.out.println();
  20.         for (int i = 0; i < rooms.length; i+=2) {
  21.             int number = Integer.parseInt(rooms[i+1]);
  22.             int healedFor=0;
  23.             switch (rooms[i]){
  24.  
  25.                 case "potion":
  26.                     //health += number;
  27.                     if (health + number > 100){
  28.                         healedFor=100-health;
  29.                         health = maxHealth;
  30.                     }else{
  31.                         healedFor=number;
  32.                         health+=number;
  33.                     }
  34.                     System.out.printf("You healed for %d hp.\n",healedFor);
  35.                     System.out.printf("Current health: %d hp.\n",health);
  36.                     break;
  37.                 case "chest":
  38.                     coins += number;
  39.                     System.out.printf("You found %d coins.\n",number);
  40.                     break;
  41.                 default:
  42.                     health -= number;
  43.                     if (health > 0){
  44.                         System.out.printf("You slayed %s.\n",rooms[i]);
  45.  
  46.                     }else {
  47.                         System.out.printf("You died! Killed by %s.\n",rooms[i]);
  48.                         int index=Arrays.asList(roomsNumbers).indexOf(rooms[i]+" "+rooms[i+1])+1;
  49.                         System.out.printf("Best room: %d\n",index );
  50.                         return;
  51.  
  52.                     }
  53.  
  54.  
  55.  
  56.             }
  57.  
  58.         }
  59.         if (health > 0) {
  60.             System.out.println("You've made it!");
  61.             System.out.printf("Coins: %d\n",coins);
  62.             System.out.printf("Health: %d\n",health);
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement