Rayk

MuOnline

Jul 13th, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.92 KB | None | 0 0
  1. package Test;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Second {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.         String[] rooms = scan.nextLine().split("\\|");
  9.         int health = 100;
  10.         int bitcoin = 0;
  11.         int bestRoom = 0;
  12.         for (int i = 0; i < rooms.length; i++) {
  13.             String[] tokens = rooms[i].split(" ");
  14.             int command = Integer.parseInt(tokens[1]);
  15.             if (tokens[0].equals("potion")){
  16.                 if (health + command <= 100){
  17.                     health += command;
  18.                     System.out.printf("You healed for %d hp.%n", command);
  19.                     System.out.printf("Current health: %d hp.%n", health);
  20.                 }else if (health + command > 100){
  21.                     int atFirst = health;
  22.                     health = 100;
  23.                     System.out.printf("You healed for %d hp.%n",100 - atFirst);
  24.                     System.out.printf("Current health: %d hp.%n", health);
  25.                 }
  26.             }else if (tokens[0].equals("chest")){
  27.                 bitcoin += command;
  28.                 System.out.printf("You found %d bitcoins.%n", command);
  29.             } else {
  30.                 if (health - command > 0){
  31.                     System.out.printf("You slew %s.%n", tokens[0]);
  32.                     health -= command;
  33.                 }else if (health - command <= 0){
  34.                     health -= command;
  35.                     System.out.printf("You died! Killed by %s.%n", tokens[0]);
  36.                     bestRoom++;
  37.                     System.out.printf("Best room: %d", bestRoom);
  38.                     break;
  39.                 }
  40.             }
  41.             bestRoom++;
  42.         }
  43.         if (health > 0){
  44.             System.out.println("You've made it!");
  45.             System.out.printf("Bitcoins: %d%n", bitcoin);
  46.             System.out.printf("Health: %d%n", health);
  47.         }
  48.     }
  49. }
Add Comment
Please, Sign In to add comment