Advertisement
MeGaM1nd

Untitled

Apr 2nd, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.List;
  4. import java.util.Scanner;
  5.  
  6. class Mu {
  7. public static void main(String[] args) {
  8.  
  9. Scanner scanner = new Scanner(System.in);
  10.  
  11. String[] split = scanner.nextLine().split("\\|");
  12.  
  13. List<String> dungeons = new ArrayList<>(Arrays.asList(split));
  14.  
  15. int maxHealth = 100;
  16. int health = 100;
  17. int bitcoins = 0;
  18. boolean isOver = false;
  19.  
  20. for (int i = 0; i < dungeons.size(); i++) {
  21.  
  22. String get = dungeons.get(i);
  23. String[] tokens = get.split(" ");
  24. String command = tokens[0];
  25.  
  26. switch (command) {
  27. case "potion": {
  28. int num = Integer.parseInt(tokens[1]);
  29. int temp = health + num;
  30. if (maxHealth < temp) {
  31. int hp = maxHealth - health;
  32. health = maxHealth;
  33. System.out.printf("You healed for %d hp.%n", hp);
  34. System.out.printf("Current health: %d hp.%n", health);
  35.  
  36. } else {
  37. health += num;
  38. System.out.printf("You healed for %d hp.%n", num);
  39. System.out.printf("Current health: %d hp.%n", health);
  40.  
  41. }
  42. break;
  43.  
  44. }
  45. case "chest": {
  46. int coins = Integer.parseInt(tokens[1]);
  47. System.out.printf("You found %d bitcoins.%n", coins);
  48. bitcoins += coins;
  49. break;
  50.  
  51. }
  52. default: {
  53. int damage = Integer.parseInt(tokens[1]);
  54. String monsterName = tokens[0];
  55. health -= damage;
  56. if (health <= 0) {
  57. System.out.printf("You died! Killed by %s.%n", monsterName);
  58. System.out.printf("Best room: %d%n", i + 1);
  59. return;
  60. } else {
  61. System.out.printf("You slayed %s.%n", monsterName);
  62. }
  63. break;
  64. }
  65. }
  66. if (i == dungeons.size() - 1) {
  67. isOver = true;
  68. }
  69. }
  70. if (isOver) {
  71. System.out.println("You've made it!");
  72. System.out.printf("Bitcoins: %d%n", bitcoins);
  73. System.out.printf("Health: %d", health);
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement