Yargi

TheHeiganDance

Sep 22nd, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.71 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TheHeiganDance {
  4.  
  5.     private static double playerDamage;
  6.     private static double playerHealth = 18500.0;
  7.     private static double heiganHealth = 3000000.0;
  8.     private static final double plageCloud = 3500.0;
  9.     private static final double eruption = 6000.0;
  10.     private static int[][][] damage = new int[3][3][2];
  11.     private static int[] position = {7, 7};
  12.  
  13.     public static void main(String[] args) {
  14.  
  15.         Scanner sc = new Scanner(System.in);
  16.         playerDamage = Double.parseDouble(sc.nextLine());
  17.         String spell ="";
  18.  
  19.         while (playerHealth > 0 && heiganHealth > 0){
  20.  
  21.             //checker(1);
  22.  
  23.             heiganHealth -= playerDamage;
  24.  
  25.             if (spell.equals("Cloud")){
  26.                 if (checkPosition()){
  27.                     playerHealth -= plageCloud;
  28.                 }
  29.             }
  30.  
  31.             //checker(2);
  32.  
  33.             if (heiganHealth > 0 && playerHealth > 0) {
  34.                 String[] token = sc.nextLine().split("\\s+");
  35.                 spell = token[0];
  36.                 damage[1][1][0] = Integer.parseInt(token[1]);
  37.                 damage[1][1][1] = Integer.parseInt(token[2]);
  38.                 for (int i = -1; i < 2; i++) {
  39.                     for (int j = -1; j < 2; j++) {
  40.                         damage[i + 1][j + 1][0] = damage[1][1][0] + i;
  41.                         damage[i + 1][j + 1][1] = damage[1][1][1] + j;
  42.                     }
  43.                 }
  44.  
  45.                 if (checkPosition()) {
  46.  
  47.                     if (!tryToMove()) {
  48.  
  49.                         playerHealth = spell.equals("Eruption") ? playerHealth - eruption : playerHealth - plageCloud;
  50.                     }
  51.                 }
  52.             }
  53.             //checker(3);
  54.         }
  55.         if (spell.equals("Cloud")){
  56.             spell = "Plague Cloud";
  57.         }
  58.         String heigan = heiganHealth <= 0 ? "Defeated!" : String.format("%.2f", heiganHealth);
  59.         String player = playerHealth <= 0 ? String.format("Killed by %s", spell) : "" + (int) playerHealth;
  60.         System.out.println("Heigan: " + heigan);
  61.         System.out.println("Player: " + player);
  62.         System.out.printf("Final position: %d, %d%n", position[0], position[1]);
  63.     }
  64.     private static boolean checkPosition(){
  65.         for (int i = 0; i < 3; i++){
  66.             for (int j = 0; j < 3; j++){
  67.                 if (damage[i][j][0] == position[0] && damage[i][j][1] == position[1]){
  68.                     return true;
  69.                 }
  70.             }
  71.         }
  72.         return false;
  73.     }
  74.  
  75.     private static boolean tryToMove(){
  76.  
  77.         for (int i = 0; i < 3; i++){
  78.             if (damage[0][i][0] == position[0] && damage[0][i][1] == position[1]){
  79.                 if (position[0] - 1 >= 0){
  80.                     position[0]--;
  81.                     return true;
  82.                 }
  83.             }
  84.         }
  85.         for (int i = 0; i < 3; i++) {
  86.             if (damage[i][2][0] == position[0] && damage[i][2][1] == position[1]) {
  87.                 if (position[1] + 1 < 16){
  88.                     position[1]++;
  89.                     return true;
  90.                 }
  91.             }
  92.         }
  93.         for (int i = 2; i >= 0; i--) {
  94.             if (damage[2][i][0] == position[0] && damage[2][i][1] == position[1]) {
  95.                 if (position[0] + 1 < 16){
  96.                     position[0]++;
  97.                     return true;
  98.                 }
  99.             }
  100.         }
  101.         for (int i = 2; i >= 0; i--) {
  102.             if (damage[i][0][0] == position[0] && damage[i][0][1] == position[1]) {
  103.                 if (position[1] - 1 >= 0){
  104.                     position[1]--;
  105.                     return true;
  106.                 }
  107.             }
  108.         }
  109.         return false;
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment