Advertisement
N_Damyanov

02. Dungeonest Dark

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