Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class MuOnline {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] room1 = scanner.nextLine().split("\\|");
- int health = 100;
- int bitcoins = 0;
- int room2 = 0;
- for (String room : room1) {
- room2++;
- String[] tokens = room.split("\\s+");
- String command = tokens[0];
- if ("potion".equals(command)) {
- int number = Integer.parseInt(tokens[1]);
- if (health < 100) {
- health += number;
- if (health > 100) {
- number = Math.abs((health - 100) - number);
- health = 100;
- }
- }
- System.out.printf("You healed for %d hp.%n", number);
- System.out.printf("Current health: %d hp.%n", health);
- } else if ("chest".equals(command)) {
- int bitcoinsQuantity = Integer.parseInt(tokens[1]);
- bitcoins += bitcoinsQuantity;
- System.out.printf("You found %d bitcoins.%n", bitcoinsQuantity);
- } else {
- int monsterAttack = Integer.parseInt(tokens[1]);
- health -= monsterAttack;
- if (health <= 0) {
- System.out.printf("You died! Killed by %s.%n", command);
- System.out.printf("Best room: %d%n", room2);
- return;
- } else {
- System.out.printf("You slayed %s.%n", command);
- }
- }
- }
- System.out.printf("You've made it!%n" +
- "Bitcoins: %d%n" +
- "Health: %d", bitcoins, health);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment