borovaneca

MuOnline

Feb 18th, 2023
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.18 KB | None | 0 0
  1. package Fundamentals.Exams.Mid;
  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.  
  9.  
  10.         int initialHealth = 100;
  11.         int initialBitcoins = 0;
  12.         int bestRoom = 0;
  13.         boolean dead = false;
  14.  
  15.         String[] dungeons = scanner.nextLine().split("\\|");
  16.  
  17.         for (int i = 0; i < dungeons.length; i++) {
  18.             String command = dungeons[i].split(" ")[0];
  19.             int currentNumber = Integer.parseInt(dungeons[i].split(" ")[1]);
  20.  
  21.             if ("potion".equals(command)) {
  22.                 if (initialHealth < 100 && initialHealth + currentNumber <= 100) {
  23.                     initialHealth += currentNumber;
  24.                     System.out.printf("You healed for %d hp.\n", currentNumber);
  25.                 } else if (initialHealth < 100 && initialHealth + currentNumber > 100) {
  26.                     int neededHealth = 100 - initialHealth;
  27.                     initialHealth += neededHealth;
  28.                     System.out.printf("You healed for %d hp.\n", neededHealth);
  29.                 }
  30.                 System.out.println("Current health: " + initialHealth + " hp.");
  31.                 bestRoom++;
  32.             } else if ("chest".equals(command)) {
  33.                 initialBitcoins += currentNumber;
  34.                 System.out.println("You found " + currentNumber + " bitcoins.");
  35.                 bestRoom++;
  36.             } else {
  37.                 initialHealth -= currentNumber;
  38.                 if (initialHealth > 0) {
  39.                     System.out.printf("You slayed %s.\n", command);
  40.                     bestRoom++;
  41.                 } else {
  42.                     System.out.println("You died! Killed by " + command + ".");
  43.                     bestRoom = i + 1;
  44.                     dead = true;
  45.                     break;
  46.                 }
  47.             }
  48.         }
  49.         if (!dead) {
  50.             System.out.println("You've made it!");
  51.             System.out.println("Bitcoins: " + initialBitcoins);
  52.             System.out.println("Health: " + initialHealth);
  53.         } else {
  54.             System.out.printf("Best room: %d\n", bestRoom);
  55.         }
  56.     }
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment