Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Uprajnenie;
- import java.util.Scanner;
- public class TheHeiganDance {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double heiganHP = 3000000.0;
- int playerHP = 18500;
- int playerRow = 7;
- int playerCol = 7;
- String lastSpell = "";
- boolean isCloudActive = false;
- double damage = Double.parseDouble(scanner.nextLine());
- while (playerHP > 0 && heiganHP > 0) {
- heiganHP -= damage;
- if (isCloudActive) {
- playerHP -= 3500;
- isCloudActive = false;
- if (playerHP < 0) {
- break;
- }
- }
- if (heiganHP < 0) {
- break;
- }
- String[] tokens = scanner.nextLine().split("\\s+");
- String spell = tokens[0];
- int row = Integer.parseInt(tokens[1]);
- int col = Integer.parseInt(tokens[2]);
- boolean[][] heiganChamber = new boolean[15][15];
- for (int i = row - 1; i <= row + 1; i++) {
- if (i >= 0 && i < heiganChamber.length) {
- for (int j = col - 1; j <= col + 1; j++) {
- if (j >= 0 && j < heiganChamber[i].length) {
- heiganChamber[i][j] = true;
- }
- }
- }
- }
- if (heiganChamber[playerRow][playerCol]) {
- if (isRowValid(heiganChamber, playerRow - 1) && !heiganChamber[playerRow - 1][playerCol]) {
- playerRow--; // move up
- } else if (isColValid(heiganChamber, playerCol + 1) && !heiganChamber[playerRow][playerCol + 1]) {
- playerCol++; // move right
- } else if (isRowValid(heiganChamber, playerRow + 1) && !heiganChamber[playerRow + 1][playerCol]) {
- playerRow++; // move down
- } else if (isColValid(heiganChamber, playerCol - 1) && !heiganChamber[playerRow][playerCol - 1]) {
- playerCol--; // move left
- }
- if (heiganChamber[playerRow][playerCol]) {
- switch (spell) {
- case "Cloud":
- playerHP -= 3500;
- isCloudActive = true;
- lastSpell = "Plague Cloud";
- break;
- case "Eruption":
- playerHP -= 6000;
- lastSpell = spell;
- break;
- default:
- throw new IllegalArgumentException("Invalid spell: " + spell);
- }
- }
- }
- }
- if (heiganHP > 0) {
- System.out.printf("Heigan: %.2f%n", heiganHP);
- } else {
- System.out.println("Heigan: Defeated!");
- }
- if (playerHP > 0) {
- System.out.printf("Player: %d%n", playerHP);
- } else {
- System.out.println("Player: Killed by " + lastSpell);
- }
- System.out.println("Final position: " + playerRow + ", " + playerCol);
- }
- private static boolean isRowValid(boolean[][] heiganChamber, int playerRow) {
- return playerRow >= 0 && playerRow < heiganChamber.length;
- }
- private static boolean isColValid(boolean[][] heiganChamber, int playerCol) {
- return playerCol >= 0 && playerCol < heiganChamber[0].length;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement