Advertisement
Ligh7_of_H3av3n

08. The Heigan Dance

May 17th, 2024
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.59 KB | None | 0 0
  1. package Uprajnenie;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class TheHeiganDance {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.  
  10.         double heiganHP = 3000000.0;
  11.         int playerHP = 18500;
  12.  
  13.         int playerRow = 7;
  14.         int playerCol = 7;
  15.  
  16.         String lastSpell = "";
  17.         boolean isCloudActive = false;
  18.  
  19.         double damage = Double.parseDouble(scanner.nextLine());
  20.  
  21.         while (playerHP > 0 && heiganHP > 0) {
  22.             heiganHP -= damage;
  23.  
  24.             if (isCloudActive) {
  25.                 playerHP -= 3500;
  26.                 isCloudActive = false;
  27.  
  28.                 if (playerHP < 0) {
  29.                     break;
  30.                 }
  31.             }
  32.  
  33.             if (heiganHP < 0) {
  34.                 break;
  35.             }
  36.  
  37.             String[] tokens = scanner.nextLine().split("\\s+");
  38.  
  39.             String spell = tokens[0];
  40.             int row = Integer.parseInt(tokens[1]);
  41.             int col = Integer.parseInt(tokens[2]);
  42.  
  43.             boolean[][] heiganChamber = new boolean[15][15];
  44.             for (int i = row - 1; i <= row + 1; i++) {
  45.                 if (i >= 0 && i < heiganChamber.length) {
  46.                     for (int j = col - 1; j <= col + 1; j++) {
  47.                         if (j >= 0 && j < heiganChamber[i].length) {
  48.                             heiganChamber[i][j] = true;
  49.                         }
  50.                     }
  51.                 }
  52.             }
  53.  
  54.             if (heiganChamber[playerRow][playerCol]) {
  55.                 if (isRowValid(heiganChamber, playerRow - 1) && !heiganChamber[playerRow - 1][playerCol]) {
  56.                     playerRow--; // move up
  57.                 } else if (isColValid(heiganChamber, playerCol + 1) && !heiganChamber[playerRow][playerCol + 1]) {
  58.                     playerCol++; // move right
  59.                 } else if (isRowValid(heiganChamber, playerRow + 1) && !heiganChamber[playerRow + 1][playerCol]) {
  60.                     playerRow++; // move down
  61.                 } else if (isColValid(heiganChamber, playerCol - 1) && !heiganChamber[playerRow][playerCol - 1]) {
  62.                     playerCol--; // move left
  63.                 }
  64.  
  65.                 if (heiganChamber[playerRow][playerCol]) {
  66.                     switch (spell) {
  67.                         case "Cloud":
  68.                             playerHP -= 3500;
  69.                             isCloudActive = true;
  70.                             lastSpell = "Plague Cloud";
  71.                             break;
  72.                         case "Eruption":
  73.                             playerHP -= 6000;
  74.                             lastSpell = spell;
  75.                             break;
  76.                         default:
  77.                             throw new IllegalArgumentException("Invalid spell: " + spell);
  78.                     }
  79.                 }
  80.             }
  81.         }
  82.  
  83.         if (heiganHP > 0) {
  84.             System.out.printf("Heigan: %.2f%n", heiganHP);
  85.         } else {
  86.             System.out.println("Heigan: Defeated!");
  87.         }
  88.  
  89.         if (playerHP > 0) {
  90.             System.out.printf("Player: %d%n", playerHP);
  91.         } else {
  92.             System.out.println("Player: Killed by " + lastSpell);
  93.         }
  94.  
  95.         System.out.println("Final position: " + playerRow + ", " + playerCol);
  96.     }
  97.  
  98.     private static boolean isRowValid(boolean[][] heiganChamber, int playerRow) {
  99.         return playerRow >= 0 && playerRow < heiganChamber.length;
  100.     }
  101.  
  102.     private static boolean isColValid(boolean[][] heiganChamber, int playerCol) {
  103.         return playerCol >= 0 && playerCol < heiganChamber[0].length;
  104.     }
  105. }
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement