Advertisement
Whi7eW0lf

Untitled

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