RGAlex

O2 Mu Online / O5. Mid Exam Retake

Feb 26th, 2021
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. package MidExam.O5;
  2.  
  3. import java.util.Arrays;
  4. import java.util.List;
  5. import java.util.Scanner;
  6. import java.util.stream.Collectors;
  7.  
  8. public class O2MuOnline {
  9.     public static void main(String[] args) {
  10.         Scanner scanner = new Scanner(System.in);
  11.         int health = 100;
  12.         int bitcoin = 0;
  13.         int room = 0;
  14.  
  15.         List<String> test = Arrays.stream(scanner.nextLine().split("\\|")).
  16.                 map(String::toString).collect(Collectors.toList());
  17.         while (room < test.size()) {
  18.             String command = test.get(room).split("\\s+")[0];
  19.             int number = Integer.parseInt(test.get(room).split("\\s+")[1]);
  20.             if (command.equals("potion")) {
  21.                 if (health < 100) {
  22.                     int a = health;
  23.                     health += number;
  24.                     if (health > 100) {
  25.                         number = 100 - a;
  26.                         health = 100;
  27.                     }
  28.                     System.out.printf("You healed for %d hp.%n", number);
  29.                     System.out.printf("Current health: %d hp.%n", health);
  30.                 }
  31.  
  32.             } else if (command.equals("chest")) {
  33.                 bitcoin += number;
  34.                 System.out.printf("You found %d bitcoins.%n", number);
  35.             } else {
  36.                 health -= number;
  37.                 if (health <= 0) {
  38.                     System.out.printf("You died! Killed by %s.%n", command);
  39.                     System.out.printf("Best room: %d", room + 1);
  40.                     return;
  41.                 } else {
  42.                     System.out.printf("You slayed %s.%n", command);
  43.                 }
  44.             }
  45.             room++;
  46.         }
  47.         System.out.printf("You've made it!%n" + "Bitcoins: %d%n" + "Health: %d", bitcoin, health);
  48.     }
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment