Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Fundamentals.Exams.Mid;
- import java.util.Scanner;
- public class MuOnline {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int initialHealth = 100;
- int initialBitcoins = 0;
- int bestRoom = 0;
- boolean dead = false;
- String[] dungeons = scanner.nextLine().split("\\|");
- for (int i = 0; i < dungeons.length; i++) {
- String command = dungeons[i].split(" ")[0];
- int currentNumber = Integer.parseInt(dungeons[i].split(" ")[1]);
- if ("potion".equals(command)) {
- if (initialHealth < 100 && initialHealth + currentNumber <= 100) {
- initialHealth += currentNumber;
- System.out.printf("You healed for %d hp.\n", currentNumber);
- } else if (initialHealth < 100 && initialHealth + currentNumber > 100) {
- int neededHealth = 100 - initialHealth;
- initialHealth += neededHealth;
- System.out.printf("You healed for %d hp.\n", neededHealth);
- }
- System.out.println("Current health: " + initialHealth + " hp.");
- bestRoom++;
- } else if ("chest".equals(command)) {
- initialBitcoins += currentNumber;
- System.out.println("You found " + currentNumber + " bitcoins.");
- bestRoom++;
- } else {
- initialHealth -= currentNumber;
- if (initialHealth > 0) {
- System.out.printf("You slayed %s.\n", command);
- bestRoom++;
- } else {
- System.out.println("You died! Killed by " + command + ".");
- bestRoom = i + 1;
- dead = true;
- break;
- }
- }
- }
- if (!dead) {
- System.out.println("You've made it!");
- System.out.println("Bitcoins: " + initialBitcoins);
- System.out.println("Health: " + initialHealth);
- } else {
- System.out.printf("Best room: %d\n", bestRoom);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment