Advertisement
Guest User

2.MuOnline

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