Advertisement
SIRAKOV4444

Untitled

Apr 9th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. import java.nio.charset.IllegalCharsetNameException;
  2. import java.util.*;
  3.  
  4. public class practice{
  5. public static void main(String[]args){
  6. Scanner sc=new Scanner(System.in);
  7.  
  8. Map<String,Integer> HEROEShp = new TreeMap<>();
  9. Map<String,Integer> HEROESwp = new TreeMap<>();
  10.  
  11. int times=Integer.parseInt(sc.nextLine());
  12. for(int i=0;i<times;i++){
  13. String[]input=sc.nextLine().split("\\s+");
  14. String name=input[0];
  15. int HP=Integer.parseInt(input[1]);
  16. int MP=Integer.parseInt(input[2]);
  17.  
  18. if(!HEROEShp.containsKey(name) && !HEROESwp.containsKey(name)) {
  19. HEROEShp.put(name,HP);
  20. HEROESwp.put(name,MP);
  21. }
  22. }
  23. String input2=sc.nextLine();
  24. while(!input2.equals("End")){
  25. String[]commands=input2.split(" - ");
  26. String cases=commands[0];
  27. String heroName=commands[1];
  28. switch (cases){
  29. case"CastSpell":
  30. int neededMP=Integer.parseInt(commands[2]);
  31. String spellName=commands[3];
  32. int currentMP=HEROESwp.get(heroName);
  33. if(currentMP>=neededMP){
  34. currentMP -=neededMP;
  35. HEROESwp.put(heroName,currentMP);
  36. System.out.printf
  37. ("%s has successfully cast %s and now has %d MP!",heroName,spellName,(currentMP));
  38. System.out.println();
  39. }else{
  40. System.out.printf("%s does not have enough MP to cast %s!",heroName,spellName);
  41. System.out.println();
  42. }
  43. break;
  44. case"TakeDamage":
  45. int damage=Integer.parseInt(commands[2]);
  46. String attacker=commands[3];
  47. int currentHP=HEROEShp.get(heroName);
  48. currentHP-=damage;
  49. HEROEShp.put(heroName,currentHP);
  50. if((currentHP)>0){
  51. System.out.printf("%s was hit for %d HP by %s and now has %d HP left!",
  52. heroName,damage,attacker,(currentHP));
  53. System.out.println();
  54. }else{
  55. HEROEShp.remove(heroName);
  56. HEROESwp.remove(heroName);
  57. System.out.printf("%s has been killed by %s!",heroName,attacker);
  58. System.out.println();
  59. }
  60. break;
  61. case"Recharge":
  62. int amount=Integer.parseInt(commands[2]);
  63. int currentMP2=HEROESwp.get(heroName);
  64. if(currentMP2+amount>200){
  65. HEROESwp.put(heroName,200);
  66. System.out.printf("%s recharged for %d MP!",heroName,(200-currentMP2));
  67. System.out.println();
  68. }else{
  69. HEROESwp.put(heroName,(amount+(HEROESwp.get(heroName))));
  70. System.out.printf("%s recharged for %d MP!",heroName,(amount));
  71. System.out.println();
  72. }
  73. break;
  74. case"Heal":
  75. int amountHP= Integer.parseInt(commands[2]);
  76. int currentHP2=HEROEShp.get(heroName);
  77.  
  78. if((currentHP2+amountHP)>100){
  79. HEROEShp.put(heroName,100);
  80. System.out.printf("%s healed for %d HP!"
  81. ,heroName,(100-(currentHP2)));
  82. System.out.println();
  83. }else{
  84. HEROEShp.put(heroName,(currentHP2+amountHP));
  85. System.out.printf("%s healed for %d HP!"
  86. ,heroName,(amountHP));
  87. System.out.println();
  88. }
  89. break;
  90. default:
  91. throw new IllegalStateException("KUR KUR");
  92. }
  93. input2=sc.nextLine();
  94.  
  95. }
  96.  
  97. HEROEShp
  98. .entrySet()
  99. .stream()
  100. .sorted((n1, n2) -> n2.getValue().compareTo(n1.getValue()))
  101. .forEach(n->{
  102. String name=n.getKey();
  103. int name4=n.getValue();
  104. int name5=HEROESwp.get((name));
  105. System.out.print(name);
  106. System.out.println();
  107. System.out.printf(" HP: %d%n",name4);
  108. System.out.printf(" MP: %d%n",name5);
  109. });
  110.  
  111. }
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement