Advertisement
veronikaaa86

02. MuOnline

Jun 21st, 2022
678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. package examPrep;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P02MuOnline {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. String[] roomsArr = scanner.nextLine().split("\\|");
  10.  
  11. boolean isDead = false;
  12. int health = 100;
  13. int bitcoins = 0;
  14. for (int i = 0; i < roomsArr.length; i++) {
  15. String[] room = roomsArr[i].split(" ");
  16. String command = room[0];
  17. int num = Integer.parseInt(room[1]);
  18.  
  19. switch (command) {
  20. case "potion":
  21. int diffHealth = 100 - health;
  22. health = health + num;
  23. if (health > 100) {
  24. num = diffHealth;
  25. health = 100;
  26. }
  27. System.out.printf("You healed for %d hp.%n", num);
  28. System.out.printf("Current health: %d hp.%n", health);
  29. break;
  30. case "chest":
  31. System.out.printf("You found %d bitcoins.%n", num);
  32. bitcoins += num;
  33. break;
  34. default:
  35. health = health - num;
  36. if (health <= 0) {
  37. isDead = true;
  38. System.out.printf("You died! Killed by %s.%n", command);
  39. System.out.printf("Best room: %d%n", i + 1);
  40. } else {
  41. System.out.printf("You slayed %s.%n", command);
  42. }
  43. break;
  44. }
  45.  
  46. if (isDead) {
  47. break;
  48. }
  49. }
  50.  
  51. if (!isDead) {
  52. System.out.println("You've made it!");
  53. System.out.printf("Bitcoins: %d%n", bitcoins);
  54. System.out.printf("Health: %d%n", health);
  55. }
  56. }
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement