-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.java
executable file
·39 lines (31 loc) · 1.08 KB
/
Utils.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package battleships;
import java.awt.Point;
public class Utils {
private Utils() {
}
//Distance between two points, i.e shiplength
public static double distanceBetweenPoints(Point from, Point to) {
double x1 = from.getX();
double y1 = from.getY();
double x2 = to.getX();
double y2 = to.getY();
return Math.sqrt(Math.pow(x1-x2, 2) + Math.pow(y1-y2, 2)) + 1;
}
public static boolean isPointEqual(Point point, Position position) {
Point from = position.getFrom();
Point to = position.getTo();
System.out.println("kommer jag hit??");
if (point.equals(from) || point.equals(to))
return false;
return true;
}
//Is point between boolean
public static boolean isPointBetween(Point point, Position position) {
Point from = position.getFrom();
Point to = position.getTo();
return from.getY() <= point.getY()
&& to.getY() >= point.getY()
&& from.getX() <= point.getX()
&& to.getX() >= point.getX();
}
}