Advertisement
Guest User

Magic and Sword

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