Didart

MuOnline

Oct 21st, 2021
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 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[] room1 = scanner.nextLine().split("\\|");
  8.         int health = 100;
  9.         int bitcoins = 0;
  10.  
  11.         int room2 = 0;
  12.         for (String room : room1) {
  13.             room2++;
  14.             String[] tokens = room.split("\\s+");
  15.             String command = tokens[0];
  16.             if ("potion".equals(command)) {
  17.                 int number = Integer.parseInt(tokens[1]);
  18.                 if (health < 100) {
  19.                     health += number;
  20.                     if (health > 100) {
  21.                         number = Math.abs((health - 100) - number);
  22.                         health = 100;
  23.                     }
  24.                 }
  25.                 System.out.printf("You healed for %d hp.%n", number);
  26.                 System.out.printf("Current health: %d hp.%n", health);
  27.             } else if ("chest".equals(command)) {
  28.                 int bitcoinsQuantity = Integer.parseInt(tokens[1]);
  29.                 bitcoins += bitcoinsQuantity;
  30.                 System.out.printf("You found %d bitcoins.%n", bitcoinsQuantity);
  31.             } else {
  32.                 int monsterAttack = Integer.parseInt(tokens[1]);
  33.                 health -= monsterAttack;
  34.                 if (health <= 0) {
  35.                     System.out.printf("You died! Killed by %s.%n", command);
  36.                     System.out.printf("Best room: %d%n", room2);
  37.                     return;
  38.                 } else {
  39.                     System.out.printf("You slayed %s.%n", command);
  40.                 }
  41.             }
  42.         }
  43.         System.out.printf("You've made it!%n" +
  44.                 "Bitcoins: %d%n" +
  45.                 "Health: %d", bitcoins, health);
  46.     }
  47. }
  48.  
  49.  
  50.  
Advertisement
Add Comment
Please, Sign In to add comment