Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.03 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.Map;
  3. import java.util.Scanner;
  4.  
  5. public class Heroes {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.         int n = Integer.parseInt(scan.nextLine());
  9.  
  10.         HashMap<String,HashMap<String,Integer>> heros = new HashMap<>();
  11.  
  12.         //heros.put("Bojo",new HashMap<>());
  13.         //heros.get("Bojo").put("Manna",100);
  14.         //heros.get("Bojo").put("HP",100);
  15.  
  16.         for (int i = 0; i < n; i++) {
  17.             String command = scan.nextLine();
  18.             String[] cmd =command.split(" ");
  19.             heros.put(cmd[0],new HashMap<>());
  20.             heros.get(cmd[0]).put("HP", Integer.parseInt(cmd[1]));
  21.             heros.get(cmd[0]).put("MP",Integer.parseInt(cmd[2]));
  22.  
  23.  
  24.         }
  25.  
  26.         while (true){
  27.             String command = scan.nextLine();
  28.             String[] commandParts =command.split(" - ");
  29.  
  30.  
  31.  
  32.             if (commandParts[0].equals("CastSpell")) {
  33.                 if (heros.get(commandParts[1]).get("MP")>Integer.parseInt(commandParts[2]) ){
  34.                     int mana = heros.get(commandParts[1]).get("MP");
  35.                     heros.get(commandParts[1]).replace("MP",mana,(mana-Integer.parseInt(commandParts[2])));
  36.                     System.out.println(commandParts[1]+" has successfully cast "+commandParts[3]+" and now has "+heros.get(commandParts[1]).get("MP")+" MP!");
  37.  
  38.                 }else{
  39.                     System.out.println(commandParts[1]+" does not have enough MP to cast "+commandParts[3]+"!");
  40.                 }
  41.  
  42.             }if (commandParts[0].equals("TakeDamage")){
  43.                 int hp=heros.get(commandParts[1]).get("HP");
  44.                 heros.get(commandParts[1]).replace("HP",(hp-Integer.parseInt(commandParts[2])));
  45.                 if (heros.get(commandParts[1]).get("HP")>0){
  46.                     System.out.println(commandParts[1]+" was hit for "+commandParts[2] +" HP by "+commandParts[3]+" and now has "+heros.get(commandParts[1]).get("HP")+" HP left!");
  47.                 }else{
  48.                     System.out.println(commandParts[1]+" has been killed by "+commandParts[3]+"!");
  49.                     heros.remove(commandParts[1]);
  50.                 }
  51.  
  52.             }if (commandParts[0].equals("Recharge")){
  53.                 int mana = heros.get(commandParts[1]).get("MP");
  54.                 int manaRechareg= 200 - heros.get(commandParts[1]).get("MP");
  55.                 heros.get(commandParts[1]).replace("MP",(Integer.parseInt(commandParts[2])+mana));
  56.  
  57.                 if (heros.get(commandParts[1]).get("MP")>200){
  58.                     heros.get(commandParts[1]).replace("MP",200);
  59.                     System.out.println(commandParts[1]+" recharged for "+manaRechareg +" MP!");
  60.  
  61.                 }else
  62.                 System.out.println(commandParts[1]+" recharged for "+commandParts[2] +" MP!");
  63.  
  64.             }if (commandParts[0].equals("Heal")){
  65.                
  66.  
  67.             }if (commandParts[0].equals("End")){
  68.                 break;
  69.             }
  70.         }
  71.  
  72.     }
  73. }
  74. //Recharge - Solmyr - 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement