Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- static int objectX = 30;
- static int objectY = 30;
- static int objectW = 40;
- static int objectH = 40;
- static int explosionX = 10;
- static int explosionY = 10;
- static int[] fire = {20, 30, 50};
- static int[] water = {10, 25, 40};
- static int[] earth = {25, 55, 70};
- static int[] air = {18, 38, 60};
- static int damage;
- static int radius;
- public static void main(String[] args) {
- int n = 0;
- Scanner scan = new Scanner(System.in);
- do {
- System.out.println("Quanti test vuoi fare? Inserisci un numero da 1 a 1000");
- n = scan.nextInt();
- if (n<1 && n>1000) {
- System.out.println("Inserisci un numero compreso tra 1 e 1000");
- }
- } while (n<1 && n>1000);
- for (int i=0; i<n; i++) {
- setUnitCoordinates(scan);
- setSpell(scan);
- damageCheck();
- }
- }
- static void setUnitCoordinates(Scanner scan) {
- boolean flag;
- do {
- System.out.println("Inserisci larghezza, altezza, coordinata X e Y separate da spazi. Solo numeri compresi tra 1 e 1000");
- flag = false;
- objectW = scan.nextInt();
- if (objectW<1 || objectW>1000) {
- flag = true;
- continue;
- }
- objectH = scan.nextInt();
- if (objectH<1 || objectH>1000) {
- flag = true;
- continue;
- }
- objectX = scan.nextInt();
- if (objectX<1 || objectX>1000) {
- flag = true;
- continue;
- }
- objectY = scan.nextInt();
- if (objectY<1 || objectY>1000) {
- flag = true;
- }
- objectW += objectX;
- objectH += objectY;
- } while (flag);
- }
- static void setSpell(Scanner scan) {
- boolean flag;
- String element;
- int n;
- do {
- System.out.println("Inserisci elemento, livello, coordinata X e Y separati da spazi.");
- flag = false;
- element = scan.next().toLowerCase();
- n = scan.nextInt();
- if (n<1 || n>3) {
- flag = true;
- continue;
- }
- explosionX = scan.nextInt();
- if (explosionX<1 || explosionX>1000) {
- flag = true;
- continue;
- }
- explosionY = scan.nextInt();
- if (explosionY<1 || explosionY>1000) {
- flag = true;
- }
- } while (flag);
- if (element.equals("fire")) {
- radius = fire[n-1];
- damage = 200;
- }
- if (element.equals("water")) {
- radius = water[n-1];
- damage = 300;
- }
- if (element.equals("earth")) {
- radius = earth[n-1];
- damage = 400;
- }
- if (element.equals("air")) {
- radius = air[n-1];
- damage = 100;
- }
- }
- static void damageCheck() {
- if (objectX >= explosionX && objectY >= explosionY) {
- if (hitTopRight())
- System.out.println(damage);
- else
- System.out.println(damage-damage);
- } else if (objectX <= explosionX && objectY >= explosionY) {
- if (hitTopLeft())
- System.out.println(damage);
- else
- System.out.println(damage-damage);
- } else if (objectX >= explosionX && objectY <= explosionY) {
- if (hitBottomRight())
- System.out.println(damage);
- else
- System.out.println(damage-damage);
- } else if (objectX <= explosionX && objectY <= explosionY) {
- if (hitBottomLeft())
- System.out.println(damage);
- else
- System.out.println(damage-damage);
- }
- }
- static boolean hitTopRight() {
- return explosionX+radius >= objectX && explosionY+radius >= objectY;
- }
- static boolean hitTopLeft() {
- return explosionX-radius <= objectW && explosionY+radius >= objectY;
- }
- static boolean hitBottomRight() {
- return explosionX+radius >= objectX && explosionY-radius <= objectH;
- }
- static boolean hitBottomLeft() {
- return explosionX-radius <= objectW && explosionY-radius <= objectH;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement