Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.ArrayDeque;
- import java.util.Collections;
- public class P02_DangeonDark {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- int initialHeath = 100;
- int initialCoins = 0;
- String[] inputLine = reader.readLine().split("\\|");
- ArrayDeque<String> quest = new ArrayDeque<>();
- Collections.addAll(quest, inputLine);
- int room = 0;
- while (!quest.isEmpty()) {
- room++;
- String[] tokens = quest.pop().split("\\s+");
- String item = tokens[0];
- int number = Integer.parseInt(tokens[1]);
- switch (item) {
- case "potion":
- int pointForHealth = initialHeath + number;
- if (pointForHealth > 100) {
- int regenPoints = 100 - initialHeath;
- initialHeath = 100;
- System.out.printf("You healed for %d hp.\n", regenPoints);
- } else {
- System.out.printf("You healed for %d hp.\n", number);
- initialHeath = pointForHealth;
- }
- System.out.printf("Current health: %d hp.\n", initialHeath);
- break;
- case "chest":
- initialCoins += number;
- System.out.printf("You found %d coins.\n", number);
- break;
- default:
- int currentHealth = initialHeath - number;
- if (currentHealth <= 0) {
- System.out.printf("You died! Killed by %s.\n", item);
- System.out.printf("Best room: %d\n", room);
- return;
- } else {
- System.out.printf("You slayed %s.\n", item);
- initialHeath = currentHealth;
- }
- break;
- }
- }
- System.out.printf("You've made it!\nCoins: %d\nHealth: %d\n", initialCoins, initialHeath);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement