Advertisement
Guest User

MuOnline

a guest
Mar 1st, 2020
1,297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class MuOnline {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String[] dungeonsRooms = scanner.nextLine().split("\\|+");
  8.         int health = 100;
  9.         int bitcoins = 0;
  10.  
  11.         int bestRoom = 0;
  12.  
  13.         boolean madeIt = true;
  14.  
  15.         for (int i = 0; i < dungeonsRooms.length; i++) {
  16.             String[] tokens = dungeonsRooms[i].split("\\s+");
  17.             String command = tokens[0];
  18.             int number = Integer.parseInt(tokens[1]);
  19.             bestRoom++;
  20.  
  21.             if (command.equalsIgnoreCase("potion")) {
  22.                 int currentHealth = health;
  23.                 health += number;
  24.                 if (health > 100) {
  25.                     health = 100;
  26.                     int amount = 100 - currentHealth;
  27.                     System.out.printf("You healed for %d hp.%n", amount);
  28.                 } else {
  29.                     System.out.printf("You healed for %d hp.%n", number);
  30.                 }
  31.                 System.out.printf("Current health: %d hp.%n", health);
  32.             } else if (command.equalsIgnoreCase("chest")) {
  33.                 bitcoins += number;
  34.                 System.out.printf("You found %d bitcoins.%n", number);
  35.  
  36.             } else {
  37.                 health -= number;
  38.                 if (health > 0) {
  39.                     System.out.printf("You slayed %s.%n", command);
  40.                 } else {
  41.                     System.out.printf("You died! Killed by %s.%n", command);
  42.                     System.out.printf("Best room: %d", bestRoom);
  43.                     madeIt = false;
  44.                     break;
  45.                 }
  46.             }
  47.         }
  48.         if (madeIt) {
  49.             System.out.println("You've made it!");
  50.             System.out.printf("Bitcoins: %d%n", bitcoins);
  51.             System.out.printf("Health: %d%n", health);
  52.         }
  53.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement