Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MoreExercise;
- import java.util.Scanner;
- public class MuOnline {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String dungeon = scanner.nextLine();
- playDungeon(dungeon);
- scanner.close();
- }
- public static void playDungeon(String dungeon) {
- String[] rooms = dungeon.split("\\|");
- int health = 100;
- int bitcoins = 0;
- int bestRoomIndex = 0;
- for (int i = 0; i < rooms.length; i++) {
- String[] room = rooms[i].split(" ");
- String command = room[0];
- int value = Integer.parseInt(room[1]);
- switch (command) {
- case "potion":
- int healedAmount = Math.min(100 - health, value);
- health += healedAmount;
- System.out.println("You healed for " + healedAmount + " hp.");
- System.out.println("Current health: " + health + " hp.");
- break;
- case "chest":
- bitcoins += value;
- System.out.println("You found " + value + " bitcoins.");
- break;
- default:
- health -= value;
- if (health > 0) {
- System.out.println("You slayed " + command + ".");
- } else {
- System.out.println("You died! Killed by " + command + ".");
- bestRoomIndex = i; // Update the best room index without incrementing
- break;
- }
- }
- if (health <= 0) {
- break;
- }
- bestRoomIndex = i;
- }
- if (health > 0) {
- System.out.println("You've made it!");
- System.out.println("Bitcoins: " + bitcoins);
- System.out.println("Health: " + health);
- } else {
- System.out.println("Best room: " + (bestRoomIndex + 1));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement