Advertisement
Ligh7_of_H3av3n

MuOnline

Feb 12th, 2024
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.05 KB | None | 0 0
  1. package MoreExercise;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class MuOnline {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String dungeon = scanner.nextLine();
  9.         playDungeon(dungeon);
  10.         scanner.close();
  11.     }
  12.  
  13.     public static void playDungeon(String dungeon) {
  14.         String[] rooms = dungeon.split("\\|");
  15.         int health = 100;
  16.         int bitcoins = 0;
  17.         int bestRoomIndex = 0;
  18.  
  19.         for (int i = 0; i < rooms.length; i++) {
  20.             String[] room = rooms[i].split(" ");
  21.             String command = room[0];
  22.             int value = Integer.parseInt(room[1]);
  23.  
  24.             switch (command) {
  25.                 case "potion":
  26.                     int healedAmount = Math.min(100 - health, value);
  27.                     health += healedAmount;
  28.                     System.out.println("You healed for " + healedAmount + " hp.");
  29.                     System.out.println("Current health: " + health + " hp.");
  30.                     break;
  31.                 case "chest":
  32.                     bitcoins += value;
  33.                     System.out.println("You found " + value + " bitcoins.");
  34.                     break;
  35.                 default:
  36.                     health -= value;
  37.                     if (health > 0) {
  38.                         System.out.println("You slayed " + command + ".");
  39.                     } else {
  40.                         System.out.println("You died! Killed by " + command + ".");
  41.                         bestRoomIndex = i; // Update the best room index without incrementing
  42.                         break;
  43.                     }
  44.             }
  45.  
  46.             if (health <= 0) {
  47.                 break;
  48.             }
  49.  
  50.             bestRoomIndex = i;
  51.         }
  52.  
  53.         if (health > 0) {
  54.             System.out.println("You've made it!");
  55.             System.out.println("Bitcoins: " + bitcoins);
  56.             System.out.println("Health: " + health);
  57.         } else {
  58.             System.out.println("Best room: " + (bestRoomIndex + 1));
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement