Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Izpit;
- import java.util.Scanner;
- public class wda {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] rooms = scanner.nextLine().split("\\|");
- int health = 100;
- int bitcoins = 0;
- int roomsGot = 0;
- for (String room : rooms) {
- roomsGot++;
- String[] parts = room.split("\\s+");
- String name = parts[0];
- int number = Integer.parseInt(parts[1]);
- switch (name) {
- case "potion":
- int healing = Math.min(100 - health, number);
- health += healing;
- System.out.printf("You healed for %d hp.%n", healing);
- System.out.printf("Current health: %d hp.%n", health);
- break;
- case "chest":
- bitcoins += number;
- System.out.printf("You found %d bitcoins.%n", number);
- break;
- default:
- health -= number;
- if (health > 0) {
- System.out.printf("You slayed %s.%n", name);
- } else {
- System.out.printf("You died! Killed by %s.%n", name);
- System.out.printf("Best room: %d%n", roomsGot);
- return;
- }
- break;
- }
- }
- System.out.println("You've made it!");
- System.out.printf("Bitcoins: %d%n", bitcoins);
- System.out.printf("Health: %d%n", health);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement