Advertisement
Ligh7_of_H3av3n

fixed code

Feb 16th, 2024
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. package Izpit;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class wda {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.  
  10.         String[] rooms = scanner.nextLine().split("\\|");
  11.         int health = 100;
  12.         int bitcoins = 0;
  13.         int roomsGot = 0;
  14.  
  15.         for (String room : rooms) {
  16.             roomsGot++;
  17.  
  18.             String[] parts = room.split("\\s+");
  19.             String name = parts[0];
  20.             int number = Integer.parseInt(parts[1]);
  21.  
  22.             switch (name) {
  23.                 case "potion":
  24.                     int healing = Math.min(100 - health, number);
  25.                     health += healing;
  26.                     System.out.printf("You healed for %d hp.%n", healing);
  27.                     System.out.printf("Current health: %d hp.%n", health);
  28.                     break;
  29.                 case "chest":
  30.                     bitcoins += number;
  31.                     System.out.printf("You found %d bitcoins.%n", number);
  32.                     break;
  33.                 default:
  34.                     health -= number;
  35.                     if (health > 0) {
  36.                         System.out.printf("You slayed %s.%n", name);
  37.                     } else {
  38.                         System.out.printf("You died! Killed by %s.%n", name);
  39.                         System.out.printf("Best room: %d%n", roomsGot);
  40.                         return;
  41.                     }
  42.                     break;
  43.             }
  44.         }
  45.  
  46.         System.out.println("You've made it!");
  47.         System.out.printf("Bitcoins: %d%n", bitcoins);
  48.         System.out.printf("Health: %d%n", health);
  49.     }
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement