Didart

The Heigan Dance

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