Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- class Mu {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] split = scanner.nextLine().split("\\|");
- List<String> dungeons = new ArrayList<>(Arrays.asList(split));
- int maxHealth = 100;
- int health = 100;
- int bitcoins = 0;
- boolean isOver = false;
- for (int i = 0; i < dungeons.size(); i++) {
- String get = dungeons.get(i);
- String[] tokens = get.split(" ");
- String command = tokens[0];
- switch (command) {
- case "potion": {
- int num = Integer.parseInt(tokens[1]);
- int temp = health + num;
- if (maxHealth < temp) {
- int hp = maxHealth - health;
- health = maxHealth;
- System.out.printf("You healed for %d hp.%n", hp);
- System.out.printf("Current health: %d hp.%n", health);
- } else {
- health += num;
- System.out.printf("You healed for %d hp.%n", num);
- System.out.printf("Current health: %d hp.%n", health);
- }
- break;
- }
- case "chest": {
- int coins = Integer.parseInt(tokens[1]);
- System.out.printf("You found %d bitcoins.%n", coins);
- bitcoins += coins;
- break;
- }
- default: {
- int damage = Integer.parseInt(tokens[1]);
- String monsterName = tokens[0];
- health -= damage;
- if (health <= 0) {
- System.out.printf("You died! Killed by %s.%n", monsterName);
- System.out.printf("Best room: %d%n", i + 1);
- return;
- } else {
- System.out.printf("You slayed %s.%n", monsterName);
- }
- break;
- }
- }
- if (i == dungeons.size() - 1) {
- isOver = true;
- }
- }
- if (isOver) {
- System.out.println("You've made it!");
- System.out.printf("Bitcoins: %d%n", bitcoins);
- System.out.printf("Health: %d", health);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement