-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathController.java
More file actions
109 lines (103 loc) · 3.44 KB
/
Copy pathController.java
File metadata and controls
109 lines (103 loc) · 3.44 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package application;
import javafx.scene.shape.Rectangle;
public class Controller {
// Getting the numbers and the MESH from Tetris
public static final int MOVE = Tetris.MOVE;
public static final int SIZE = Tetris.SIZE;
public static int XMAX = Tetris.XMAX;
public static int YMAX = Tetris.YMAX;
public static int[][] MESH = Tetris.MESH;
public static void MoveRight(Form form) {
if (form.a.getX() + MOVE <= XMAX - SIZE && form.b.getX() + MOVE <= XMAX - SIZE
&& form.c.getX() + MOVE <= XMAX - SIZE && form.d.getX() + MOVE <= XMAX - SIZE) {
int movea = MESH[((int) form.a.getX() / SIZE) + 1][((int) form.a.getY() / SIZE)];
int moveb = MESH[((int) form.b.getX() / SIZE) + 1][((int) form.b.getY() / SIZE)];
int movec = MESH[((int) form.c.getX() / SIZE) + 1][((int) form.c.getY() / SIZE)];
int moved = MESH[((int) form.d.getX() / SIZE) + 1][((int) form.d.getY() / SIZE)];
if (movea == 0 && movea == moveb && moveb == movec && movec == moved) {
form.a.setX(form.a.getX() + MOVE);
form.b.setX(form.b.getX() + MOVE);
form.c.setX(form.c.getX() + MOVE);
form.d.setX(form.d.getX() + MOVE);
}
}
}
public static void MoveLeft(Form form) {
if (form.a.getX() - MOVE >= 0 && form.b.getX() - MOVE >= 0 && form.c.getX() - MOVE >= 0
&& form.d.getX() - MOVE >= 0) {
int movea = MESH[((int) form.a.getX() / SIZE) - 1][((int) form.a.getY() / SIZE)];
int moveb = MESH[((int) form.b.getX() / SIZE) - 1][((int) form.b.getY() / SIZE)];
int movec = MESH[((int) form.c.getX() / SIZE) - 1][((int) form.c.getY() / SIZE)];
int moved = MESH[((int) form.d.getX() / SIZE) - 1][((int) form.d.getY() / SIZE)];
if (movea == 0 && movea == moveb && moveb == movec && movec == moved) {
form.a.setX(form.a.getX() - MOVE);
form.b.setX(form.b.getX() - MOVE);
form.c.setX(form.c.getX() - MOVE);
form.d.setX(form.d.getX() - MOVE);
}
}
}
public static Form makeRect() {
int block = (int) (Math.random() * 100);
String name;
Rectangle a = new Rectangle(SIZE-1, SIZE-1), b = new Rectangle(SIZE-1, SIZE-1), c = new Rectangle(SIZE-1, SIZE-1),
d = new Rectangle(SIZE-1, SIZE-1);
if (block < 15) {
a.setX(XMAX / 2 - SIZE);
b.setX(XMAX / 2 - SIZE);
b.setY(SIZE);
c.setX(XMAX / 2);
c.setY(SIZE);
d.setX(XMAX / 2 + SIZE);
d.setY(SIZE);
name = "j";
} else if (block < 30) {
a.setX(XMAX / 2 + SIZE);
b.setX(XMAX / 2 - SIZE);
b.setY(SIZE);
c.setX(XMAX / 2);
c.setY(SIZE);
d.setX(XMAX / 2 + SIZE);
d.setY(SIZE);
name = "l";
} else if (block < 45) {
a.setX(XMAX / 2 - SIZE);
b.setX(XMAX / 2);
c.setX(XMAX / 2 - SIZE);
c.setY(SIZE);
d.setX(XMAX / 2);
d.setY(SIZE);
name = "o";
} else if (block < 60) {
a.setX(XMAX / 2 + SIZE);
b.setX(XMAX / 2);
c.setX(XMAX / 2);
c.setY(SIZE);
d.setX(XMAX / 2 - SIZE);
d.setY(SIZE);
name = "s";
} else if (block < 75) {
a.setX(XMAX / 2 - SIZE);
b.setX(XMAX / 2);
c.setX(XMAX / 2);
c.setY(SIZE);
d.setX(XMAX / 2 + SIZE);
name = "t";
} else if (block < 90) {
a.setX(XMAX / 2 + SIZE);
b.setX(XMAX / 2);
c.setX(XMAX / 2 + SIZE);
c.setY(SIZE);
d.setX(XMAX / 2 + SIZE + SIZE);
d.setY(SIZE);
name = "z";
} else {
a.setX(XMAX / 2 - SIZE - SIZE);
b.setX(XMAX / 2 - SIZE);
c.setX(XMAX / 2);
d.setX(XMAX / 2 + SIZE);
name = "i";
}
return new Form(a, b, c, d, name);
}
}