SHARE
TWEET

Untitled

a guest May 20th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. public class TheHeiganDance {
  6.  
  7.     public static void main(String[] args) throws IOException {
  8.  
  9.  
  10.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  11.  
  12.         double dmgToBoss = Double.parseDouble(reader.readLine());
  13.  
  14.         Player player = new Player();
  15.         player.Position = new int[]{7, 7};
  16.         player.HP = 18500;
  17.         player.Dmg = dmgToBoss;
  18.         player.IsHitByCloud = false;
  19.  
  20.         double bossHP = 3000000;
  21.         String spell = "";
  22.  
  23.         while (true) {
  24.             //check if the player is hit by Cloud
  25.             if (player.IsHitByCloud) {
  26.                 player.HP -= 3500;
  27.                 player.IsHitByCloud = false;
  28.             }
  29.  
  30.             bossHP -= player.Dmg;
  31.  
  32.             if (isGameOver(player, bossHP, spell)) {
  33.                 break;
  34.             }
  35.  
  36.             String[] attack = reader.readLine().split(" ");
  37.             spell = attack[0];
  38.             int hitRow = Integer.parseInt(attack[1]);
  39.             int hitCol = Integer.parseInt(attack[2]);
  40.  
  41.             if (isCellReached(player.Position[0], player.Position[1], hitRow, hitCol) && isPlayerDamaged(player, hitRow, hitCol)) {
  42.  
  43.                 switch (spell) {
  44.                     case "Cloud":
  45.                         player.HP -= 3500;
  46.                         player.IsHitByCloud = true;
  47.                         break;
  48.                     case "Eruption":
  49.                         player.HP -= 6000;
  50.                         break;
  51.                     default:
  52.                         break;
  53.                 }
  54.             }
  55.             if (isGameOver(player, bossHP, spell)) {
  56.                 break;
  57.             }
  58.         }
  59.  
  60.  
  61.     }
  62.  
  63.     private static boolean isPlayerDamaged(Player player, int hitRow, int hitCol) {
  64.         if (player.Position[0] > 0 &&
  65.                 !isCellReached(player.Position[0] - 1, player.Position[1], hitRow, hitCol)) // Try move Up
  66.         {
  67.             player.Position[0]--;
  68.             return false;
  69.         }
  70.  
  71.         if (player.Position[1] + 1 < 15 && // Dancing area is 15 by 15 matrix
  72.                 !isCellReached(player.Position[0], player.Position[1] + 1, hitRow, hitCol)) // Try move Right
  73.         {
  74.             player.Position[1]++;
  75.             return false;
  76.         }
  77.  
  78.         if (player.Position[0] + 1 < 15 && // Dancing area is 15 by 15 matrix
  79.                 !isCellReached(player.Position[0] + 1, player.Position[1], hitRow, hitCol)) // Try move Down
  80.         {
  81.             player.Position[0]++;
  82.             return false;
  83.         }
  84.  
  85.         if (player.Position[1] > 0 &&
  86.                 !isCellReached(player.Position[0], player.Position[1] - 1, hitRow, hitCol)) // Try move Left
  87.         {
  88.             player.Position[1]--;
  89.             return false;
  90.         }
  91.  
  92.         return true;
  93.     }
  94.  
  95.     private static boolean isCellReached(int cellRow, int cellCol, int hitRow, int hitCol) {
  96.         return (cellRow >= hitRow - 1) && (cellRow <= hitRow + 1) && (cellCol >= hitCol - 1) && (cellCol <= hitCol + 1);
  97.     }
  98.  
  99.     private static boolean isGameOver(Player player, double bossHP, String spell) {
  100.         if (player.HP <= 0 || bossHP <= 0) {
  101.             if (spell.equals("Cloud")) {
  102.                 spell = "Plague Cloud";
  103.             }
  104.  
  105.             if (bossHP > 0) {
  106.                 System.out.println(String.format("Heigan: %.2f", bossHP));
  107.             } else {
  108.                 System.out.println("Heigan: Defeated!");
  109.             }
  110.  
  111.             if (player.HP > 0) {
  112.                 System.out.println(String.format("Player: %d", player.HP));
  113.             } else {
  114.                 System.out.println(String.format("Player: Killed by %s", spell));
  115.             }
  116.  
  117.             System.out.println(String.format("Final position: %d, %d", player.Position[0], player.Position[1]));
  118.  
  119.             return true;
  120.         }
  121.         return false;
  122.     }
  123.  
  124.     static class Player {
  125.         public int[] Position;
  126.  
  127.         public int HP;
  128.  
  129.         public double Dmg;
  130.  
  131.         public boolean IsHitByCloud;
  132.  
  133.         public Player() {
  134.  
  135.         }
  136.     }
  137. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top