Advertisement
desislava_topuzakova

Untitled

Mar 21st, 2023
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.70 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. public class TheHeiganDance {
  6.  
  7. private static final String CLOUD_SPELL = "Cloud";
  8. private static final int CLOUD_SPELL_DMG = 3500;
  9. private static final String ERUPTION_SPELL = "Eruption";
  10. private static final int ERUPTION_SPELL_DMG = 6000;
  11.  
  12. public static void main(String[] args) throws IOException {
  13. BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  14.  
  15. double dmgDealtToBoss = Double.parseDouble(reader.readLine());
  16.  
  17. int fieldSize = 15;
  18. int[][] field = new int[fieldSize][fieldSize];
  19.  
  20. int playerHealth = 18500;
  21. double bossHealth = 3000000;
  22.  
  23. int[] playerPosition = new int[2];
  24.  
  25. playerPosition[0] = 7;
  26. playerPosition[1] = 7;
  27.  
  28. boolean cloudIsActive = false;
  29. boolean heroIsAlive = true;
  30.  
  31. StringBuilder report;
  32. StringBuilder bossStatus = new StringBuilder("Heigan: ");
  33. StringBuilder playerStatus = new StringBuilder("Player: ");
  34. StringBuilder finalPosition = new StringBuilder("Final position: ");
  35.  
  36. while (true) {
  37.  
  38. if (!heroIsAlive) {
  39. break;
  40. }
  41.  
  42. bossHealth -= dmgDealtToBoss;
  43.  
  44. if (cloudIsActive) {
  45. cloudIsActive = false;
  46. playerHealth -= CLOUD_SPELL_DMG;
  47. if (playerHealth <= 0) {
  48. playerStatus.append("Killed by ")
  49. .append("Plague ")
  50. .append(CLOUD_SPELL);
  51. finalPosition.append(playerPosition[0])
  52. .append(", ")
  53. .append(playerPosition[1]);
  54.  
  55.  
  56. if (bossHealth <= 0) {
  57. bossStatus.append("Defeated!");
  58. }
  59. break;
  60. }
  61. }
  62.  
  63. if (bossHealth <= 0) {
  64. bossStatus.append("Defeated!");
  65. break;
  66.  
  67. }
  68.  
  69. String[] bossAttackData = reader.readLine().split("\\s+");
  70. String spell = bossAttackData[0];
  71. int row = Integer.parseInt(bossAttackData[1]);
  72. int col = Integer.parseInt(bossAttackData[2]);
  73.  
  74. switch (spell) {
  75.  
  76. case CLOUD_SPELL:
  77.  
  78. markAttackedZones(fieldSize, field, row, col, CLOUD_SPELL_DMG);
  79.  
  80.  
  81. if (field[playerPosition[0]][playerPosition[1]] == CLOUD_SPELL_DMG) {
  82.  
  83. boolean escaped = tryToEscape(field, playerPosition, playerPosition[0], playerPosition[1]);
  84.  
  85. if (!escaped) {
  86.  
  87. playerHealth -= CLOUD_SPELL_DMG;
  88. cloudIsActive = true;
  89. if (playerHealth <= 0) {
  90. playerStatus.append("Killed by ")
  91. .append("Plague ")
  92. .append(CLOUD_SPELL);
  93. finalPosition.append(playerPosition[0])
  94. .append(", ")
  95. .append(playerPosition[1]);
  96. heroIsAlive = false;
  97. }
  98. }
  99. }
  100.  
  101. clearField(field);
  102. break;
  103. case ERUPTION_SPELL:
  104.  
  105. markAttackedZones(fieldSize, field, row, col, ERUPTION_SPELL_DMG);
  106.  
  107.  
  108. if (field[playerPosition[0]][playerPosition[1]] != 0) {
  109.  
  110. boolean escaped = tryToEscape(field, playerPosition, playerPosition[0], playerPosition[1]);
  111.  
  112. if (!escaped) {
  113.  
  114. if (field[playerPosition[0]][playerPosition[1]] != 0) {
  115.  
  116. playerHealth -= ERUPTION_SPELL_DMG;
  117. if (playerHealth <= 0) {
  118. playerStatus.append("Killed by ")
  119. .append(ERUPTION_SPELL);
  120. finalPosition.append(playerPosition[0])
  121. .append(", ")
  122. .append(playerPosition[1]);
  123. heroIsAlive = false;
  124. }
  125. }
  126. }
  127. }
  128.  
  129. clearField(field);
  130. break;
  131. }
  132. }
  133.  
  134. if (bossHealth <= 0 && playerHealth <= 0) {
  135. report = bossStatus.append(System.lineSeparator()).append(playerStatus).append(System.lineSeparator())
  136. .append(finalPosition);
  137. System.out.println(report.toString());
  138. } else if (bossHealth > 0) {
  139. bossStatus.append(String.format("%.2f", bossHealth));
  140. report = bossStatus.append(System.lineSeparator()).append(playerStatus).append(System.lineSeparator())
  141. .append(finalPosition);
  142. System.out.println(report.toString());
  143. } else {
  144. playerStatus.append(playerHealth);
  145. finalPosition.append(playerPosition[0]).append(", ")
  146. .append(playerPosition[1]);
  147. report = bossStatus.append(System.lineSeparator()).append(playerStatus).append(System.lineSeparator())
  148. .append(finalPosition);
  149. System.out.println(report.toString());
  150. }
  151. }
  152.  
  153. private static boolean tryToEscape(int[][] field, int[] playerPosition, int playerRow, int playerCol) {
  154.  
  155. if (isValidPosition(field, playerRow - 1, playerCol)) {
  156. playerPosition[0] = playerRow - 1;
  157. return true;
  158. }
  159.  
  160.  
  161. if (isValidPosition(field, playerRow, playerCol + 1)) {
  162. playerPosition[1] = playerCol + 1;
  163. return true;
  164. }
  165.  
  166.  
  167. if (isValidPosition(field, playerRow + 1, playerCol)) {
  168. playerPosition[0] = playerRow + 1;
  169. return true;
  170. }
  171.  
  172.  
  173. if (isValidPosition(field, playerRow, playerCol - 1)) {
  174. playerPosition[1] = playerCol - 1;
  175. return true;
  176. }
  177.  
  178. return false;
  179. }
  180.  
  181. private static void clearField(int[][] field) {
  182. for (int i = 0; i < field.length; i++) {
  183. for (int j = 0; j < field.length; j++) {
  184. field[i][j] = 0;
  185. }
  186. }
  187. }
  188.  
  189. private static boolean isValidPosition(int[][] field, int x, int y) {
  190.  
  191. return x >= 0 && x < field.length && y >= 0 && y < field.length && field[x][y] == 0;
  192. }
  193.  
  194. private static void markAttackedZones(int fieldSize, int[][] field, int row, int col, int dmg) {
  195. if (row == 0 && col == 0) {
  196.  
  197. for (int i = 0; i < 2; i++) {
  198. for (int j = 0; j < 2; j++) {
  199. field[i][j] += dmg;
  200. }
  201. }
  202.  
  203. } else if (row == 0 && col == field[0].length - 1) {
  204.  
  205. for (int i = 0; i < 2; i++) {
  206. for (int j = 0; j < 2; j++) {
  207. field[i][field[i].length - 1 - j] += dmg;
  208. }
  209. }
  210.  
  211. } else if (row == fieldSize - 1 && col == 0) {
  212.  
  213. for (int i = 0; i < 2; i++) {
  214. for (int j = 0; j < 2; j++) {
  215. field[fieldSize - 1 - i][j] += dmg;
  216. }
  217. }
  218.  
  219. } else if (row == fieldSize - 1 && col == fieldSize - 1) {
  220.  
  221. for (int i = 0; i < 2; i++) {
  222. for (int j = 0; j < 2; j++) {
  223. field[fieldSize - 1 - i][fieldSize - 1 - j] += dmg;
  224. }
  225. }
  226.  
  227. } else if (row == 0 && col > 0 && col < fieldSize - 1) {
  228.  
  229. field[row][col] += dmg;
  230. field[row][col + 1] += dmg;
  231. field[row][col - 1] += dmg;
  232. field[row + 1][col] += dmg;
  233. field[row + 1][col + 1] += dmg;
  234. field[row + 1][col - 1] += dmg;
  235.  
  236. } else if (row == fieldSize - 1 && col > 0 && col < fieldSize - 1) {
  237.  
  238. field[row][col - 1] += dmg;
  239. field[row][col] += dmg;
  240. field[row][col + 1] += dmg;
  241. field[row - 1][col - 1] += dmg;
  242. field[row - 1][col] += dmg;
  243. field[row - 1][col + 1] += dmg;
  244.  
  245. } else if (col == 0 && row > 0 && row < fieldSize - 1) {
  246.  
  247. field[row][col] += dmg;
  248. field[row - 1][col] += dmg;
  249. field[row - 1][col + 1] += dmg;
  250. field[row][col + 1] += dmg;
  251. field[row + 1][col] += dmg;
  252. field[row + 1][col + 1] += dmg;
  253.  
  254. } else if (col == fieldSize - 1 && row > 0 && row < fieldSize - 1) {
  255.  
  256. field[row][col] += dmg;
  257. field[row - 1][col] += dmg;
  258. field[row - 1][col - 1] += dmg;
  259. field[row][col - 1] += dmg;
  260. field[row + 1][col - 1] += dmg;
  261. field[row + 1][col] += dmg;
  262.  
  263. } else if (col == -1 && row == -1) {
  264.  
  265. field[0][0] += dmg;
  266.  
  267. } else if (col == -1 && row == fieldSize) {
  268.  
  269. field[fieldSize - 1][0] += dmg;
  270.  
  271. } else if (row == -1 && col == fieldSize) {
  272.  
  273. field[0][fieldSize - 1] += dmg;
  274.  
  275.  
  276. } else if (row == fieldSize && col == fieldSize) {
  277. field[fieldSize - 1][fieldSize - 1] += dmg;
  278.  
  279. } else if (col == -1 && row > 0 && row < fieldSize - 1) {
  280.  
  281. field[row - 1][col + 1] += dmg;
  282. field[row][col + 1] += dmg;
  283. field[row + 1][col + 1] += dmg;
  284.  
  285.  
  286. } else if (row == -1 && col > 0 && col < fieldSize - 1) {
  287.  
  288. field[row + 1][col - 1] += dmg;
  289. field[row + 1][col] += dmg;
  290. field[row + 1][col + 1] += dmg;
  291.  
  292. } else if (col == fieldSize && row > 0 && row < fieldSize - 1) {
  293.  
  294. field[row][col - 1] += dmg;
  295. field[row - 1][col - 1] += dmg;
  296. field[row + 1][col - 1] += dmg;
  297.  
  298.  
  299. } else if (row == fieldSize && col > 0 && col < fieldSize - 1) {
  300.  
  301. field[row - 1][col] += dmg;
  302. field[row - 1][col - 1] += dmg;
  303. field[row - 1][col + 1] += dmg;
  304.  
  305.  
  306. } else if (row == 0 && col == -1) {
  307.  
  308. field[row][col + 1] += dmg;
  309. field[row + 1][col + 1] += dmg;
  310.  
  311. } else if (row == -1 && col == 0) {
  312.  
  313. field[row + 1][col] += dmg;
  314. field[row + 1][col + 1] += dmg;
  315.  
  316.  
  317. } else if (row == -1 && col == fieldSize - 1) {
  318.  
  319. field[row + 1][col] += dmg;
  320. field[row + 1][col - 1] += dmg;
  321.  
  322.  
  323. } else if (row == 0 && col == fieldSize) {
  324.  
  325. field[row][col - 1] += dmg;
  326. field[row + 1][col - 1] += dmg;
  327.  
  328. } else if (row == fieldSize - 1 && col == -1) {
  329.  
  330. field[row][col + 1] += dmg;
  331. field[row - 1][col + 1] += dmg;
  332.  
  333. } else if (row == fieldSize && col == 0) {
  334.  
  335. field[row - 1][col] += dmg;
  336. field[row - 1][col + 1] += dmg;
  337.  
  338. } else if (row == fieldSize && col == fieldSize - 1) {
  339. field[row - 1][col] += dmg;
  340. field[row - 1][col - 1] += dmg;
  341.  
  342.  
  343. } else if (row == fieldSize - 1 && col == fieldSize) {
  344. field[row][col - 1] += dmg;
  345. field[row - 1][col - 1] += dmg;
  346.  
  347. } else if (row > 0 && row < fieldSize - 1 && col > 0 && col < fieldSize - 1) {
  348.  
  349. for (int i = 0; i < 3; i++) {
  350. for (int j = 0; j < 3; j++) {
  351. field[row - 1 + i][col - 1 + j] += dmg;
  352. }
  353. }
  354. }
  355. }
  356. }
  357.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement