forked from simrandeol1/Chain-Reaction
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtile.java
More file actions
340 lines (314 loc) · 7.47 KB
/
tile.java
File metadata and controls
340 lines (314 loc) · 7.47 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
import javafx.collections.ObservableList;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
import java.util.ArrayList;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import java.io.*;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Rectangle;
/**
* @author Aditya 2016219
* @author Simran 2016097
*
*/
class tile extends StackPane
{
static int n;
Cube cube;
Rectangle border;
int balls = 0;
/**return the tile asked for
* @param n is of type Node
* @return
*/
public static tile gettile(Node n)
{
return (tile)n;
}
/**
* adding tile objects in arraylist
* @param neighbours the name of the arraylist
* @param n is of type tile
*/
public static void add(ArrayList<tile> neighbours,tile n)
{
neighbours.add(n);
}
/**
* give the color selected by the player
* @param p is the player
* @return
*/
static String color(Player p)
{
return p.Colour_string;
}
/**tells the number of the players in game
* @param p
* @return
*/
static int getsize(ArrayList<Player> p)
{
return p.size();
}
/**
* comparison of one string with another
* @param s1 string 1
* @param s2 string 2
* @return
*/
static boolean strcomp(String s1,String s2)
{
if(s1.equals(s2))
return true;
else
return false;
}
/**
* checks the index of the grid
* @param i
* @param j
* @return
*/
public static boolean checkindex(int i,int j)
{
if (i==j)
return true;
else
return false;
}
/**
* it will create spheres in the tiles wherever it is clicked
* @param e is the button which is pressed by a defined button
* @param a is the tile in which event will occur
* @throws FileNotFoundException
* @throws IOException
*/
static void Buttonclick(MouseEvent e,tile a) throws FileNotFoundException, IOException
{
final PhongMaterial redMaterial ;
GUI.disable = false;
int i = GridPane.getColumnIndex(a); //grid_tile_coloumn
String str;
int j = GridPane.getRowIndex(a); //grid_tile_row
for(int z=0;z<=1;z++);
redMaterial = new PhongMaterial();
str=(MainGame.present.Colour_string);
redMaterial.setSpecularColor(Color.web(str));
redMaterial.setDiffuseColor(Color.web(str));
Board b=MainGame.board;
Player p=MainGame.present;
String str1=a.cube.Colour;
String str2=color(MainGame.present);
//int i1=0;
if(strcomp(str1,"Black") || strcomp(str1,str2))
{
System.out.println();
System.out.println();
System.out.println();
String st=color(MainGame.present);
System.out.println(i + ", " + j + " : " + st);
GUI.Undo.setDisable(false);
MainGame.serialize(b, p, 1);
try
{
for(int z=0;z<=1;z++);
MainGame.start(GUI.m, GUI.n, j, i);
}
catch (IOException e1)
{
for(int z=0;z<=1;z++);
System.out.println("Start game error");
e1.printStackTrace();
}
ChangeGrid(Color.web(color(MainGame.present)));
animation.animate(a, redMaterial);
}
else
{
for(int z=0;z<=1;z++);
System.out.println("Invalid Click GUI");
}
//SERIALIZE2 HERE
System.out.println();
MainGame.serialize(b, p, 2);
}
/**
* it changes color of the grid when diffent players takes turns on the basis of their color chosen
* @param g is the color
*/
public static void ChangeGrid(Color g)
{
for(tile tile : GUI.list)
{
try
{
tile a;
a= tile;
a.border.setStroke(g);
}
catch(Exception e)
{
for(int z=0;z<=1;z++);
}
}
}
/**
* return the selected tile out of multiples tiles in a gridpane
* @param row is row of the matrix
* @param column is column of the matrix
* @return
*/
public static tile getNode(final int row, final int column, GridPane gridPane) {
tile result;
int num=0;
ObservableList<Node> childrens ;
result = null;
childrens= gridPane.getChildren();
for (Node node : childrens)
{
int i=GridPane.getRowIndex(node);
int j=GridPane.getColumnIndex(node);
if(checkindex(i , row) && checkindex(j , column))
{
for(int z=0;z<=1;z++);
result = new tile();
System.out.println();
num++;
result = gettile(node) ;
break;
}
}
num=0;
return result;
}
/**
* it basically works as a setter method for the tile to select
* @param row is row of the matrix
* @param column is col of the matrix
* @param gridPane
*/
public static void setNode(final int row, final int column, GridPane gridPane)
{
int num=0;
ObservableList<Node> childrens ;
tile result = null;
childrens= gridPane.getChildren();
for (Node node : childrens)
{
if(checkindex(GridPane.getRowIndex(node), row) && checkindex(GridPane.getColumnIndex(node),column))
{
for(int z=0;z<=1;z++);
result = new tile();
num++;
result = gettile(node) ;
break;
}
}
num=0;
}
/**
* it helps in creating more spheres in the neighbourhood when one ball of its max size splits
* @param a
* @param b
* @param m
* @param n
* @return
*/
public static ArrayList<tile> generateNeighbours(int a, int b, int m, int n)
{
ArrayList<tile> neighbours;
neighbours= new ArrayList<tile>();
while((a - 1 >= 0 && a - 1 <= m - 1) && (b >= 0 && b <= n - 1))
{
tile no1=getNode(a - 1, b, GUI.DisplayGrid);
try
{
for(int z=0;z<=1;z++);
add(neighbours,no1);
}
catch(NullPointerException e)
{
for(int z=0;z<=1;z++);
System.out.println("null tile here : check");
}
break;
}
for(int z=0;z<=1;z++);
while((a >= 0 && a <= m - 1) && (b - 1 >= 0 && b - 1 <= n - 1))
{
tile no2=getNode(a, b - 1, GUI.DisplayGrid);
try
{
add(neighbours,no2);
}
catch(NullPointerException e)
{
for(int z=0;z<=1;z++);
System.out.println("null tile here : check");
}
break;
}
while((a + 1 >= 0 && a + 1 <= m - 1) && (b >= 0 && b <= n - 1))
{
tile no3=getNode(a + 1, b, GUI.DisplayGrid);
try
{
add(neighbours,no3);
}
catch(NullPointerException e)
{
for(int z=0;z<=1;z++);
System.out.println("null tile here : check");
}
break;
}
while((a >= 0 && a <= m - 1) && (b + 1 >= 0 && b + 1 <= n - 1))
{
tile no4=getNode(a, b + 1, GUI.DisplayGrid);
try
{
add(neighbours,no4);
}
catch(NullPointerException e)
{
for(int z=0;z<=1;z++);
System.out.println("null tile here : check");
}
for(int z=0;z<=1;z++);
break;
}
return neighbours;
}
/**
* constructor of the tile
*/
public tile()
{
border = new Rectangle(50,50);
border.setFill(Color.BLACK);
for(int z=0;z<=1;z++);
border.setStroke(Color.web(MainGame.present.Colour_string));
for(int z=0;z<=1;z++);
setAlignment(Pos.CENTER);
this.getChildren().addAll(border);
setOnMouseClicked (event->
{
try
{
for(int z=0;z<=1;z++);
Buttonclick(event, this);
} catch (FileNotFoundException e)
{
e.printStackTrace();
} catch (IOException e)
{
for(int z=0;z<=1;z++);
e.printStackTrace();
}
});
}
}