Advertisement
ivanov_ivan

TheHeiganDance

Apr 22nd, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.06 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Scanner;
  4.  
  5. public class TheHeiganDance { //100/100
  6.     private static boolean isCloudOn;
  7.     private static boolean isEruptionOn;
  8.     private static int playerRow = 7;
  9.     private static int playerColumn = 7;
  10.     private static boolean isHeiganDead = false;
  11.     private static boolean isPlayerDead = false;
  12.  
  13.     public static void main(String[] args) {
  14.         Scanner sc = new Scanner(System.in);
  15.  
  16.         double playerDamage = Double.parseDouble(sc.nextLine());
  17.  
  18.         int plegueCloudDamage = 3500;
  19.         int eruptionDamage = 6000;
  20.  
  21.         int playerHealth = 18500;
  22.         double heiganHealth = 3000000.00;
  23.  
  24.         String input = sc.nextLine();
  25.         String lastSpell = "";
  26.  
  27.         while (true) {
  28.             heiganHealth -= playerDamage;
  29.             if (checkForDead(playerHealth, heiganHealth)) break;
  30.             if (isCloudOn) {
  31.                 playerHealth -= plegueCloudDamage;
  32.                 isCloudOn = false;
  33.             }
  34.             if (!isCloudOn && isEruptionOn) {
  35.                 playerHealth -= eruptionDamage;
  36.             }
  37.             String[] spellCoord = input.split("\\s+");
  38.             String spell = spellCoord[0];
  39.             int spellRow = Integer.parseInt(spellCoord[1]);
  40.             int spellColumn = Integer.parseInt(spellCoord[2]);
  41.  
  42.             List<Integer> rowsHitted = new ArrayList<>();
  43.             rowsHitted.add((spellRow - 1) < 0 ? 0 : (spellRow - 1));
  44.             rowsHitted.add(spellRow);
  45.             rowsHitted.add((spellRow + 1) >= 15 ? 14 : (spellRow + 1));
  46.  
  47.             List<Integer> columnsHitted = new ArrayList<>();
  48.             columnsHitted.add((spellColumn - 1) < 0 ? 0 : (spellColumn - 1));
  49.             columnsHitted.add(spellColumn);
  50.             columnsHitted.add((spellColumn + 1) >= 15 ? 14 : (spellColumn + 1));
  51.             switch (spell) {
  52.                 case "Cloud":
  53.                     if (isPlayerHit(playerRow, playerColumn, rowsHitted, columnsHitted) && !isPlayerEscape(playerRow, playerColumn, rowsHitted, columnsHitted)) {
  54.                         isCloudOn = true;
  55.                         playerHealth -= plegueCloudDamage;
  56.                     }
  57.                     break;
  58.                 case "Eruption":
  59.                     if (isPlayerHit(playerRow, playerColumn, rowsHitted, columnsHitted) && !isPlayerEscape(playerRow, playerColumn, rowsHitted, columnsHitted)) {
  60.                         if (isCloudOn) {
  61.                             isEruptionOn = true;
  62.                         } else {
  63.                             playerHealth -= eruptionDamage;
  64.                         }
  65.                     }
  66.                     break;
  67.             }
  68.             if (spell.equals("Cloud")) {
  69.                 lastSpell = "Plague Cloud";
  70.             } else {
  71.                 lastSpell = spell;
  72.             }
  73.             if (checkForDead(playerHealth, heiganHealth)) break;
  74.             if (isCloudOn) {
  75.                 playerHealth -= plegueCloudDamage;
  76.                 isCloudOn = false;
  77.             }
  78.             input = sc.nextLine();
  79.         }
  80.  
  81.         System.out.printf("Heigan: %s\n", isHeiganDead ? "Defeated!" : String.format("%.2f", heiganHealth));
  82.         System.out.printf("Player: %s\n", isPlayerDead ? String.format("Killed by %s", lastSpell) : playerHealth);
  83.         System.out.printf("Final position: %d, %d\n", playerRow, playerColumn);
  84.     }
  85.  
  86.     private static boolean checkForDead(int playerHealth, double heiganHealth) {
  87.         if (heiganHealth <= 0 && playerHealth <= 0) {
  88.             isHeiganDead = true;
  89.             isPlayerDead = true;
  90.             return true;
  91.         } else if (heiganHealth <= 0) {
  92.             isHeiganDead = true;
  93.             return true;
  94.         } else if (playerHealth <= 0) {
  95.             isPlayerDead = true;
  96.             return true;
  97.         }
  98.         return false;
  99.     }
  100.  
  101.     private static boolean isPlayerHit(int plRow, int plColumn, List<Integer> rowsHitted, List<Integer> columnsHitted) {
  102.         if (rowsHitted.contains(plRow) && columnsHitted.contains(plColumn)) {
  103.             return true;
  104.         }
  105.         return false;
  106.     }
  107.  
  108.     private static boolean isPlayerEscape(int plRow, int plColumn, List<Integer> rowsHitted, List<Integer> columnsHitted) {
  109.         if (!isPlayerHit((plRow - 1) < 0 ? 0 : (plRow - 1), plColumn, rowsHitted, columnsHitted)) {
  110.             playerRow = (plRow - 1) < 0 ? 0 : (plRow - 1);
  111.             return true;
  112.         } else if (!isPlayerHit(plRow, (plColumn + 1) >= 15 ? 14 : plColumn + 1, rowsHitted, columnsHitted)) {
  113.             playerColumn = (plColumn + 1) >= 15 ? 14 : plColumn + 1;
  114.             return true;
  115.         } else if (!isPlayerHit((plRow + 1) >= 15 ? 14 : (plRow + 1), plColumn, rowsHitted, columnsHitted)) {
  116.             playerRow = (plRow + 1) >= 15 ? 14 : (plRow + 1);
  117.             return true;
  118.         } else if (!isPlayerHit(plRow, (plColumn - 1) < 0 ? 0 : plColumn - 1, rowsHitted, columnsHitted)) {
  119.             playerColumn = (plColumn - 1) < 0 ? 0 : plColumn - 1;
  120.             return true;
  121.         }
  122.         return false;
  123.     }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement