Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.13 KB | None | 0 0
  1. package PF_Exam;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.LinkedHashMap;
  5. import java.util.Map;
  6. import java.util.Scanner;
  7.  
  8. public class Heros_of_Code {
  9.     public static void main(String[] args) {
  10.         Scanner scanner = new Scanner(System.in);
  11.  
  12.         int n = Integer.parseInt(scanner.nextLine());
  13.         Map<String, ArrayList<Integer>> heros = new LinkedHashMap<>();
  14.  
  15.         //GET HEROS
  16.         for (int i = 0; i < n; i++) {
  17.             String[] tokens = scanner.nextLine().split("\\s+");
  18.             String name = tokens[0];
  19.             int HP = Integer.parseInt(tokens[1]);
  20.             int MP = Integer.parseInt(tokens[2]);
  21.             heros.putIfAbsent(name, new ArrayList<>());
  22.             heros.get(name).add(HP);
  23.             heros.get(name).add(MP);
  24.         }
  25.  
  26.         //PLAY GAME
  27.         //{hero name} {HP} {MP}
  28.         String input = scanner.nextLine();
  29.         while (!"End".equals(input)) {
  30.             String[] tokens = input.split(" - ");
  31.             String action = tokens[0];
  32.             String heroName = tokens[1];
  33.  
  34.             switch (action) {
  35.                 case "CastSpell":
  36.                     //CastSpell – {hero name} – {MP needed} – {spell name}
  37.                     int reqMP = Integer.parseInt(tokens[2]);
  38.                     String spellName = tokens[3];
  39.                     int currentMP = heros.get(heroName).get(1);
  40.                     if (currentMP > reqMP) {
  41.                         currentMP -= reqMP;
  42.                         heros.get(heroName).set(1, currentMP);
  43.                         System.out.printf("%s has successfully cast %s and now has %d MP!%n", heroName, spellName, currentMP);
  44.                     } else {
  45.                         System.out.printf("%s does not have enough MP to cast %s!%n", heroName, spellName);
  46.                     }
  47.                     break;
  48.  
  49.                 case "TakeDamage":
  50.                     break;
  51.  
  52.                 case "Recharge":
  53.                     break;
  54.  
  55.                 case "Heal":
  56.                     break;
  57.  
  58.             }
  59.  
  60.             input = scanner.nextLine();
  61.         }
  62.  
  63.         System.out.println("TEST");
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement