-
Notifications
You must be signed in to change notification settings - Fork 0
/
four_and_five.patch
445 lines (390 loc) · 16.9 KB
/
four_and_five.patch
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
Index: src/felix/gridgame/Grid.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/felix/gridgame/Grid.java (revision d5ab2a2d36d4c21a45a93d39b75ce1bd81f15a60)
+++ src/felix/gridgame/Grid.java (date 1585349782154)
@@ -12,39 +12,45 @@
private Random r = new Random();
- public Grid(int x_size, int y_size, int numberOfColors){
+ public Grid(int x_size, int y_size, int numberOfColors) {
this.x_size = x_size;
this.y_size = y_size;
this.numberOfColors = numberOfColors;
}
- public int getPoints(){ return this.points; }
+ public int getPoints() {
+ return this.points;
+ }
- public int getSpecialGrid(int x, int y){ return this.specialGrid[x][y];}
+ public int getSpecialGrid(int x, int y) {
+ return this.specialGrid[x][y];
+ }
- public void setSpecialGrid(int element, int x, int y){ this.specialGrid[x][y] = element;}
+ public void setSpecialGrid(int element, int x, int y) {
+ this.specialGrid[x][y] = element;
+ }
- public void setPointsToZero(){
+ public void setPointsToZero() {
this.points = 0;
}
- public void setGrid(int value, int x, int y){
+ public void setGrid(int value, int x, int y) {
grid[x][y] = value;
}
- public int getGrid(int x, int y){
+ public int getGrid(int x, int y) {
return grid[x][y];
}
- public void generateRandomArray(){
+ public void generateRandomArray() {
grid = new int[x_size][y_size];
// set the special array to 0's
specialGrid = new int[x_size][y_size];
- for(int x_iterator = 0; x_iterator < x_size; x_iterator++){
- for(int y_iterator = 0; y_iterator < y_size; y_iterator++){
+ for (int x_iterator = 0; x_iterator < x_size; x_iterator++) {
+ for (int y_iterator = 0; y_iterator < y_size; y_iterator++) {
grid[x_iterator][y_iterator] = r.nextInt(numberOfColors);
specialGrid[x_iterator][y_iterator] = 0;
}
@@ -52,10 +58,10 @@
}
- public boolean checkGrid(int x1, int x2, int y1, int y2, boolean mouseClick){
+ public boolean checkGrid(int x1, int x2, int y1, int y2, boolean mouseClick) {
// true = changes!, false = no changes
- if(checkGridHorizontal(x1, x2, mouseClick)) return true;
- return checkGridVertical(x1, x2, y1, y2, mouseClick);
+ if (checkGridHorizontal(x1, x2, mouseClick)) return true;
+ return checkGridVertical(y1, y2, mouseClick);
}
@@ -85,8 +91,9 @@
}
} else {
- isFour = false;
horizontalRepeats = 1;
+
+ isFour = false;
}
if (horizontalRepeats == 3) {
@@ -111,19 +118,20 @@
}
}
}
- if(breakLoop) {
+ if (breakLoop) {
int x_end = x_col;
- if(horizontalRepeats > 3) x_end += horizontalRepeats-3;
- int x_start = (x_end - (horizontalRepeats-1));
+ if (horizontalRepeats > 3) x_end += horizontalRepeats - 3;
+ int x_start = (x_end - (horizontalRepeats - 1));
- if(mouseClick) points += x_end - x_start + 1;
+ if (mouseClick) points += x_end - x_start + 1;
- if(!mouseClick) {
- x1 = x_start+1;
- x2 = x_start+1;
+ if (!mouseClick) {
+ x1 = x_start + 1;
+ x2 = x_start + 1;
}
- removeFromRow(x1, x2, x_start, x_end, y_row);
+ if (isFour) combineFour(y_row, false);
+ else removeFromRow(x1, x2, x_start, x_end, y_row);
return true; // changes!
}
@@ -133,36 +141,36 @@
private void removeFromRow(int click1, int click2, int x_start, int x_end, int row) {
int dif = x_end - x_start;
- int element = grid[x_start+1][row];
+ int element = grid[x_start + 1][row];
- for(int y_iterator = row; y_iterator >= 0; y_iterator--){
- for(int x_iterator = x_start; x_iterator <= x_end; x_iterator++){
- if(y_iterator == 0){
+ for (int y_iterator = row; y_iterator >= 0; y_iterator--) {
+ for (int x_iterator = x_start; x_iterator <= x_end; x_iterator++) {
+ if (y_iterator == 0) {
grid[x_iterator][y_iterator] = r.nextInt(numberOfColors);
- }else {
- grid[x_iterator][y_iterator] = grid[x_iterator][y_iterator-1];
+ } else {
+ grid[x_iterator][y_iterator] = grid[x_iterator][y_iterator - 1];
}
}
}
+ // check where where we should place an four/five elemnt
boolean isClick1 = false;
- for(int i = 0; i <= dif; i ++){
- if((x_start + i) == click1) {
+ for (int i = 0; i <= dif; i++) {
+ if ((x_start + i) == click1) {
isClick1 = true;
break;
}
}
int xRemove;
- if(isClick1) xRemove = click1;
+ if (isClick1) xRemove = click1;
else xRemove = click2;
- if((dif+1) == 4) {
+ if ((dif + 1) == 4) {
System.out.println("Four!!!");
setSpecialElement(element, xRemove, row, true);
- }
- else if((dif+2) >= 5) {
+ } else if ((dif + 2) >= 5) {
System.out.println("Five!!!");
setSpecialElement(element, xRemove, row, false);
}
@@ -170,8 +178,9 @@
}
+ private boolean checkGridVertical(int y1, int y2, boolean mouseClick) {
+ boolean isFour = false;
- private boolean checkGridVertical(int x1, int x2, int y1, int y2, boolean mouseClick) {
int verticalRepeats = 1;
int lastNumber;
int actualNumber;
@@ -184,11 +193,19 @@
actualNumber = grid[x_iterator][y_iterator];
if (y_iterator - 1 < 0) lastNumber = 999;
- else lastNumber = grid[x_iterator][y_iterator-1];
+ else lastNumber = grid[x_iterator][y_iterator - 1];
if (actualNumber == lastNumber) {
verticalRepeats++;
- } else verticalRepeats = 1;
+
+ if (specialGrid[x_iterator][y_iterator] == 4) {
+ isFour = true;
+ }
+
+ } else {
+ verticalRepeats = 1;
+ isFour = false;
+ }
if (verticalRepeats == 3) {
@@ -199,7 +216,7 @@
//checks that we are in the grid
if ((y_iterator + i) > (y_size - 1)) break;
- int nextNumber = grid[x_iterator][y_iterator+1];
+ int nextNumber = grid[x_iterator][y_iterator + 1];
if (nextNumber == actualNumber) verticalRepeats++;
else break;
@@ -213,64 +230,84 @@
}
}
}
- if(breakLoop) {
+ if (breakLoop) {
int y_end = y_row;
- if(verticalRepeats > 3) y_end += verticalRepeats-3;
- int y_start = (y_end - (verticalRepeats-1));
+ if (verticalRepeats > 3) y_end += verticalRepeats - 3;
+ int y_start = (y_end - (verticalRepeats - 1));
- if(mouseClick) points += y_end - y_start + 1;
+ if (mouseClick) points += y_end - y_start + 1;
- removeFromCol(y_start, y_end, x_col);
+ if (!mouseClick) {
+ y1 = y_start + 1;
+ y2 = y_start + 1;
+ }
+
+ if (isFour) combineFour(x_col, true);
+ else removeFromCol(y1, y2, y_start, y_end, x_col);
return true; // changes!
}
return false; // no changes
}
- private void removeFromCol(int y_start, int y_end, int col){
+
+ private void removeFromCol(int click1, int click2, int y_start, int y_end, int col) {
int dif = y_end - y_start;
- int element = grid[col][y_start+1];
+ int element = grid[col][y_start + 1];
- for(int y_iterator = y_end; y_iterator >= 0; y_iterator--){
- if( (y_iterator-dif) >= 0){
- grid[col][y_iterator] = grid[col][y_iterator-dif];
- }
- else{
+ for (int y_iterator = y_end; y_iterator >= 0; y_iterator--) {
+ if ((y_iterator - dif) >= 0) {
+ grid[col][y_iterator] = grid[col][y_iterator - dif];
+ } else {
grid[col][y_iterator] = r.nextInt(numberOfColors);
}
}
- if((dif+1) == 4) {
+ boolean isClick1 = false;
+
+ for (int i = 0; i <= dif; i++) {
+ if ((y_start + i) == click1) {
+ isClick1 = true;
+ return;
+ }
+ }
+
+ int yRemove;
+ if (isClick1) yRemove = click1;
+ else yRemove = click2;
+
+
+ if ((dif + 1) == 4) {
System.out.println("Four!!!");
- setSpecialElement(element, col, y_start+1, true);
- }
- else if((dif+2) >= 5) {
+ setSpecialElement(element, col, yRemove, true);
+ } else if ((dif + 2) >= 5) {
System.out.println("Five!!!");
- setSpecialElement(element, col, y_start+1, false);
+ setSpecialElement(element, col, yRemove, false);
}
}
+
- private void setSpecialElement(int element, int x, int y, boolean isFour){
+ private void setSpecialElement(int element, int x, int y, boolean isFour) {
// four Elements in one row/col
- if(isFour) specialGrid[x][y] = 4;
+ if (isFour) specialGrid[x][y] = 4;
- // five elements in one row/col
+ // five elements in one row/col
else specialGrid[x][y] = 5;
grid[x][y] = element;
}
- public void combineFive(int elementToRemove){
-
- for(int x_iterator = 0; x_iterator < x_size; x_iterator++){
- for(int y_iterator = 0; y_iterator < y_size; y_iterator++){
+
+ public void combineFive(int elementToRemove) {
+ for (int x_iterator = 0; x_iterator < x_size; x_iterator++) {
+ for (int y_iterator = 0; y_iterator < y_size; y_iterator++) {
int el = grid[x_iterator][y_iterator];
- if(elementToRemove == el){
+ if (elementToRemove == el) {
int yToTop = y_iterator;
- while(yToTop > 0){
- grid[x_iterator][yToTop] = grid[x_iterator][yToTop-1];
+ while (yToTop > 0) {
+ grid[x_iterator][yToTop] = grid[x_iterator][yToTop - 1];
yToTop--;
}
@@ -280,27 +317,28 @@
}
}
- public void combineFour(int rowOrCol, boolean isLine){
- if(isLine){
- // remove line
- for(int i = 0; i < x_size; i++)
- for(int toTop = rowOrCol; toTop >= 0; toTop--) {
- if(toTop != 0) {
+
+ public void combineFour(int rowOrCol, boolean isLine) {
+ if (isLine) {
+ System.out.println("Remove line");
+ for (int i = 0; i < x_size; i++) {
+ for (int toTop = rowOrCol; toTop >= 0; toTop--) {
+ if (toTop != 0) {
grid[i][toTop] = grid[i][toTop - 1];
- }else {
+ } else {
grid[i][toTop] = r.nextInt(numberOfColors);
}
}
}
-
- System.out.println("REmove line");
} else {
// remove column
- System.out.println("REmove column");
+ System.out.println("Remove column");
+
+ for (int i = 0; i < y_size; i++) {
+ grid[i][rowOrCol] = r.nextInt(numberOfColors);
+ }
}
-
- r.nextInt(numberOfColors);
}
Index: .idea/inspectionProfiles/Project_Default.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- .idea/inspectionProfiles/Project_Default.xml (date 1585349155222)
+++ .idea/inspectionProfiles/Project_Default.xml (date 1585349155222)
@@ -0,0 +1,10 @@
+<component name="InspectionProjectProfileManager">
+ <profile version="1.0">
+ <option name="myName" value="Project Default" />
+ <inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
+ <Languages>
+ <language minSize="60" name="Java" />
+ </Languages>
+ </inspection_tool>
+ </profile>
+</component>
\ No newline at end of file
diff --git out/production/testGame/felix/gridgame/Grid.class out/production/testGame/felix/gridgame/Grid.class
index f6dc2052acffa968cef14d354639853b40a189dc..6e3e988cd82dd31c67334ac73a85639fa82b128f
GIT binary patch
literal 5843
zc$~FYdvH|M9sbVVyYHKXBwRw0-4NbkwTT2+H6T91!zdC;D3pLCOL7xdHrcS*V1l+q
zjkHunt$hrN6_IILi_am!(N2xEt&g_!{fE=(W2_ym(@v-DOgn0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