1 |
|
package game.shad.tempus.hearts; |
2 |
|
|
3 |
|
import java.text.DecimalFormat; |
4 |
|
import java.util.ArrayList; |
5 |
|
import java.util.concurrent.atomic.AtomicReference; |
6 |
|
|
7 |
|
|
8 |
|
import android.content.Context; |
9 |
|
import android.graphics.Canvas; |
10 |
|
import android.graphics.Color; |
11 |
|
import android.util.Log; |
12 |
|
import android.view.SurfaceHolder; |
13 |
|
import android.view.View; |
14 |
|
import android.widget.Toast; |
15 |
|
|
|
|
| 74,4% |
Uncovered Elements: 139 (542) |
Complexity: 99 |
Complexity Density: 0,24 |
|
16 |
|
public class GameThread extends Thread |
17 |
|
{ |
18 |
|
public static final String TAG = "Hearts--GameThread"; |
19 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
20 |
|
public enum State { |
21 |
|
RUNNING(), PAUSED(), DEAD(); |
22 |
|
} |
23 |
|
public volatile AtomicReference<State> state = new AtomicReference<GameThread.State>(State.PAUSED); |
24 |
|
public String eol = System.getProperty("line.separator"); |
25 |
|
|
26 |
|
private final static int MAX_FPS = 50; |
27 |
|
private final static int MAX_FRAME_SKIPS = 5; |
28 |
|
private final static int FRAME_PERIOD = 1000 / MAX_FPS; |
29 |
|
|
30 |
|
private DecimalFormat df = new DecimalFormat("0.##"); |
31 |
|
private final static int STAT_INTERVAL = 1000; |
32 |
|
private final static int FPS_HISTORY_NR = 10; |
33 |
|
private long statusIntervalTimer = 0l; |
34 |
|
private long totalFramesSkipped = 0l; |
35 |
|
private long framesSkippedPerStatCycle = 0l; |
36 |
|
|
37 |
|
private int frameCountPerStatCycle = 0; |
38 |
|
private long totalFrameCount = 0l; |
39 |
|
private double fpsStore[]; |
40 |
|
private long statsCount = 0; |
41 |
|
private double averageFps = 0.0; |
42 |
|
|
43 |
|
private SurfaceHolder surfaceHolder; |
44 |
|
private Game game; |
45 |
|
private MainActivity main; |
46 |
|
private Canvas canvas; |
47 |
|
private Context context; |
48 |
|
public GameView gameView; |
49 |
|
private boolean running; |
50 |
|
private boolean firstStart = false; |
51 |
|
private boolean justPickedUpPile = false; |
52 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
53 |
0
|
public void setRunning(boolean running){... |
54 |
0
|
this.running = running; |
55 |
|
} |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
|
57 |
8
|
public GameThread(Context context, MainActivity main, Game game, GameView gameView){... |
58 |
8
|
super(); |
59 |
8
|
this.gameView = gameView; |
60 |
8
|
this.context = context; |
61 |
8
|
this.main = main; |
62 |
8
|
this.game = game; |
63 |
|
} |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
64 |
8
|
public void firstInit(){... |
65 |
8
|
heartsMe(); |
66 |
8
|
main.gt.start(); |
67 |
|
|
68 |
|
} |
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 4 |
Complexity Density: 0,5 |
|
69 |
8
|
public void run(){... |
70 |
8
|
Thread.currentThread().setName("Craps Game Thread"); |
71 |
|
|
72 |
256
|
while (state.get() != State.DEAD) { |
73 |
248
|
try{ |
74 |
248
|
if(state.get() == State.PAUSED) { |
75 |
12
|
sleep(5000); |
76 |
|
} |
77 |
236
|
pause(420); |
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
224
|
main.gameView.update(); |
86 |
|
|
87 |
|
} catch(InterruptedException e){ |
88 |
24
|
Log.d(TAG, "Interrupted Exception!!! state=" + state.get(), e); |
89 |
|
} |
90 |
|
} |
91 |
|
} |
92 |
|
|
|
|
| 55,6% |
Uncovered Elements: 8 (18) |
Complexity: 2 |
Complexity Density: 0,12 |
|
93 |
8
|
public void heartsMe(){ ... |
94 |
8
|
Log.d(TAG, "start()"); |
95 |
|
|
96 |
|
|
97 |
8
|
if(game.restart){ |
98 |
|
|
99 |
8
|
Log.d(TAG, "Game first start"); |
100 |
8
|
makeDeck(); |
101 |
8
|
shuffle(); |
102 |
8
|
deal(); |
103 |
|
|
104 |
|
|
105 |
8
|
voidCheck(); |
106 |
|
|
107 |
|
|
108 |
|
|
109 |
8
|
checkForTwoMethod(); |
110 |
8
|
displayCards(game.p1); |
111 |
|
} |
112 |
|
|
113 |
|
else{ |
114 |
0
|
Log.d(TAG, "New round delt"); |
115 |
|
|
116 |
0
|
makeDeck(); |
117 |
0
|
shuffle(); |
118 |
0
|
deal(); |
119 |
|
|
120 |
0
|
voidCheck(); |
121 |
|
|
122 |
|
|
123 |
0
|
checkForTwoMethod(); |
124 |
0
|
displayCards(game.p1); |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
} |
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0,5 |
|
136 |
8
|
public void makeDeck() { ... |
137 |
8
|
Log.d(TAG, "make Deck"); |
138 |
8
|
game.deck.clearALL(); |
139 |
40
|
for(int suit=0;suit<4;suit++){ |
140 |
448
|
for(int value=1;value<14;value++){ |
141 |
416
|
Card cd = new Card(value, suit, context); |
142 |
416
|
game.deck.addCard(cd); |
143 |
|
} |
144 |
|
|
145 |
|
} |
146 |
|
|
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
|
|
| 95,5% |
Uncovered Elements: 5 (112) |
Complexity: 19 |
Complexity Density: 0,23 |
|
152 |
8
|
public void shuffle(){... |
153 |
8
|
Log.d(TAG, "shuffle"); |
154 |
8
|
if(game.shuffleType==1){ |
155 |
3
|
Log.d(TAG, "shuffle type 1"); |
156 |
|
|
157 |
|
|
158 |
3
|
int x = 0; |
159 |
3
|
int z = 50; |
160 |
3
|
int total =0; |
161 |
|
|
162 |
3
|
Deck deck2 = new Deck(); |
163 |
3
|
Deck deck3 = new Deck(); |
164 |
3
|
Deck deck4 = new Deck(); |
165 |
3
|
deck2.addAllCards(game.deck); |
166 |
3
|
int j=0; |
167 |
3
|
int a=(int) (Math.random()*7)+1; |
168 |
3
|
int dLength=0;; |
169 |
3
|
boolean stop = false; |
170 |
153
|
while(x<z&&!stop){ |
171 |
150
|
x++; |
172 |
150
|
dLength=deck2.getSize(); |
173 |
1776
|
while(dLength>0){ |
174 |
1626
|
if(dLength<=a){ |
175 |
122
|
Log.d(TAG, "STOP, too Small. "+dLength); |
176 |
122
|
deck3.addAllCards(deck2); |
177 |
122
|
deck2.clearALL(); |
178 |
122
|
a=-1; |
179 |
122
|
stop=true; |
180 |
|
|
181 |
|
} |
182 |
|
|
183 |
9073
|
while(a>=0){ |
184 |
7447
|
deck3.addCard(deck2.getCard(a)); |
185 |
7447
|
deck2.removeCardAtIndex(a); |
186 |
7447
|
a--; |
187 |
7447
|
j++; |
188 |
|
} |
189 |
|
|
190 |
1626
|
deck4.addAllCards(deck3); |
191 |
1626
|
deck3.clearALL(); |
192 |
|
|
193 |
1626
|
a=(int) (Math.random()*7)+1; |
194 |
1626
|
dLength=deck2.getSize(); |
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
} |
199 |
|
|
200 |
150
|
stop=false; |
201 |
150
|
deck2.addAllCards(deck4); |
202 |
150
|
deck4.clearALL(); |
203 |
150
|
Log.d(TAG, "x="+x+" z="+z); |
204 |
|
|
205 |
|
} |
206 |
3
|
Log.d(TAG, "j is "+j); |
207 |
3
|
game.deck.clearALL(); |
208 |
3
|
game.deck.addAllCards(deck2); |
209 |
|
} |
210 |
5
|
else if(game.shuffleType==2){ |
211 |
1
|
Log.d(TAG, "shuffle type 2"); |
212 |
1
|
int x=0; |
213 |
1
|
int z=50; |
214 |
1
|
int r = 51; |
215 |
1
|
boolean stop=false; |
216 |
1
|
Deck deck2 = new Deck(); |
217 |
|
|
218 |
51
|
while(x<z){ |
219 |
50
|
x++; |
220 |
50
|
int j=0; |
221 |
50
|
int a=(int) (Math.random()*r); |
222 |
51
|
for(int i=52; i>0&&!stop; i--){ |
223 |
1
|
int loop=0; |
224 |
17
|
while(game.deck.getCard(a)!=null&&!stop){ |
225 |
16
|
loop++; |
226 |
16
|
a=(int) (Math.random()*r); |
227 |
16
|
if(loop>15&&!stop){ |
228 |
1
|
r = 0; |
229 |
53
|
for(int q=0; q<game.deck.getSize();q++){ |
230 |
52
|
if(game.deck.getCard(q)!=null){ |
231 |
52
|
deck2.addCardAtIndex(q, game.deck.getCard(q)); |
232 |
52
|
r++; |
233 |
52
|
j++; |
234 |
|
} |
235 |
|
|
236 |
|
|
237 |
|
} |
238 |
1
|
stop=true; |
239 |
|
|
240 |
|
|
241 |
|
} |
242 |
|
} |
243 |
1
|
if(!stop){ |
244 |
0
|
deck2.addCardAtIndex(a, game.deck.getCard(a)); |
245 |
0
|
game.deck.addCardAtIndex(a, null); |
246 |
0
|
j++; |
247 |
|
} |
248 |
|
} |
249 |
|
|
250 |
50
|
game.deck=deck2; |
251 |
|
|
252 |
|
|
253 |
|
|
254 |
|
} |
255 |
|
} |
256 |
|
else{ |
257 |
|
|
258 |
4
|
Log.d(TAG, "shuffle type 3"); |
259 |
4
|
int x = 0; |
260 |
4
|
int z = 50; |
261 |
4
|
int total =0; |
262 |
4
|
ArrayList<Deck> decks= new ArrayList<Deck>(); |
263 |
4
|
Deck deck2 = new Deck(); |
264 |
4
|
deck2.addAllCards(game.deck); |
265 |
204
|
while(x<z){ |
266 |
200
|
decks.addAll(splitDeck(deck2)); |
267 |
200
|
Log.d(TAG, "the deck is "+decks.size()); |
268 |
200
|
deck2.clearALL(); |
269 |
200
|
deck2.addAllCards(mixOutIn(decks)); |
270 |
200
|
decks.clear(); |
271 |
200
|
x++; |
272 |
|
} |
273 |
|
|
274 |
|
|
275 |
|
|
276 |
|
|
277 |
|
|
278 |
|
} |
279 |
|
} |
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
@param |
284 |
|
@return |
285 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 4 |
Complexity Density: 0,29 |
|
286 |
200
|
private ArrayList<Deck> splitDeck(Deck a) {... |
287 |
200
|
ArrayList<Deck> decks = new ArrayList<Deck>(); |
288 |
2200
|
for(int i =0; i<10;i++){ |
289 |
2000
|
Deck deck2 = new Deck(); |
290 |
|
|
291 |
2000
|
int t=0; |
292 |
12000
|
while(t<5){ |
293 |
10000
|
deck2.addCard(a.getCard(t)); |
294 |
10000
|
t++; |
295 |
|
} |
296 |
2000
|
t--; |
297 |
12000
|
while(t>=0){ |
298 |
10000
|
a.removeCardAtIndex(t); |
299 |
10000
|
t--; |
300 |
|
} |
301 |
2000
|
decks.add(deck2); |
302 |
|
} |
303 |
200
|
decks.add(a); |
304 |
200
|
return decks; |
305 |
|
} |
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
@param |
310 |
|
@return |
311 |
|
|
312 |
|
|
313 |
|
|
|
|
| 92,9% |
Uncovered Elements: 1 (14) |
Complexity: 3 |
Complexity Density: 0,3 |
|
314 |
200
|
private Deck mixOutIn(ArrayList<Deck> a){... |
315 |
200
|
int size = a.size(); |
316 |
200
|
boolean extra=false; |
317 |
200
|
if(size%2==1){ |
318 |
200
|
size--; |
319 |
200
|
extra=true; |
320 |
|
} |
321 |
200
|
Deck d= new Deck(); |
322 |
1200
|
for(int i =0;i<size/2;i++){ |
323 |
1000
|
d.addAllCards(mixDecks(a.get(i), a.get(size-i-1))); |
324 |
|
} |
325 |
200
|
d.addAllCards(a.get(size/2)); |
326 |
|
|
327 |
200
|
return d; |
328 |
|
} |
329 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
330 |
1000
|
public Deck mixDecks(Deck a, Deck b){... |
331 |
6000
|
for(int i=0; i<a.getSize();i++){ |
332 |
5000
|
b.addCardAtIndex(i+i, a.getCard(i)); |
333 |
|
} |
334 |
1000
|
return b; |
335 |
|
} |
336 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
337 |
0
|
public ArrayList<Card> addLowHigh(ArrayList<Card> fromDeck){... |
338 |
0
|
ArrayList<Card> toDeck= new ArrayList<Card>(); |
339 |
0
|
for(int i=0;i<fromDeck.size();i++){ |
340 |
0
|
toDeck.add(fromDeck.get(i)); |
341 |
|
} |
342 |
0
|
return toDeck; |
343 |
|
} |
344 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
345 |
0
|
public ArrayList<Card> addHighLow(ArrayList<Card> fromDeck){... |
346 |
0
|
ArrayList<Card> toDeck= new ArrayList<Card>(); |
347 |
0
|
for(int i=fromDeck.size()-1;i>=0;i--){ |
348 |
0
|
toDeck.add(fromDeck.get(i)); |
349 |
|
} |
350 |
0
|
return toDeck; |
351 |
|
} |
352 |
|
|
353 |
|
|
354 |
|
|
355 |
|
|
356 |
|
|
357 |
|
|
|
|
| 80,6% |
Uncovered Elements: 6 (31) |
Complexity: 4 |
Complexity Density: 0,15 |
|
358 |
8
|
public void deal() {... |
359 |
8
|
Log.d(TAG, "dealing"); |
360 |
8
|
Deck hand1 = new Deck(); |
361 |
8
|
Deck hand2 = new Deck(); |
362 |
8
|
Deck hand3 = new Deck(); |
363 |
8
|
Deck hand4 = new Deck(); |
364 |
112
|
for(int i=0;i<game.deck.getSize();i+=4){ |
365 |
104
|
int d1=i; |
366 |
104
|
int d2=i+1; |
367 |
104
|
int d3=i+2; |
368 |
104
|
int d4=i+3; |
369 |
104
|
hand1.addCard(game.deck.getCard(d1)); |
370 |
104
|
hand2.addCard(game.deck.getCard(d2)); |
371 |
104
|
hand3.addCard(game.deck.getCard(d3)); |
372 |
104
|
hand4.addCard(game.deck.getCard(d4)); |
373 |
|
|
374 |
|
|
375 |
|
} |
376 |
8
|
if(game.p1==null||game.restart){ |
377 |
8
|
Log.d(TAG, "New hands dealt."); |
378 |
8
|
int b = Color.rgb(0, 50 , 200); |
379 |
8
|
game.p1 = new Player(game, hand1, 0, 1, game.name, Color.WHITE); |
380 |
8
|
game.p2 = new Player(game, hand2, 0, 2, "Chuck (P2)", Color.RED); |
381 |
8
|
game.p3 = new Player(game, hand3, 0, 3, "Skippy (P3)", b); |
382 |
8
|
game.p4 = new Player(game, hand4, 0, 4, "Jeff (P4)", Color.YELLOW); |
383 |
8
|
gameView.deckHolder.addDeck(hand1); |
384 |
|
|
385 |
|
} |
386 |
|
else { |
387 |
0
|
Log.d(TAG, "new round being delt"); |
388 |
0
|
game.p1.sethand(hand1); |
389 |
0
|
game.p2.sethand(hand2); |
390 |
0
|
game.p3.sethand(hand3); |
391 |
0
|
game.p4.sethand(hand4); |
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 |
|
|
|
|
| 75% |
Uncovered Elements: 11 (44) |
Complexity: 5 |
Complexity Density: 0,14 |
|
444 |
8
|
public void checkForTwoMethod(){... |
445 |
8
|
Log.d(TAG, "checkForTwoMethod() called"); |
446 |
8
|
if(game.p1.checkForTwo()){ |
447 |
0
|
Log.d(TAG, "p1 played the 2 of clubs"); |
448 |
0
|
game.curPlayer=game.p1; |
449 |
|
|
450 |
|
|
451 |
|
|
452 |
0
|
game.p1.setState(1); |
453 |
0
|
game.p2.setState(2); |
454 |
0
|
game.p3.setState(3); |
455 |
0
|
game.p4.setState(4); |
456 |
0
|
playTwoOfClubs(); |
457 |
0
|
gameView.displayCards(game.p1); |
458 |
|
|
459 |
|
|
460 |
|
} |
461 |
8
|
else if(game.p2.checkForTwo()){ |
462 |
6
|
Log.d(TAG, "p2 plays 2 of clubs"); |
463 |
6
|
game.curPlayer=game.p2; |
464 |
6
|
game.p1.setState(4); |
465 |
6
|
game.p2.setState(1); |
466 |
6
|
game.p3.setState(2); |
467 |
6
|
game.p4.setState(3); |
468 |
6
|
playTwoOfClubs(); |
469 |
|
} |
470 |
2
|
else if(game.p3.checkForTwo()){ |
471 |
1
|
Log.d(TAG, "p3 plays 2 of clubs"); |
472 |
1
|
game.curPlayer=game.p3; |
473 |
1
|
game.p1.setState(3); |
474 |
1
|
game.p2.setState(4); |
475 |
1
|
game.p3.setState(1); |
476 |
1
|
game.p4.setState(2); |
477 |
1
|
playTwoOfClubs(); |
478 |
|
} |
479 |
1
|
else if(game.p4.checkForTwo()){ |
480 |
1
|
Log.d(TAG, "p4 plays 2 of clubs"); |
481 |
1
|
game.curPlayer=game.p4; |
482 |
1
|
game.p1.setState(2); |
483 |
1
|
game.p2.setState(3); |
484 |
1
|
game.p3.setState(4); |
485 |
1
|
game.p4.setState(1); |
486 |
1
|
playTwoOfClubs(); |
487 |
|
} |
488 |
|
else{ |
489 |
0
|
Log.d(TAG, "The game has already started."); |
490 |
|
} |
491 |
8
|
Log.d(TAG, " 2 check done--curPlayer="+game.curPlayer.getRealName()); |
492 |
|
} |
493 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
494 |
8
|
public void voidCheck(){... |
495 |
8
|
game.p1.checkForVoids(); |
496 |
8
|
game.p2.checkForVoids(); |
497 |
8
|
game.p3.checkForVoids(); |
498 |
8
|
game.p4.checkForVoids(); |
499 |
|
} |
500 |
|
|
|
|
| 75,7% |
Uncovered Elements: 9 (37) |
Complexity: 9 |
Complexity Density: 0,31 |
|
501 |
8
|
public void displayCards(Player p){ ... |
502 |
8
|
Deck c = p.getClubs(); |
503 |
8
|
Deck d = p.getDiamonds(); |
504 |
8
|
Deck s = p.getSpades(); |
505 |
8
|
Deck h = p.getHearts(); |
506 |
8
|
String clubs = ""; |
507 |
8
|
String diamonds = ""; |
508 |
8
|
String spades = ""; |
509 |
8
|
String hearts = ""; |
510 |
36
|
for(int i=0; i<c.getSize();i++){ |
511 |
28
|
clubs+=c.getCard(i).getValue()+", "; |
512 |
|
} |
513 |
32
|
for(int i=0; i<d.getSize();i++){ |
514 |
24
|
diamonds+=d.getCard(i).getValue()+", "; |
515 |
|
} |
516 |
34
|
for(int i=0; i<s.getSize();i++){ |
517 |
26
|
spades+=s.getCard(i).getValue()+", "; |
518 |
|
} |
519 |
34
|
for(int i=0; i<h.getSize();i++){ |
520 |
26
|
hearts+=h.getCard(i).getValue()+", "; |
521 |
|
} |
522 |
|
|
523 |
8
|
switch(p.getSeat()){ |
524 |
8
|
case 1: |
525 |
8
|
gameView.p1tvScore.setText("P1:"+game.p1.getScore()); |
526 |
8
|
break; |
527 |
0
|
case 2: |
528 |
0
|
gameView.p2tvScore.setText("P2:"+game.p2.getScore()); |
529 |
0
|
break; |
530 |
|
|
531 |
0
|
case 3: |
532 |
0
|
gameView.p3tvScore.setText("P3:"+game.p3.getScore()); |
533 |
0
|
break; |
534 |
|
|
535 |
0
|
case 4: |
536 |
0
|
gameView.p4tvScore.setText("P4:"+game.p4.getScore()); |
537 |
0
|
break; |
538 |
|
|
539 |
|
} |
540 |
|
|
541 |
|
|
542 |
|
} |
543 |
|
|
544 |
|
|
545 |
|
|
546 |
|
|
547 |
|
@param |
548 |
|
@param |
549 |
|
|
550 |
|
|
551 |
|
|
552 |
|
|
553 |
|
|
554 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0,12 |
|
555 |
8
|
public void playTwoOfClubs(){... |
556 |
|
|
557 |
|
|
558 |
|
|
559 |
|
|
560 |
|
|
561 |
|
|
562 |
|
|
563 |
|
|
564 |
8
|
Card nextCard = game.curPlayer.twoOfClubs; |
565 |
8
|
game.curPlayer.deck.removeCard(nextCard); |
566 |
8
|
game.curPlayer.updateSuits(); |
567 |
8
|
Log.d(TAG, "game started by "+game.curPlayer.getRealName()); |
568 |
8
|
game.pile.add(nextCard); |
569 |
8
|
gameView.bottomText2.setText(game.curPlayer.getRealName()+" played the 2 of Clubs. "); |
570 |
8
|
playCard(nextCard); |
571 |
|
|
572 |
8
|
Log.d(TAG, "0101010"); |
573 |
|
} |
574 |
|
|
575 |
|
|
576 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0,33 |
|
577 |
0
|
public void showHand(Player p){... |
578 |
0
|
Deck hand = p.gethand(); |
579 |
0
|
String wholeHand=p.getRealName()+" "; |
580 |
0
|
for(int i=0;i<hand.getSize();i++){ |
581 |
0
|
wholeHand+=hand.getCard(i).name+", "; |
582 |
|
} |
583 |
0
|
Log.d(TAG, wholeHand); |
584 |
0
|
Log.d(TAG, "total="+hand.getSize()); |
585 |
|
} |
586 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0,12 |
|
587 |
31
|
public void GO(){... |
588 |
31
|
Log.d(TAG, "GO()"); |
589 |
31
|
gameView.roundView.setText("Round="+game.round); |
590 |
31
|
Card nextCard=(game.curPlayer.go(game.round, game.pile, game.curPlayer)); |
591 |
31
|
game.pile.add(nextCard); |
592 |
31
|
Log.d(TAG, "###"+game.curPlayer.realName+" played a "+nextCard.name+". Pile size="+game.pile.size() ); |
593 |
|
|
594 |
31
|
gameView.bottomText2.setText(game.curPlayer.getRealName()+" played the "+ nextCard.name); |
595 |
31
|
game.curPlayer.updateDeck(); |
596 |
|
|
597 |
31
|
playCard(nextCard); |
598 |
|
|
599 |
|
} |
600 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 3 |
Complexity Density: 0,33 |
|
601 |
49
|
public void playCard(Card nextCard){... |
602 |
49
|
if(justPickedUpPile){ |
603 |
8
|
gameView.clearTableCards(); |
604 |
8
|
this.justPickedUpPile=false; |
605 |
|
} |
606 |
49
|
this.gameView.addTableCard(nextCard); |
607 |
49
|
if(game.pile.size()>=4){ |
608 |
10
|
Log.d(TAG, "picking up hand"); |
609 |
10
|
pickUpHand(); |
610 |
|
} |
611 |
|
else{ |
612 |
39
|
this.game.curPlayer=nextPlayer(game.curPlayer); |
613 |
|
} |
614 |
49
|
gameView.bottomText.setText("Current player is "+game.curPlayer.getRealName()); |
615 |
|
|
616 |
|
} |
617 |
|
|
|
|
| 91,7% |
Uncovered Elements: 1 (12) |
Complexity: 5 |
Complexity Density: 0,42 |
|
618 |
39
|
public Player nextPlayer(Player p){... |
619 |
39
|
switch(p.getSeat()){ |
620 |
10
|
case 1: |
621 |
10
|
game.playing=false; |
622 |
10
|
return game.p2; |
623 |
12
|
case 2: |
624 |
12
|
return game.p3; |
625 |
9
|
case 3: |
626 |
9
|
return game.p4; |
627 |
8
|
case 4: |
628 |
8
|
game.playing=true; |
629 |
8
|
return game.p1; |
630 |
|
} |
631 |
0
|
return null; |
632 |
|
} |
633 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
634 |
10
|
public void setCurPlayer(Player p){... |
635 |
10
|
game.curPlayer = p; |
636 |
|
} |
637 |
|
|
|
|
| 60,7% |
Uncovered Elements: 42 (107) |
Complexity: 16 |
Complexity Density: 0,19 |
|
638 |
10
|
public void pickUpHand(){... |
639 |
10
|
game.roundHands.add(game.pile); |
640 |
10
|
this.justPickedUpPile=true; |
641 |
10
|
int high = 0; |
642 |
10
|
int highSeat = 0; |
643 |
10
|
int points = 0; |
644 |
10
|
int firstSuit=game.pile.get(0).getSuit(); |
645 |
50
|
for(int i=0;i<game.pile.size();i++){ |
646 |
40
|
game.pile.get(i).setPlayed(true); |
647 |
40
|
int curSuit=game.pile.get(i).getSuit(); |
648 |
40
|
int curCard =game.pile.get(i).getValue(); |
649 |
40
|
if(firstSuit==curSuit){ |
650 |
39
|
if(high<=curCard){ |
651 |
33
|
high=curCard; |
652 |
33
|
highSeat=game.pile.get(i).getOwner().getSeat(); |
653 |
|
} |
654 |
|
} |
655 |
40
|
if(curSuit==0){ |
656 |
39
|
game.clubsPlayedInt++; |
657 |
|
} |
658 |
|
|
659 |
1
|
else if(curSuit==1){ |
660 |
1
|
game.diamondsPlayedInt++; |
661 |
1
|
if(curCard==11){ |
662 |
1
|
points-=10; |
663 |
1
|
Toast.makeText(context, "Jack - 10", Toast.LENGTH_SHORT).show(); |
664 |
|
|
665 |
|
} |
666 |
|
} |
667 |
0
|
else if(curSuit==2){ |
668 |
0
|
game.spadesPlayedInt++; |
669 |
|
|
670 |
0
|
if(curCard==12){ |
671 |
0
|
game.heartsBroken=true; |
672 |
0
|
points+=13; |
673 |
0
|
Toast.makeText(context, "Queen + 13", Toast.LENGTH_SHORT).show(); |
674 |
|
|
675 |
|
} |
676 |
|
} |
677 |
0
|
else if(curSuit==3){ |
678 |
0
|
game.heartsPlayedInt++; |
679 |
0
|
game.heartsBroken=true; |
680 |
0
|
points++; |
681 |
|
} |
682 |
|
|
683 |
|
} |
684 |
10
|
gameView.clubsPlayed.setText("C="+game.clubsPlayedInt); |
685 |
10
|
gameView.diamondsPlayed.setText("D="+game.diamondsPlayedInt); |
686 |
10
|
gameView.spadesPlayed.setText("S="+game.spadesPlayedInt); |
687 |
10
|
gameView.heartsPlayed.setText("H="+game.heartsPlayedInt); |
688 |
10
|
int total=game.clubsPlayedInt+game.diamondsPlayedInt+game.spadesPlayedInt+game.heartsPlayedInt; |
689 |
10
|
gameView.totalPlayed.setText("total= "+total); |
690 |
10
|
switch(highSeat){ |
691 |
8
|
case 1: |
692 |
8
|
game.curPlayer=game.p1; |
693 |
8
|
game.p1.addToScore(points); |
694 |
8
|
gameView. p1tvScore.setText("P1:"+game.p1.getScore()); |
695 |
8
|
game.playing=true; |
696 |
8
|
gameView.bottomText2.setText("You won, points="+points); |
697 |
8
|
gameView.bottomText2.append(eol+"Pick a Start Card"); |
698 |
|
|
699 |
8
|
break; |
700 |
1
|
case 2: |
701 |
1
|
game.curPlayer=game.p2; |
702 |
1
|
game.p2.addToScore(points); |
703 |
1
|
gameView.p2tvScore.setText("P2:"+game.p2.getScore()); |
704 |
1
|
gameView.bottomText2.append(eol+"P2 won, points="+points); |
705 |
|
|
706 |
1
|
break; |
707 |
1
|
case 3: |
708 |
1
|
game.curPlayer=game.p3; |
709 |
1
|
game.p3.addToScore(points); |
710 |
1
|
gameView.p3tvScore.setText("P3:"+game.p3.getScore()); |
711 |
1
|
gameView.bottomText2.append(eol+"P3 won, points="+points); |
712 |
|
|
713 |
1
|
break; |
714 |
0
|
case 4: |
715 |
0
|
game.curPlayer=game.p4; |
716 |
0
|
game.p4.addToScore(points); |
717 |
0
|
gameView.p4tvScore.setText("P4:"+game.p4.getScore()); |
718 |
0
|
gameView.bottomText2.append(eol+"P4 won, taking="+points+" points"); |
719 |
0
|
break; |
720 |
|
} |
721 |
10
|
Log.d(TAG, "pickUpHand() for "+game.curPlayer.getRealName()); |
722 |
10
|
game.curPlayer.addDeckItem(game.pile); |
723 |
10
|
game.pile.clear(); |
724 |
10
|
setCurPlayer(game.curPlayer); |
725 |
|
|
726 |
|
|
727 |
10
|
game.round++; |
728 |
10
|
if(game.round==14){ |
729 |
0
|
game.count++; |
730 |
0
|
game.round=1; |
731 |
0
|
if(game.endGameCheck()){ |
732 |
0
|
game.curPlayer =game.winnerCheck(); |
733 |
0
|
gameView.bottomText.setText(game.curPlayer.getRealName()+" won the game!"); |
734 |
0
|
gameView.bottomText2.setText("Press menu, then restart to play again"); |
735 |
|
|
736 |
|
} |
737 |
|
else{ |
738 |
0
|
game.newRound=true; |
739 |
0
|
Log.d(TAG, "New round"); |
740 |
0
|
game.restart=false; |
741 |
0
|
game.clubsPlayedInt=0; |
742 |
0
|
game.diamondsPlayedInt=0; |
743 |
0
|
game.spadesPlayedInt=0; |
744 |
0
|
game.heartsPlayedInt=0; |
745 |
0
|
Toast.makeText(context, "New Round Dealt", Toast.LENGTH_LONG).show(); |
746 |
|
|
747 |
0
|
heartsMe(); |
748 |
|
} |
749 |
|
|
750 |
|
} |
751 |
|
|
752 |
|
|
753 |
|
} |
754 |
|
|
755 |
|
|
756 |
|
|
757 |
|
|
758 |
|
private long lastUpdate = System.currentTimeMillis(); |
759 |
|
private long timeElapsed = 1; |
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
760 |
236
|
private void pause(long ms) throws InterruptedException{... |
761 |
|
|
762 |
236
|
Thread.sleep(Math.max(0, ms - System.currentTimeMillis() + lastUpdate)); |
763 |
|
|
764 |
224
|
timeElapsed = System.currentTimeMillis() - lastUpdate; |
765 |
224
|
lastUpdate = System.currentTimeMillis(); |
766 |
|
} |
767 |
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 4 |
Complexity Density: 0,24 |
|
768 |
0
|
private void storeStats() {... |
769 |
0
|
frameCountPerStatCycle++; |
770 |
0
|
totalFrameCount++; |
771 |
0
|
statusIntervalTimer += FRAME_PERIOD; |
772 |
|
|
773 |
0
|
if(statusIntervalTimer >= STAT_INTERVAL){ |
774 |
0
|
double actualFps = (double)(frameCountPerStatCycle / (STAT_INTERVAL / 1000)); |
775 |
0
|
fpsStore[(int)statsCount % FPS_HISTORY_NR] = actualFps; |
776 |
0
|
statsCount++; |
777 |
0
|
double totalFps = 0.0; |
778 |
|
|
779 |
0
|
for(int i =0; i < FPS_HISTORY_NR; i++) { |
780 |
0
|
totalFps += fpsStore[i]; |
781 |
|
} |
782 |
|
|
783 |
0
|
if(statsCount < FPS_HISTORY_NR){ |
784 |
0
|
averageFps = totalFps / statsCount; |
785 |
|
}else { |
786 |
0
|
averageFps = totalFps / FPS_HISTORY_NR; |
787 |
|
} |
788 |
|
|
789 |
0
|
totalFramesSkipped += framesSkippedPerStatCycle; |
790 |
0
|
framesSkippedPerStatCycle = 0; |
791 |
0
|
statusIntervalTimer = 0; |
792 |
0
|
frameCountPerStatCycle = 0; |
793 |
|
|
794 |
|
|
795 |
|
} |
796 |
|
} |
797 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
798 |
0
|
private void initTimingElements(){... |
799 |
0
|
fpsStore = new double[FPS_HISTORY_NR]; |
800 |
0
|
for(int i = 0; i < FPS_HISTORY_NR; i++){ |
801 |
0
|
fpsStore[i] = 0.0; |
802 |
|
} |
803 |
0
|
Log.d(TAG + ".initTimingElements()","Timing elements for stats intialized"); |
804 |
|
} |
805 |
|
|
806 |
|
|
807 |
|
} |