5kov

The Heigan Dance

May 18th, 2023
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.76 KB | None | 0 0
  1. package advanced.multiDimensionalArrays;
  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.         int playerRow = 7;
  9.         int playerCol = 7;
  10.         int playerHealth = 18500;
  11.         double bossHealth = 3000000;
  12.         int plagueCloudDamage = 3500;
  13.         int eruptionDamage = 6000;
  14.         double playerDamage = Double.parseDouble(scanner.nextLine());
  15.         boolean poisoned = false;
  16.         boolean fightFinished = false;
  17.         boolean playerDead = false;
  18.         boolean bossDead = false;
  19.         String lastSpellHit = "";
  20.  
  21.         while (!fightFinished) {
  22.             bossHealth -= playerDamage;
  23.  
  24.             if (poisoned) {
  25.                 playerHealth -= plagueCloudDamage;
  26.                 poisoned = false;
  27.             }
  28.  
  29.             if (playerHealth <= 0) {
  30.                 fightFinished = true;
  31.                 playerDead = true;
  32.             }
  33.  
  34.             if (bossHealth <= 0) {
  35.                 fightFinished = true;
  36.                 bossDead = true;
  37.             }
  38.  
  39.             if (fightFinished) {
  40.                 break;
  41.             }
  42.  
  43.                 String[] attack = scanner.nextLine().split(" ");
  44.                 String spell = attack[0];
  45.                 int spellRow = Integer.parseInt(attack[1]);
  46.                 int spellCol = Integer.parseInt(attack[2]);
  47.                 boolean isHit = false;
  48.                 if (spellRow == playerRow && spellCol == playerCol) {
  49.                     isHit = true;
  50.                 } else if (Math.abs(playerCol - spellCol) <= 1 && Math.abs(playerRow - spellRow) <= 1) {
  51.                     if (upIsSafe(playerRow, spellRow)) {
  52.                         playerRow -= 1;
  53.                     } else if (rightIsSafe(playerCol, spellCol)) {
  54.                         playerCol += 1;
  55.                     } else if (downIsSafe(playerRow, spellRow)) {
  56.                         playerRow += 1;
  57.                     } else if (leftIsSafe(playerCol, spellCol)) {
  58.                         playerCol -= 1;
  59.                     } else {
  60.                         isHit = true;
  61.                     }
  62.                 }
  63.  
  64.                 if (isHit) {
  65.                     if (spell.equals("Cloud")) {
  66.                         playerHealth -= plagueCloudDamage;
  67.                         poisoned = true;
  68.                         lastSpellHit = "Plague Cloud";
  69.                     } else {
  70.                         playerHealth -= eruptionDamage;
  71.                         lastSpellHit = "Eruption";
  72.                     }
  73.                 }
  74.  
  75.             if (playerHealth < 0) {
  76.                 fightFinished = true;
  77.                 playerDead = true;
  78.             }
  79.         }
  80.  
  81.         if (bossDead) {
  82.             System.out.println("Heigan: Defeated!");
  83.         } else {
  84.             System.out.printf("Heigan: %.2f%n", bossHealth);
  85.         }
  86.  
  87.         if (playerDead) {
  88.             System.out.println("Player: Killed by " + lastSpellHit);
  89.         } else {
  90.             System.out.println("Player: " + playerHealth);
  91.         }
  92.  
  93.         System.out.printf("Final position: %d, %d%n", playerRow, playerCol);
  94.     }
  95.  
  96.     public static boolean upIsSafe(int playerRow, int spellRow) {
  97.         return playerRow - 1 >= 0 && Math.abs(playerRow - 1 - spellRow) > 1;
  98.     }
  99.  
  100.     public static boolean rightIsSafe(int playerCol, int spellCol) {
  101.         return playerCol + 1 < 15 && Math.abs(playerCol + 1 - spellCol) > 1;
  102.     }
  103.  
  104.     public static boolean downIsSafe(int playerRow, int spellRow) {
  105.         return playerRow + 1 < 15 && Math.abs(playerRow + 1 - spellRow) > 1;
  106.     }
  107.  
  108.     public static boolean leftIsSafe(int playerCol, int spellCol) {
  109.         return playerCol - 1 >= 0 && Math.abs(playerCol - 1 - spellCol) > 1;
  110.     }
  111. }
  112.  
  113.  
Advertisement
Add Comment
Please, Sign In to add comment