Advertisement
Guest User

Untitled

a guest
Jun 6th, 2016
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.81 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.StringJoiner;
  3.  
  4. public class Problem20_TheHeiganDance {
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.         double damageToHeaigen = Double.parseDouble(sc.nextLine());
  8.         double playerLife = 18500.0;
  9.         double heigenLife = 3000000.0;
  10.         double cloudDamage = 3500.0;
  11.         double eruptionDamage = 6000.0;
  12.         boolean isCloudAktiv = false;
  13.         boolean isHeiganDead = false;
  14.         boolean isPlayerDead = false;
  15.         boolean killedByEruption = false;
  16.  
  17.         boolean[][] field = new boolean[15][15];
  18.  
  19.         int playerRow = 7;
  20.         int playerCol = 7;
  21.  
  22.         while (heigenLife > 0 && playerLife > 0) {
  23.             heigenLife -= damageToHeaigen;
  24.             if (heigenLife <= 0) {
  25.                 isHeiganDead = true;
  26.                 break;
  27.             }
  28.  
  29.             if (isCloudAktiv){
  30.                 playerLife -= cloudDamage;
  31.                 isCloudAktiv = false;
  32.             }
  33.  
  34.             if (playerLife <= 0){
  35.                 isPlayerDead = true;
  36.                 break;
  37.             }
  38.  
  39.             String[] input = sc.nextLine().split(" ");
  40.             String magic = input[0];
  41.             int row = Integer.parseInt(input[1]);
  42.             int col = Integer.parseInt(input[2]);
  43.  
  44.             if (row - 1 >= 0 && row - 1 <= 14 && col - 1 >= 0 && col - 1 <= 14) {
  45.                 field[row - 1][col - 1] = true;
  46.             }
  47.             if (row - 1 >= 0 && row - 1 <= 14 && col >= 0 && col <= 14) {
  48.                 field[row - 1][col] = true;
  49.             }
  50.             if (row - 1 >= 0 && row - 1 <= 14 && col + 1 >= 0 && col + 1 <= 14) {
  51.                 field[row - 1][col + 1] = true;
  52.             }
  53.             if (row >= 0 && row <= 14 && col - 1 >= 0 && col - 1 <= 14) {
  54.                 field[row][col - 1] = true;
  55.             }
  56.             if (row >= 0 && row <= 14 && col >= 0 && col <= 14) {
  57.                 field[row][col] = true;
  58.             }
  59.             if (row >= 0 && row <= 14 && col + 1 >= 0 && col + 1 <= 14) {
  60.                 field[row][col + 1] = true;
  61.             }
  62.             if (row + 1 >= 0 && row + 1 <= 14 && col - 1 >= 0 && col - 1 <= 14) {
  63.                 field[row + 1][col - 1] = true;
  64.             }
  65.             if (row + 1 >= 0 && row + 1 <= 14 && col >= 0 && col <= 14) {
  66.                 field[row + 1][col] = true;
  67.             }
  68.             if (row + 1 >= 0 && row + 1 <= 14 && col + 1 >= 0 && col + 1 <= 14) {
  69.                 field[row + 1][col + 1] = true;
  70.             }
  71.  
  72.  
  73.             if (field[playerRow][playerCol] == true) {
  74.                 if (playerRow - 1 < 0 || field[playerRow - 1][playerCol] == true){
  75.                     if (playerCol + 1 >= 15 || field[playerRow][playerCol + 1] == true){
  76.                         if (playerRow + 1 >= 15 || field[playerRow + 1][playerCol] == true){
  77.                             if (playerCol - 1 < 0 || field[playerRow][playerCol - 1] == true){
  78.                                 switch (magic){
  79.                                     case "Cloud":
  80.                                         playerLife -= cloudDamage;
  81.                                         isCloudAktiv = true;
  82.                                         if (playerLife <= 0){
  83.                                             isPlayerDead = true;
  84.                                         }
  85.                                         break;
  86.                                     case "Eruption":
  87.                                         playerLife -= eruptionDamage;
  88.                                         if (playerLife <= 0){
  89.                                             isPlayerDead = true;
  90.                                             killedByEruption = true;
  91.                                         }
  92.                                         break;
  93.                                 }
  94.                             } else {
  95.                                 playerCol--;
  96.                             }
  97.                         } else {
  98.                             playerRow++;
  99.                         }
  100.                     } else {
  101.                         playerCol++;
  102.                     }
  103.                 } else {
  104.                     playerRow--;
  105.                 }
  106.             }
  107.  
  108.             field = new boolean[15][15];
  109.         }
  110.  
  111.         if (isHeiganDead) {
  112.             System.out.printf("Heigan: Defeated!\n");
  113.             System.out.printf("Player: %.0f\n", playerLife);
  114.             System.out.printf("Final position: %d, %d\n", playerRow, playerCol);
  115.         }
  116.  
  117.         if (isPlayerDead) {
  118.             System.out.printf("Heigan: %.2f\n", heigenLife);
  119.             System.out.printf("Player: Killed by %s\n", killedByEruption ? "Eruption" : "Plague Cloud");
  120.             System.out.printf("Final position: %d, %d\n", playerRow, playerCol);
  121.         }
  122.     }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement