@matfah/

Tile Game FR 2009

Java

No description

fork
loading
Files
  • Main.java
  • NumberTile.java
  • TileGame.java

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.7197009841797464","path":"Main.java","file":{"path":"Main.java","content":{"asEncoding":{"base64":"aW1wb3J0IGphdmEudXRpbC5BcnJheUxpc3Q7CmltcG9ydCBqYXZhLmxhbmcucmVmbGVjdC4qOwoKcHVibGljIGNsYXNzIE1haW4gewogIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKICAgIHRlc3RHZXRJbmRleEZvckZpdCgpOwogICAgU3lzdGVtLm91dC5wcmludGxuKCJnZXRJbmRleEZvckZpdCgpLi4uIHBhc3NlZCEiKTsKICAgIAogICAgdGVzdEluc2VydFRpbGUoKTsKICAgIFN5c3RlbS5vdXQucHJpbnRsbigiaW5zZXJ0VGlsZSgpLi4uIHBhc3NlZCEiKTsKICAgIAogICAgU3lzdGVtLm91dC5wcmludGxuKCJBbGwgdGVzdHMgcGFzc2VkISIpOwogIH0KICAKICBwdWJsaWMgc3RhdGljIHZvaWQgdGVzdEdldEluZGV4Rm9yRml0KCkgewogICAgCiAgICBGaWVsZCBib2FyZEZpZWxkID0gbnVsbDsKICAgIAogICAgdHJ5IHsKICAgICAgYm9hcmRGaWVsZCA9IFRpbGVHYW1lLmNsYXNzLmdldERlY2xhcmVkRmllbGQoImJvYXJkIik7CiAgICB9CiAgICBjYXRjaChFeGNlcHRpb24gZSkgewogICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIkVycm9yIHRyeWluZyB0byBhY2Nlc3MgdGhlIGJvYXJkIGZpZWxkIG9mIHRoZSBUaWxlR2FtZSBjbGFzcyIpOwogICAgICBTeXN0ZW0uZXhpdCgwKTsKICAgIH0KICAgIAogICAgTWV0aG9kIG0gPSBudWxsOwogICAgCiAgICB0cnkgewogICAgICBtID0gVGlsZUdhbWUuY2xhc3MuZ2V0RGVjbGFyZWRNZX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l0OwogICAgICAgIAogICAgICAgIGlmKGMhPSB0b0FkZCAmJiBjLnJvdGF0ZUNvdW50ICE9IDApIHsKICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiaW5zZXJ0VGlsZSgpIHNob3VsZCBOT1Qgcm90YXRlIGFueSB0aWxlcyBpbiB0aGUgYm9hcmQgbGlzdCEiKTsKICAgICAgICAgIFN5c3RlbS5leGl0KDApOwogICAgICAgIH0KICAgICAgfQogICAgICAKICAgICAgaW50IGluc2VydGlvblNwb3QgPSBsaXN0LmluZGV4T2YodG9BZGQpOwogICAgICAKICAgICAgaWYoKGluc2VydGlvblNwb3QgIT0gLTEpICE9IHJlc3VsdCkgewogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiaW5zZXJUaWxlKCkncyBib29sZWFuIHJldHVybmVkIHZhbHVlIGlzIHdyb25nIik7CiAgICAgICAgU3lzdGVtLmV4aXQoMCk7CiAgICAgIH0KICAgICAgCiAgICAgIGlmKGluc2VydGlvblNwb3QgIT0gLTEpIHsKICAgICAgICBsaXN0LnJlbW92ZShpbnNlcnRpb25TcG90KTsKICAgICAgfQogICAgICAKICAgICAgU3RyaW5nIHN0cmluZ0luZm8yPSAiIjsKICAgICAgZm9yKE51bWJlclRpbGUgdCA6IGxpc3QpIHsKICAgICAgICBzdHJpbmdJbmZvMiArPSB0OwogICAgICB9CiAgICAgIAogICAgICBpZighc3RyaW5nSW5mby5lcXVhbHMoc3RyaW5nSW5mbzIpKSB7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJpbnNlclRpbGUoKSBzaG91bGQgTk9UIGNoYW5nZSB0aGUgb3RoZXIgdGlsZXMgaW4gdGhlIGJvYXJkIGxpc3QhIik7CiAgICAgICAgU3lzdGVtLmV4aXQoMCk7CiAgICAgIH0KICAgICAgCiAgICAgIGlmKGluc2VydGlvblNwb3QgPT0gLTEpIHsKICAgICAgICAKICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgNDsgaSsrKSB7CiAgICAgICAgICAKICAgICAgICAgIGlmKCBsZWZ0UmlnaHRzLmluZGV4T2YodG9BZGQucmlnaHQrIiIpID09IDAgfHwKICAgICAgICAgICAgICBsZWZ0UmlnaHRzLmxhc3RJbmRleE9mKHRvQWRkLmxlZnQrIiIpID09IGxlZnRSaWdodHMubGVuZ3RoKCktMSB8fAogICAgICAgICAgICAgIGxlZnRSaWdodHMuaW5kZXhPZih0b0FkZC5sZWZ0ICsgIiIgKyB0b0FkZC5yaWdodCkgIT0gLTEpIHsKICAgICAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiaW5zZXJUaWxlKCkgaXMgbm90IGluc2VydGluZyBhIFRpbGUgd2hlbiBpdCBzaG91bGQhIik7CiAgICAgICAgICAgICAgICBTeXN0ZW0uZXhpdCgwKTsKICAgICAgICAgIH0KICAgICAgICAgIHRvQWRkLnJvdGF0ZSgpOwogICAgICAgICAgCiAgICAgICAgfQogICAgICAgIAogICAgICB9CiAgICAgIGVsc2UgewogICAgICAgIGlmKGluc2VydGlvblNwb3QgPT0gMCAmJiBsaXN0LnNpemUoKSA9PSAwKSB7CiAgICAgICAgICAvL3RoaXMgaXMgb2theSEKICAgICAgICB9CiAgICAgICAgZWxzZSBpZihpbnNlcnRpb25TcG90ID09IDAgJiYgbGVmdFJpZ2h0cy5pbmRleE9mKHRvQWRkLnJpZ2h0KyIiKSAhPSAwIHx8CiAgICAgICAgICAgaW5zZXJ0aW9uU3BvdCA9PSBsaXN0LnNpemUoKSAmJiBsZWZ0UmlnaHRzLmxhc3RJbmRleE9mKHRvQWRkLmxlZnQrIiIpICE9IGxlZnRSaWdodHMubGVuZ3RoKCktMSkgewogICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJpbnNlclRpbGUoKSBpcyBpbnNlcnRpbmcgYSB0aWxlIGluIHRoZSB3cm9uZyBzcG90IDEuLi4iKTsKICAgICAgICAgICAgIFN5c3RlbS5leGl0KDApOwogICAgICAgIH0KICAgICAgICB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cm4gbGVmdDsKICB9CiAgCiAgcHVibGljIGludCBnZXRSaWdodCgpIHsKICAgIHJldHVybiByaWdodDsKICB9CiAgCn0="},"asBuffer":null},"loaded":true}}
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
import java.util.ArrayList;
import java.lang.reflect.*;

public class Main {
  public static void main(String[] args) {
    testGetIndexForFit();
    System.out.println("getIndexForFit()... passed!");
    
    testInsertTile();
    System.out.println("insertTile()... passed!");
    
    System.out.println("All tests passed!");
  }
  
  public static void testGetIndexForFit() {
    
    Field boardField = null;
    
    try {
      boardField = TileGame.class.getDeclaredField("board");
    }
    catch(Exception e) {
      System.out.println("Error trying to access the board field of the TileGame class");
      System.exit(0);
    }
    
    Method m = null;
    
    try {
      m = TileGame.class.getDeclaredMethod("getIndexForFit", NumberTile.class);
    }
    catch(Exception e) {
      System.out.println("Error trying to access the getIndexForFit() method of the TileGame class");
      System.exit(0);
    }
    
    boardField.setAccessible(true);
    m.setAccessible(true);
    
    for(int numTiles = 20; numTiles >= 0; numTiles--) {
    
      TileGame game = new TileGame();
      ArrayList<NumberTile> list = null;
      
      try {
        list = (ArrayList<NumberTile>)boardField.get(game);
      }
      catch(Exception e) {
        e.printStackTrace();
        System.exit(0);
      }
      
      String stringInfo = "";
      String leftRights = "";
      
      for(int i = numTiles; i > 0; i--) {
        CustomNumberTile tile = new CustomNumberTile();
        leftRights += tile.left + "_" + tile.right;
        stringInfo += tile;
        list.add(tile);
      }
      
      CustomNumberTile toAdd = new CustomNumberTile();
      
      int result = 0;
      
      try {
        result = (Integer)m.invoke(game,toAdd);
      }
      catch(Exception e) {
        System.out.println("Error trying to call getIndexForFit() of the TileGame class");
        System.exit(0);
      }
      
      ArrayList<NumberTile> postList = null;
      try {
        postList = (ArrayList<NumberTile>)boardField.get(game);
      }
      catch(Exception e) {
        System.out.println("Error trying to access the board field of the TileGame class");
        System.exit(0);
      }
      
      if(list != postList) {
        System.out.println("You should NOT be assigning the board instance variable!");
        System.exit(0);
      }
      
      String stringInfo2= "";
      for(NumberTile t : list) {
        stringInfo2 += t;
      }
      
      if(!stringInfo.equals(stringInfo2)) {
        System.out.println("getIndexForFit() should NOT modify the board instance variable!");
        System.exit(0);
      }
      
      //now make sure they don't rotate anything
      
      for(NumberTile t: list) {
        CustomNumberTile c = (CustomNumberTile)t;
        
        if(c.rotateCount != 0) {
          System.out.println("getIndexForFit() should NOT rotate any tiles!");
          System.exit(0);
        }
      }
      
      if(toAdd.rotateCount != 0) {
        System.out.println("getIndexForFit() should NOT rotate any tiles!");
        System.exit(0);
      }
      
      //now make sure their insert position makes sense!
      
      if(result < -1 || result > list.size()) {
        System.out.println("getIndexForFit() returns an invalid position");
        System.exit(0);
      }
      else if(result == 0) {
        if(list.size() != 0 && list.get(0).getLeft() != toAdd.getRight()) {
          System.out.println("getIndexForFit() returns the wrong position");
          System.exit(0);
        }
      }
      else if(result == list.size()) {
        if(list.get(list.size()-1).getRight() != toAdd.getLeft()) {
          System.out.println("getIndexForFit() returns the wrong position");
          System.exit(0);
        }
      }
      else if(result != -1) {
        if(list.get(result-1).getRight() != toAdd.getLeft() ||
           list.get(result).getLeft() != toAdd.getRight()) {
             System.out.println("getIndexForFit() returns the wrong position");
             System.exit(0);
        }
      }
      else { //they claim there is no insertion spot...
        if(leftRights.indexOf(toAdd.left + "" + toAdd.right) != -1) {
          System.out.println(leftRights + " " + toAdd.left + toAdd.right);
          System.out.println("getIndexForFit() says there isn't an insertion spot when there is one!");
          System.exit(0);
        }
      }
    }
    
    
  }
  
  public static void testInsertTile() {
    Field boardField = null;
    
    try {
      boardField = TileGame.class.getDeclaredField("board");
    }
    catch(Exception e) {
      System.out.println("Error trying to access the board field of the TileGame class");
      System.exit(0);
    }
    
    Method m = null;
    
    try {
      m = TileGame.class.getDeclaredMethod("insertTile", NumberTile.class);
    }
    catch(Exception e) {
      System.out.println("Error trying to access the insertTile() method of the TileGame class");
      System.exit(0);
    }
    
    boardField.setAccessible(true);
    m.setAccessible(true);
    
    for(int numTiles = 20; numTiles >= 0; numTiles--) {
    
      TileGame game = new TileGame();
      ArrayList<NumberTile> list = null;
      
      try {
        list = (ArrayList<NumberTile>)boardField.get(game);
      }
      catch(Exception e) {
        e.printStackTrace();
        System.exit(0);
      }
      
      String stringInfo = "";
      String leftRights = "";

      for(int i = numTiles; i > 0; i--) {
        CustomNumberTile tile = new CustomNumberTile();
        stringInfo += tile;
        leftRights += tile.left + "_" + tile.right;
        list.add(tile);
      }
      
      CustomNumberTile toAdd = new CustomNumberTile();
      
      boolean result = false;
      
      try {
        result = (Boolean)m.invoke(game,toAdd);
      }
      catch(Exception e) {
        System.out.println("Error trying to call insertTile() of the TileGame class");
        System.exit(0);
      }
      
      ArrayList<NumberTile> postList = null;
      try {
        postList = (ArrayList<NumberTile>)boardField.get(game);
      }
      catch(Exception e) {
        System.out.println("Error trying to access the board field of the TileGame class");
        System.exit(0);
      }
      
      if(list != postList) {
        System.out.println("You should NOT be assigning the board instance variable!");
        System.exit(0);
      }
      
      
      //now make sure they don't rotate anything in list besides the toAdd tile
      for(NumberTile t: list) {
        CustomNumberTile c = (CustomNumberTile)t;
        
        if(c!= toAdd && c.rotateCount != 0) {
          System.out.println("insertTile() should NOT rotate any tiles in the board list!");
          System.exit(0);
        }
      }
      
      int insertionSpot = list.indexOf(toAdd);
      
      if((insertionSpot != -1) != result) {
        System.out.println("inserTile()'s boolean returned value is wrong");
        System.exit(0);
      }
      
      if(insertionSpot != -1) {
        list.remove(insertionSpot);
      }
      
      String stringInfo2= "";
      for(NumberTile t : list) {
        stringInfo2 += t;
      }
      
      if(!stringInfo.equals(stringInfo2)) {
        System.out.println("inserTile() should NOT change the other tiles in the board list!");
        System.exit(0);
      }
      
      if(insertionSpot == -1) {
        
        for(int i = 0; i < 4; i++) {
          
          if( leftRights.indexOf(toAdd.right+"") == 0 ||
              leftRights.lastIndexOf(toAdd.left+"") == leftRights.length()-1 ||
              leftRights.indexOf(toAdd.left + "" + toAdd.right) != -1) {
                System.out.println("inserTile() is not inserting a Tile when it should!");
                System.exit(0);
          }
          toAdd.rotate();
          
        }
        
      }
      else {
        if(insertionSpot == 0 && list.size() == 0) {
          //this is okay!
        }
        else if(insertionSpot == 0 && leftRights.indexOf(toAdd.right+"") != 0 ||
           insertionSpot == list.size() && leftRights.lastIndexOf(toAdd.left+"") != leftRights.length()-1) {
             System.out.println("inserTile() is inserting a tile in the wrong spot 1...");
             System.exit(0);
        }
        else if(insertionSpot > 0 && insertionSpot < list.size()) {
          if(list.get(insertionSpot-1).getRight() != toAdd.getLeft() ||
             list.get(insertionSpot).getLeft() != toAdd.getRight()) {
               System.out.println("inserTile() is inserting a tile in the wrong spot 2");
               System.exit(0);
          }
        }
        
      }
      
    }
  }
}

class CustomNumberTile extends NumberTile {
  
  int top, right, bottom, left;
  
  int rotateCount = 0;
  
  public CustomNumberTile() {
    top = (int)(Math.random()*5);
    right = (int)(Math.random()*5);
    bottom = (int)(Math.random()*5);
    left = (int)(Math.random()*5);
  }
  
  public void rotate() {
    int temp = left;
    left = bottom;
    bottom = right;
    right = top;
    top = temp;
    rotateCount++;
  }

  public int getLeft() {
    return left;
  }
  
  public int getRight() {
    return right;
  }
  
}