Advertisement
Ligh7_of_H3av3n

Fixed Code !!!

Feb 16th, 2024
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 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.             String name = room.split(" ")[0];
  17.             int number = Integer.parseInt(room.split(" ")[1]);
  18.             roomsGot++;
  19.  
  20.             switch (name) {
  21.                 case "potion":
  22.                     int healing = Math.min(100 - health, number);
  23.                     health += healing;
  24.                     System.out.printf("You healed for %d hp.%n", healing);
  25.                     System.out.printf("Current health: %d hp.%n", health);
  26.                     break;
  27.                 case "chest":
  28.                     bitcoins += number;
  29.                     System.out.printf("You found %d bitcoins.%n", number);
  30.                     break;
  31.                 default:
  32.                     health -= number;
  33.                     // facing a monster
  34.                     if (health > 0) {
  35.                         System.out.printf("You slayed %s.%n", name);
  36.                     } else {
  37.                         System.out.printf("You died! Killed by %s.%n", name);
  38.                         System.out.printf("Best room: %d%n", roomsGot);
  39.                         return;
  40.                     }
  41.                     break;
  42.             }
  43.         }
  44.  
  45.         System.out.print("You've made it!\nBitcoins: " + bitcoins + "\nHealth: " + health);
  46.     }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement