-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
86 lines (70 loc) · 2.76 KB
/
Main.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package javaDVDLogo;
import java.util.HashSet;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
int x, y, width, height;
Scanner in = new Scanner(System.in);
System.out.println("Enter the width of the screen you would like to simulate:");
width = in.nextInt();
System.out.println("Enter the height of the screen you would like to simulate:");
height = in.nextInt();
System.out.println("Enter the x-coordinate of the starting point for the bouncing logo (1-" + width + "):" );
x = in.nextInt()-1;
System.out.println("Enter the y-coordinate of the starting point for the bouncing logo (1-" + height + "):");
y = in.nextInt()-1;
System.out.println("\n\n"+logoWillHitCorner(x,y,width,height));
in.close();
}
public static boolean logoWillHitCorner(int x, int y, int width, int height) {
HashSet<Integer> UpLeft = new HashSet<Integer>();
HashSet<Integer> UpRight = new HashSet<Integer>();
HashSet<Integer> DownLeft = new HashSet<Integer>();
HashSet<Integer> DownRight = new HashSet<Integer>();
height -= 143;
width -= 143;
int xdelta = 1;
int ydelta = 1;
while (true){
x += xdelta;
y += ydelta;
if (xdelta == 1 && ydelta == 1){
if (DownRight.contains(x+y*width)){
return false;
}
DownRight.add(x+y*width);
}else if(xdelta == 1 && ydelta == -1){
if(UpRight.contains(x+y*width)){
return false;
}
UpRight.add(x+y*width);
}else if(xdelta == -1 && ydelta == 1){
if (DownLeft.contains(x+y*width)){
return false;
}
DownLeft.add(x+y*width);
}else{
if (UpLeft.contains(x+y*width)){
return false;
}
UpLeft.add(x+y*width);
}
if ((x == 0 && y == 0)||(x == 0 && y == height-1)||(x== width-1 && y==0)||(x==width-1 && y == height-1)){
return true;
}
if (x==0){
xdelta = 1;
// System.out.println("Left Wall "+y);
}else if (x==width-1){
xdelta = -1;
// System.out.println("Right Wall "+y);
}else if (y==0){
ydelta = 1;
// System.out.println("Ceiling "+x);
}else if (y==height-1){
ydelta = -1;
// System.out.println("Floor "+x);
}
}
}
}