LardaX

TheHeiganDance

Feb 18th, 2017
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.25 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. public class TheHeiganDance {
  6.     private static String[][] chamber;
  7.     public static void main(String[] args) throws IOException {
  8.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  9.         double playerDamage = Double.parseDouble(reader.readLine());
  10.         chamber = new String[15][15];
  11.         int playerRow = 7;
  12.         int playerCol = 7;
  13.         int playerHealth = 18500;
  14.         double heiganHealth = 3000000;
  15.  
  16.         boolean cloudActive = false;
  17.  
  18.         resetChamber();
  19.  
  20.         while (true) {
  21.             String[] spellArgs = reader.readLine().trim().split("\\s+");
  22.             String spell = spellArgs[0];
  23.             int spellRow = Integer.parseInt(spellArgs[1]);
  24.             int spellCol = Integer.parseInt(spellArgs[2]);
  25.             int spellDamage = spell.equals("Cloud") ? 3500 : 6000;
  26.  
  27.             if (cloudActive) {
  28.                 if ("C".equals(chamber[playerRow][playerCol])) {
  29.                     if (playerRow - 1 >= 0 && "M".equals(chamber[playerRow - 1][playerCol])) {
  30.                         playerRow--;
  31.                     } else if (playerCol + 1 < 15 && "M".equals(chamber[playerRow][playerCol + 1])) {
  32.                         playerCol++;
  33.                     } else if (playerRow + 1 < 15 && "M".equals(chamber[playerRow + 1][playerCol])) {
  34.                         playerRow++;
  35.                     } else if (playerCol - 1 >= 0 && "M".equals(chamber[playerRow][playerCol - 1])) {
  36.                         playerCol--;
  37.                     } else {
  38.                         playerHealth -= spellDamage;
  39.                     }
  40.                 }
  41.             }
  42.             if (playerHealth <= 0) {
  43.                 System.out.println(String.format("Heigan: %.2f", heiganHealth));
  44.                 System.out.println("Player: Killed by " + (cloudActive ? "Plague Cloud" : "Eruption"));
  45.                 System.out.println(String.format("Final position: %s, %s", playerRow, playerCol));
  46.                 return;
  47.             }
  48.  
  49.             resetChamber();
  50.             cloudActive = false;
  51.  
  52.             heiganHealth -= playerDamage;
  53.  
  54.             if (heiganHealth <= 0) {
  55.                 System.out.println("Heigan: Defeated!");
  56.                 System.out.println("Player: " + playerHealth);
  57.                 System.out.println(String.format("Final position: %s, %s", playerRow, playerCol));
  58.                 return;
  59.             }
  60.  
  61.             for (int row = spellRow - 1; row <= spellRow + 1; row++) {
  62.                 for (int col = spellCol - 1; col <= spellCol + 1; col++) {
  63.                     try {
  64.                         chamber[row][col] = "C";
  65.                     } catch (IndexOutOfBoundsException e) {}
  66.                 }
  67.             }
  68.             if (spell.equals("Cloud")) {
  69.                 cloudActive = true;
  70.             }
  71.  
  72.             if ("C".equals(chamber[playerRow][playerCol])) {
  73.                 if (playerRow - 1 >= 0 && "M".equals(chamber[playerRow - 1][playerCol])) {
  74.                     playerRow--;
  75.                 } else if (playerCol + 1 < 15 && "M".equals(chamber[playerRow][playerCol + 1])) {
  76.                     playerCol++;
  77.                 } else if (playerRow + 1 < 15 && "M".equals(chamber[playerRow + 1][playerCol])) {
  78.                     playerRow++;
  79.                 } else if (playerCol - 1 >= 0 && "M".equals(chamber[playerRow][playerCol - 1])) {
  80.                     playerCol--;
  81.                 } else {
  82.                     playerHealth -= spellDamage;
  83.                 }
  84.             }
  85.  
  86.             if (playerHealth <= 0) {
  87.                 System.out.println(String.format("Heigan: %.2f", heiganHealth));
  88.                 System.out.println("Player: Killed by " + (cloudActive ? "Plague Cloud" : "Eruption"));
  89.                 System.out.println(String.format("Final position: %s, %s", playerRow, playerCol));
  90.                 return;
  91.             }
  92.  
  93.             if (spell.equals("Eruption")) {
  94.                 resetChamber();
  95.             }
  96.         }
  97.     }
  98.  
  99.     private static void resetChamber() {
  100.         for (int row = 0; row < 15; row++) {
  101.             for (int col = 0; col < 15; col++) {
  102.                 chamber[row][col] = "M";
  103.             }
  104.         }
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment