Advertisement
SIRAKOV4444

Untitled

Apr 9th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.91 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. if((HEROESwp.get(heroName)+amount)>200){
  64. HEROESwp.put(heroName,200);
  65. System.out.printf("%s recharged for %d MP!",heroName,(200-HEROESwp.get(heroName)));
  66. System.out.println();
  67. }else{
  68. HEROESwp.put(heroName,(amount+(HEROESwp.get(heroName))));
  69. System.out.printf("%s recharged for %d MP!",heroName,(amount));
  70. System.out.println();
  71. }
  72. break;
  73. case"Heal":
  74. int amountHP= Integer.parseInt(commands[2]);
  75. int currentHP2=HEROEShp.get(heroName);
  76.  
  77. if((currentHP2+amountHP)>100){
  78. HEROEShp.put(heroName,100);
  79. System.out.printf("%s healed for %d HP!"
  80. ,heroName,(100-(currentHP2)));
  81. System.out.println();
  82. }else{
  83. HEROEShp.put(heroName,(currentHP2+amountHP));
  84. System.out.printf("%s healed for %d HP!"
  85. ,heroName,(amountHP));
  86. System.out.println();
  87. }
  88. break;
  89. default:
  90. throw new IllegalStateException("KUR KUR");
  91. }
  92. input2=sc.nextLine();
  93.  
  94. }
  95.  
  96. HEROEShp
  97. .entrySet()
  98. .stream()
  99. .sorted((n1, n2) -> n2.getValue().compareTo(n1.getValue()))
  100. .forEach(n -> {
  101. System.out.println(n.getKey());
  102. System.out.printf(" HP:%d%n",n.getValue());
  103. HEROESwp
  104. .entrySet()
  105. .stream()
  106. .sorted((n1, n2) -> n1.getValue().compareTo(n2.getValue()))
  107. .forEach(n5 ->{
  108. //System.out.println(n5.getKey());
  109. System.out.printf(" MP:%d%n",n5.getValue());
  110. });
  111. });
  112.  
  113. }
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement