Advertisement
Guest User

P02_DangeonDark

a guest
Dec 17th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.28 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.ArrayDeque;
  5. import java.util.Collections;
  6.  
  7. public class P02_DangeonDark {
  8.     public static void main(String[] args) throws IOException {
  9.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  10.  
  11.         int initialHeath = 100;
  12.         int initialCoins = 0;
  13.  
  14.         String[] inputLine = reader.readLine().split("\\|");
  15.  
  16.         ArrayDeque<String> quest = new ArrayDeque<>();
  17.  
  18.         Collections.addAll(quest, inputLine);
  19.  
  20.         int room = 0;
  21.  
  22.         while (!quest.isEmpty()) {
  23.             room++;
  24.             String[] tokens = quest.pop().split("\\s+");
  25.  
  26.             String item = tokens[0];
  27.             int number = Integer.parseInt(tokens[1]);
  28.  
  29.             switch (item) {
  30.                 case "potion":
  31.                     int pointForHealth = initialHeath + number;
  32.  
  33.                     if (pointForHealth > 100) {
  34.                         int regenPoints = 100 - initialHeath;
  35.                         initialHeath = 100;
  36.                         System.out.printf("You healed for %d hp.\n", regenPoints);
  37.                     } else {
  38.                         System.out.printf("You healed for %d hp.\n", number);
  39.                         initialHeath = pointForHealth;
  40.                     }
  41.  
  42.                     System.out.printf("Current health: %d hp.\n", initialHeath);
  43.  
  44.                     break;
  45.                 case "chest":
  46.                     initialCoins += number;
  47.                     System.out.printf("You found %d coins.\n", number);
  48.                     break;
  49.                 default:
  50.                     int currentHealth = initialHeath - number;
  51.  
  52.                     if (currentHealth <= 0) {
  53.                         System.out.printf("You died! Killed by %s.\n", item);
  54.                         System.out.printf("Best room: %d\n", room);
  55.                         return;
  56.                     } else {
  57.                         System.out.printf("You slayed %s.\n", item);
  58.                         initialHeath = currentHealth;
  59.                     }
  60.  
  61.                     break;
  62.             }
  63.         }
  64.         System.out.printf("You've made it!\nCoins: %d\nHealth: %d\n", initialCoins, initialHeath);
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement