Advertisement
Guest User

Magic and Sword

a guest
Feb 21st, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.31 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.             static int objectX = 30;
  5.             static int objectY = 30;
  6.             static int objectW = 40;
  7.             static int objectH = 40;
  8.             static int explosionX = 10;
  9.             static int explosionY = 10;
  10.             static int[] fire = {20, 30, 50};
  11.             static int[] water = {10, 25, 40};
  12.             static int[] earth = {25, 55, 70};
  13.             static int[] air = {18, 38, 60};
  14.             static int damage;
  15.             static int radius;
  16.  
  17.     public static void main(String[] args) {
  18.             int n = 0;
  19.             Scanner scan = new Scanner(System.in);
  20.            
  21.             do {
  22.                 System.out.println("Quanti test vuoi fare? Inserisci un numero da 1 a 1000");
  23.                 n = scan.nextInt();
  24.                 if (n<1 && n>1000) {
  25.                     System.out.println("Inserisci un numero compreso tra 1 e 1000");
  26.                 }
  27.             } while (n<1 && n>1000);
  28.            
  29.             for (int i=0; i<n; i++) {
  30.                 setUnitCoordinates(scan);
  31.                 setSpell(scan);
  32.                 damageCheck();
  33.             }
  34.            
  35.     }
  36.        
  37.         static void setUnitCoordinates(Scanner scan) {
  38.             boolean flag;
  39.             do {
  40.                 System.out.println("Inserisci larghezza, altezza, coordinata X e Y separate da spazi. Solo numeri compresi tra 1 e 1000");
  41.                     flag = false;
  42.                     objectW = scan.nextInt();
  43.                     if (objectW<1 || objectW>1000) {
  44.                         flag = true;
  45.                         continue;
  46.                     }
  47.                     objectH = scan.nextInt();
  48.                     if (objectH<1 || objectH>1000) {
  49.                         flag = true;
  50.                         continue;
  51.                     }
  52.                     objectX = scan.nextInt();
  53.                     if (objectX<1 || objectX>1000) {
  54.                         flag = true;
  55.                         continue;
  56.                     }
  57.                     objectY = scan.nextInt();
  58.                     if (objectY<1 || objectY>1000) {
  59.                         flag = true;
  60.                     }
  61.                     objectW += objectX;
  62.                     objectH += objectY;
  63.                 } while (flag);
  64.         }
  65.        
  66.         static void setSpell(Scanner scan) {
  67.             boolean flag;
  68.             String element;
  69.             int n;
  70.            
  71.             do {
  72.                 System.out.println("Inserisci elemento, livello, coordinata X e Y separati da spazi.");
  73.                     flag = false;
  74.                     element = scan.next().toLowerCase();
  75.                     n = scan.nextInt();
  76.                     if (n<1 || n>3) {
  77.                         flag = true;
  78.                         continue;
  79.                     }
  80.                     explosionX = scan.nextInt();
  81.                     if (explosionX<1 || explosionX>1000) {
  82.                         flag = true;
  83.                         continue;
  84.                     }
  85.                     explosionY = scan.nextInt();
  86.                     if (explosionY<1 || explosionY>1000) {
  87.                         flag = true;
  88.                     }
  89.                 } while (flag);
  90.            
  91.             if (element.equals("fire")) {
  92.                 radius = fire[n-1];
  93.                 damage = 200;
  94.             }
  95.             if (element.equals("water")) {
  96.                 radius = water[n-1];
  97.                 damage = 300;
  98.             }
  99.             if (element.equals("earth")) {
  100.                 radius = earth[n-1];
  101.                 damage = 400;
  102.             }
  103.             if (element.equals("air")) {
  104.                 radius = air[n-1];
  105.                 damage = 100;
  106.             }
  107.         }
  108.        
  109.         static void damageCheck() {
  110.             if (objectX >= explosionX && objectY >= explosionY) {
  111.                 if (hitTopRight())
  112.                     System.out.println(damage);
  113.                 else
  114.                     System.out.println(damage-damage);
  115.             } else if (objectX <= explosionX && objectY >= explosionY) {
  116.                 if (hitTopLeft())
  117.                     System.out.println(damage);
  118.                 else
  119.                     System.out.println(damage-damage);
  120.             } else if (objectX >= explosionX && objectY <= explosionY) {
  121.                 if (hitBottomRight())
  122.                     System.out.println(damage);
  123.                 else
  124.                     System.out.println(damage-damage);
  125.             } else if (objectX <= explosionX && objectY <= explosionY) {
  126.                 if (hitBottomLeft())
  127.                     System.out.println(damage);
  128.                 else
  129.                     System.out.println(damage-damage);
  130.             }
  131.         }
  132.        
  133.         static boolean hitTopRight() {
  134.                 return explosionX+radius >= objectX && explosionY+radius >= objectY;
  135.         }
  136.        
  137.         static boolean hitTopLeft() {
  138.             return explosionX-radius <= objectW && explosionY+radius >= objectY;
  139.         }
  140.        
  141.         static boolean hitBottomRight() {
  142.             return explosionX+radius >= objectX && explosionY-radius <= objectH;
  143.         }
  144.        
  145.         static boolean hitBottomLeft() {
  146.             return explosionX-radius <= objectW && explosionY-radius <= objectH;
  147.         }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement