SHARE
TWEET

Untitled

shniaga Feb 18th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package MidExamTechNov42018;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class DungeonestDark {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String input = scanner.nextLine();
  10.         String[] rooms = input.split("\\|");
  11.         int initialHealth = 100;
  12.         boolean isDead = false;
  13.         int countRooms = 0;
  14.         int coins = 0;
  15.  
  16.         for (int i = 0; i < rooms.length; i++) {
  17.             countRooms++;
  18.             String[] currentRoom = rooms[i].split(" ");
  19.             int number = Integer.parseInt(currentRoom[1]);
  20.             if (currentRoom[0].equals("chest")) {
  21.                 coins += number;
  22.                 System.out.println(String.format("You found %s coins.", currentRoom[1]));
  23.             } else if (currentRoom[0].equals("potion")) {
  24.                 if (initialHealth == 100 || number <= 0) {
  25.                     System.out.println("You healed for 0 hp.");
  26.                     System.out.println(String.format("Current health: 100 hp."));
  27.                 } else if (100 - initialHealth <= number) {
  28.                     System.out.println(String.format("You healed for %d hp.", 100 - initialHealth));
  29.                     initialHealth = 100;
  30.                     System.out.println(String.format("Current health: %d hp.", initialHealth));
  31.                 } else {
  32.                     initialHealth += number;
  33.                     System.out.println(String.format("You healed for %d hp.", number));
  34.                     System.out.println(String.format("Current health: %d hp.", initialHealth));
  35.                 }
  36.             } else {
  37.                 if (initialHealth <= number) {
  38.                     System.out.println(String.format("You died! Killed by %s.", currentRoom[0]));
  39.                     System.out.println(String.format("Best room: %d", countRooms));
  40.                     isDead = true;
  41.                     break;
  42.                 } else {
  43.                     initialHealth -= number;
  44.                     System.out.println(String.format("You slayed %s.", currentRoom[0]));
  45.                 }
  46.             }
  47.         }
  48.         if (!isDead) {
  49.             System.out.println("You've made it!");
  50.             System.out.println(String.format("Coins: %d", coins));
  51.             System.out.println(String.format("Health: %d", initialHealth));
  52.         }
  53.     }
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top