Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package PF_Exam;
- import java.util.ArrayList;
- import java.util.LinkedHashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class Heros_of_Code {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- Map<String, ArrayList<Integer>> heros = new LinkedHashMap<>();
- //GET HEROS
- for (int i = 0; i < n; i++) {
- String[] tokens = scanner.nextLine().split("\\s+");
- String name = tokens[0];
- int HP = Integer.parseInt(tokens[1]);
- int MP = Integer.parseInt(tokens[2]);
- heros.putIfAbsent(name, new ArrayList<>());
- heros.get(name).add(HP);
- heros.get(name).add(MP);
- }
- //PLAY GAME
- //{hero name} {HP} {MP}
- String input = scanner.nextLine();
- while (!"End".equals(input)) {
- String[] tokens = input.split(" - ");
- String action = tokens[0];
- String heroName = tokens[1];
- switch (action) {
- case "CastSpell":
- //CastSpell – {hero name} – {MP needed} – {spell name}
- int reqMP = Integer.parseInt(tokens[2]);
- String spellName = tokens[3];
- int currentMP = heros.get(heroName).get(1);
- if (currentMP > reqMP) {
- currentMP -= reqMP;
- heros.get(heroName).set(1, currentMP);
- System.out.printf("%s has successfully cast %s and now has %d MP!%n", heroName, spellName, currentMP);
- } else {
- System.out.printf("%s does not have enough MP to cast %s!%n", heroName, spellName);
- }
- break;
- case "TakeDamage":
- break;
- case "Recharge":
- break;
- case "Heal":
- break;
- }
- input = scanner.nextLine();
- }
- System.out.println("TEST");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement