Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class Heroes {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int n = Integer.parseInt(scan.nextLine());
- HashMap<String,HashMap<String,Integer>> heros = new HashMap<>();
- //heros.put("Bojo",new HashMap<>());
- //heros.get("Bojo").put("Manna",100);
- //heros.get("Bojo").put("HP",100);
- for (int i = 0; i < n; i++) {
- String command = scan.nextLine();
- String[] cmd =command.split(" ");
- heros.put(cmd[0],new HashMap<>());
- heros.get(cmd[0]).put("HP", Integer.parseInt(cmd[1]));
- heros.get(cmd[0]).put("MP",Integer.parseInt(cmd[2]));
- }
- while (true){
- String command = scan.nextLine();
- String[] commandParts =command.split(" - ");
- if (commandParts[0].equals("CastSpell")) {
- if (heros.get(commandParts[1]).get("MP")>Integer.parseInt(commandParts[2]) ){
- int mana = heros.get(commandParts[1]).get("MP");
- heros.get(commandParts[1]).replace("MP",mana,(mana-Integer.parseInt(commandParts[2])));
- System.out.println(commandParts[1]+" has successfully cast "+commandParts[3]+" and now has "+heros.get(commandParts[1]).get("MP")+" MP!");
- }else{
- System.out.println(commandParts[1]+" does not have enough MP to cast "+commandParts[3]+"!");
- }
- }if (commandParts[0].equals("TakeDamage")){
- int hp=heros.get(commandParts[1]).get("HP");
- heros.get(commandParts[1]).replace("HP",(hp-Integer.parseInt(commandParts[2])));
- if (heros.get(commandParts[1]).get("HP")>0){
- 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!");
- }else{
- System.out.println(commandParts[1]+" has been killed by "+commandParts[3]+"!");
- heros.remove(commandParts[1]);
- }
- }if (commandParts[0].equals("Recharge")){
- int mana = heros.get(commandParts[1]).get("MP");
- int manaRechareg= 200 - heros.get(commandParts[1]).get("MP");
- heros.get(commandParts[1]).replace("MP",(Integer.parseInt(commandParts[2])+mana));
- if (heros.get(commandParts[1]).get("MP")>200){
- heros.get(commandParts[1]).replace("MP",200);
- System.out.println(commandParts[1]+" recharged for "+manaRechareg +" MP!");
- }else
- System.out.println(commandParts[1]+" recharged for "+commandParts[2] +" MP!");
- }if (commandParts[0].equals("Heal")){
- }if (commandParts[0].equals("End")){
- break;
- }
- }
- }
- }
- //Recharge - Solmyr - 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement