Advertisement
Whi7eW0lf

Untitled

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