Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class TheHeiganDance {
- private static double playerDamage;
- private static double playerHealth = 18500.0;
- private static double heiganHealth = 3000000.0;
- private static final double plageCloud = 3500.0;
- private static final double eruption = 6000.0;
- private static int[][][] damage = new int[3][3][2];
- private static int[] position = {7, 7};
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- playerDamage = Double.parseDouble(sc.nextLine());
- String spell ="";
- while (playerHealth > 0 && heiganHealth > 0){
- //checker(1);
- heiganHealth -= playerDamage;
- if (spell.equals("Cloud")){
- if (checkPosition()){
- playerHealth -= plageCloud;
- }
- }
- //checker(2);
- if (heiganHealth > 0 && playerHealth > 0) {
- String[] token = sc.nextLine().split("\\s+");
- spell = token[0];
- damage[1][1][0] = Integer.parseInt(token[1]);
- damage[1][1][1] = Integer.parseInt(token[2]);
- for (int i = -1; i < 2; i++) {
- for (int j = -1; j < 2; j++) {
- damage[i + 1][j + 1][0] = damage[1][1][0] + i;
- damage[i + 1][j + 1][1] = damage[1][1][1] + j;
- }
- }
- if (checkPosition()) {
- if (!tryToMove()) {
- playerHealth = spell.equals("Eruption") ? playerHealth - eruption : playerHealth - plageCloud;
- }
- }
- }
- //checker(3);
- }
- if (spell.equals("Cloud")){
- spell = "Plague Cloud";
- }
- String heigan = heiganHealth <= 0 ? "Defeated!" : String.format("%.2f", heiganHealth);
- String player = playerHealth <= 0 ? String.format("Killed by %s", spell) : "" + (int) playerHealth;
- System.out.println("Heigan: " + heigan);
- System.out.println("Player: " + player);
- System.out.printf("Final position: %d, %d%n", position[0], position[1]);
- }
- private static boolean checkPosition(){
- for (int i = 0; i < 3; i++){
- for (int j = 0; j < 3; j++){
- if (damage[i][j][0] == position[0] && damage[i][j][1] == position[1]){
- return true;
- }
- }
- }
- return false;
- }
- private static boolean tryToMove(){
- for (int i = 0; i < 3; i++){
- if (damage[0][i][0] == position[0] && damage[0][i][1] == position[1]){
- if (position[0] - 1 >= 0){
- position[0]--;
- return true;
- }
- }
- }
- for (int i = 0; i < 3; i++) {
- if (damage[i][2][0] == position[0] && damage[i][2][1] == position[1]) {
- if (position[1] + 1 < 16){
- position[1]++;
- return true;
- }
- }
- }
- for (int i = 2; i >= 0; i--) {
- if (damage[2][i][0] == position[0] && damage[2][i][1] == position[1]) {
- if (position[0] + 1 < 16){
- position[0]++;
- return true;
- }
- }
- }
- for (int i = 2; i >= 0; i--) {
- if (damage[i][0][0] == position[0] && damage[i][0][1] == position[1]) {
- if (position[1] - 1 >= 0){
- position[1]--;
- return true;
- }
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment