Advertisement
mirozspace

Untitled

Feb 27th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.28 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Pr2DungeonestDark {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int healt = 100;
  7.         String[] rooms = scanner.nextLine().split("\\|");
  8.         int sumCoins = 0;
  9.         int valueBestRoom = 0;
  10.         int bestIndex = 0;
  11.         int healed = 0;
  12.         int spentHealt = 0;
  13.         for (int i = 0; i < rooms.length; i++) {
  14.             String[] command = rooms[i].split(" ");
  15.             switch (command[0]) {
  16.                 case "potion":
  17.                     if (healt + Integer.parseInt(command[1]) > 100) {
  18.                         int tempHealt = healt;
  19.                         healt = 100;
  20.                         healed = healt - tempHealt;
  21.  
  22.                     } else {
  23.                         healed = Integer.parseInt(command[1]);
  24.                         healt = healt + Integer.parseInt(command[1]);
  25.                     }
  26.                     System.out.println(String.format("You healed for %s hp.", healed));
  27.                     System.out.println(String.format("Current health: %d hp.", healt));
  28.                     break;
  29.                 case "chest":
  30.                     System.out.println(String.format("You found %s coins.", command[1]));
  31.                     sumCoins += Integer.parseInt(command[1]);
  32.                     break;
  33.                 default:
  34.                     if (Integer.parseInt(command[1]) > valueBestRoom) {
  35.                         valueBestRoom = Integer.parseInt(command[1]);
  36.                         bestIndex = i + 1;
  37.                     }
  38.                     if (healt > Integer.parseInt(command[1])) {//>=
  39.                         healt = healt - Integer.parseInt(command[1]);
  40.                         System.out.println(String.format("You slayed %s.", command[0]));
  41.                         spentHealt = spentHealt + Integer.parseInt(command[1]);
  42.                     } else {
  43.                         System.out.println(String.format("You died! Killed by %s.", command[0]));
  44.                         System.out.println(String.format("Best room: %d", bestIndex));
  45.                         return;
  46.                     }
  47.             }
  48.         }
  49.         System.out.println(String.format("You've made it!%nCoins: %d%nHealth: %d", sumCoins, healt));
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement