1 |
|
package game.shad.tempus.hearts; |
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
import game.shad.tempus.hearts.GameThread.State; |
7 |
|
import android.app.Activity; |
8 |
|
import android.content.Context; |
9 |
|
import android.content.Intent; |
10 |
|
import android.os.AsyncTask; |
11 |
|
import android.os.Bundle; |
12 |
|
import android.os.Handler; |
13 |
|
import android.os.Looper; |
14 |
|
import android.os.PowerManager.WakeLock; |
15 |
|
import android.util.Log; |
16 |
|
import android.view.View; |
17 |
|
import android.widget.Toast; |
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
@author |
23 |
|
|
24 |
|
|
|
|
| 82,5% |
Uncovered Elements: 20 (114) |
Complexity: 25 |
Complexity Density: 0,3 |
|
25 |
|
public class MainActivity extends Activity { |
26 |
|
|
27 |
|
public static final String TAG = "Hearts--Main"; |
28 |
|
|
29 |
|
public Game game; |
30 |
|
public GameView gameView; |
31 |
|
public GameThread gt; |
32 |
|
public GameView view; |
33 |
|
private Toast myToast; |
34 |
|
|
35 |
|
public Handler handler; |
36 |
|
private WakeLock mWakeLock; |
37 |
|
private boolean loaded =false; |
38 |
|
private Bundle gameBundle; |
39 |
|
private Context appContext; |
40 |
|
private MainActivity main; |
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0,05 |
|
41 |
8
|
@Override... |
42 |
|
|
43 |
|
public void onCreate(Bundle savedInstanceState) { |
44 |
8
|
super.onCreate(savedInstanceState); |
45 |
8
|
Intent gameIntent = getIntent(); |
46 |
8
|
gameBundle = gameIntent.getExtras(); |
47 |
8
|
Log.d(TAG, "onCreate"); |
48 |
8
|
setContentView(R.layout.table); |
49 |
8
|
appContext = getApplicationContext(); |
50 |
8
|
main= this; |
51 |
8
|
game = new Game(gameBundle, getApplicationContext()); |
52 |
8
|
gameView = new GameView(appContext, main, game, gameBundle.getInt("width"), gameBundle.getInt("height")); |
53 |
8
|
gt = new GameThread(appContext, main, game, gameView); |
54 |
8
|
myToast = Toast.makeText(getBaseContext(), "", Toast.LENGTH_SHORT); |
55 |
8
|
gameView.createViews(); |
56 |
8
|
Log.d(TAG, "created Views"); |
57 |
8
|
gt.firstInit(); |
58 |
8
|
gameView.clubsPlayed.setText("C="+game.clubsPlayedInt); |
59 |
8
|
gameView.diamondsPlayed.setText("D="+game.diamondsPlayedInt); |
60 |
8
|
gameView.spadesPlayed.setText("A="+game.spadesPlayedInt); |
61 |
8
|
gameView.heartsPlayed.setText("H="+game.heartsPlayedInt); |
62 |
8
|
int total=game.clubsPlayedInt+game.diamondsPlayedInt+game.spadesPlayedInt+game.heartsPlayedInt; |
63 |
8
|
gameView.totalPlayed.setText("total= "+total); |
64 |
|
|
65 |
|
} |
66 |
|
|
|
|
| 75% |
Uncovered Elements: 3 (12) |
Complexity: 3 |
Complexity Density: 0,38 |
|
67 |
8
|
@Override... |
68 |
|
protected void onStart(){ |
69 |
8
|
super.onStart(); |
70 |
8
|
Log.d(TAG, "onStart"); |
71 |
8
|
handler= new Handler(); |
72 |
8
|
if(gt==null){ |
73 |
0
|
return; |
74 |
|
} |
75 |
8
|
if(gt.state.compareAndSet(State.PAUSED, State.RUNNING)){ |
76 |
8
|
Log.d(TAG, "Restarting game thread in start"); |
77 |
8
|
gt.interrupt(); |
78 |
|
} |
79 |
|
|
80 |
|
|
81 |
|
} |
82 |
|
|
|
|
| 83,3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
83 |
8
|
@Override... |
84 |
|
protected void onPause() { |
85 |
8
|
Log.d(TAG, "onPause"); |
86 |
|
|
87 |
8
|
super.onPause(); |
88 |
8
|
if(gt.state.compareAndSet(State.RUNNING, State.PAUSED)) { |
89 |
8
|
gt.interrupt(); |
90 |
|
} |
91 |
|
|
92 |
|
} |
93 |
|
|
|
|
| 66,7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
94 |
8
|
@Override... |
95 |
|
protected void onResume() { |
96 |
8
|
Log.d(TAG, "onResume"); |
97 |
8
|
super.onResume(); |
98 |
|
|
99 |
8
|
if(gt.state.compareAndSet(State.PAUSED, State.RUNNING)) { |
100 |
0
|
gt.interrupt(); |
101 |
|
|
102 |
|
} |
103 |
|
|
104 |
|
|
105 |
|
} |
106 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
107 |
8
|
@Override... |
108 |
|
public void onStop() { |
109 |
8
|
Log.d(TAG, "onStop"); |
110 |
8
|
super.onStop(); |
111 |
|
} |
112 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
113 |
8
|
@Override... |
114 |
|
protected void onDestroy() { |
115 |
|
|
116 |
8
|
Log.d(TAG, "onDestroy"); |
117 |
|
|
118 |
8
|
super.onDestroy(); |
119 |
8
|
gt.state.set(State.DEAD); |
120 |
8
|
gt.interrupt(); |
121 |
|
} |
122 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
123 |
0
|
@Override... |
124 |
|
public void onRestart(){ |
125 |
0
|
super.onRestart(); |
126 |
0
|
Log.d(TAG, "onRestart"); |
127 |
0
|
Log.d(TAG, "gt.state="+gt.state); |
128 |
|
} |
129 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0,1 |
|
130 |
24
|
public void onDebugButtonPressed(View v){... |
131 |
24
|
gameView.setInitializedTo(true); |
132 |
24
|
game.showHand(game.p1); |
133 |
24
|
game.showHand(game.p2); |
134 |
24
|
game.showHand(game.p3); |
135 |
24
|
game.showHand(game.p4); |
136 |
24
|
Toast.makeText(this, "Printed Hands", Toast.LENGTH_SHORT).show(); |
137 |
24
|
game.p1.updateDeck(); |
138 |
24
|
gameView.deckHolder.updateDeck(game.p1.getDeck()); |
139 |
24
|
gameView.deckHolder.initialized=true; |
140 |
24
|
game.playing=!game.playing; |
141 |
|
|
142 |
|
|
143 |
|
} |
|
|
| 72,7% |
Uncovered Elements: 3 (11) |
Complexity: 4 |
Complexity Density: 0,57 |
|
144 |
32
|
public void onNextButtonPressed(View v){... |
145 |
32
|
if(game.playing){ |
146 |
|
|
147 |
1
|
if(game.playerHelper&&game.playerHelperInt>0){ |
148 |
0
|
game.playerHelperInt=0; |
149 |
0
|
gt.GO(); |
150 |
|
|
151 |
|
} |
152 |
|
else{ |
153 |
1
|
game.playerHelperInt++; |
154 |
1
|
Toast.makeText(this, "Please play card", Toast.LENGTH_SHORT).show(); |
155 |
|
} |
156 |
|
} |
157 |
|
else{ |
158 |
31
|
gt.GO(); |
159 |
|
} |
160 |
|
|
161 |
|
} |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
162 |
0
|
public void onTablePressed(View v){... |
163 |
0
|
Log.d(TAG, "onClearPressed"); |
164 |
0
|
gameView.updateTH(); |
165 |
|
|
166 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
167 |
0
|
public void onDeckPressed(View v){... |
168 |
0
|
gameView.updateDH(); |
169 |
|
|
170 |
|
} |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
171 |
8
|
public void onExitPressed(View v){... |
172 |
8
|
finish(); |
173 |
|
} |
174 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
175 |
23
|
public void onSwipeLeftPressed(View v){... |
176 |
23
|
gameView.deckHolder.swipeLeft(); |
177 |
23
|
Toast.makeText(this, "position is "+gameView.deckHolder.getPosition(), Toast.LENGTH_SHORT).show(); |
178 |
|
|
179 |
|
} |
180 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
181 |
32
|
public void onSwipeRightPressed(View v){... |
182 |
32
|
gameView.deckHolder.swipeRight(); |
183 |
32
|
Toast.makeText(this, "position is "+gameView.deckHolder.getPosition(), Toast.LENGTH_SHORT).show(); |
184 |
|
|
185 |
|
|
186 |
|
} |
187 |
|
|
188 |
|
|
|
|
| 88,2% |
Uncovered Elements: 2 (17) |
Complexity: 4 |
Complexity Density: 0,31 |
|
189 |
32
|
public void onPlayCardPressed(View v){... |
190 |
32
|
if(game.cardToPlay!=null&&game.playing){ |
191 |
10
|
if(game.pile.size()==0){ |
192 |
0
|
gameView.clearTableCards(); |
193 |
|
} |
194 |
10
|
game.cardToPlay.setTouched(false); |
195 |
10
|
game.pile.add(game.cardToPlay); |
196 |
10
|
game.playing=false; |
197 |
10
|
this.game.p1.deck.removeCard(game.cardToPlay); |
198 |
10
|
gt.playCard(game.cardToPlay); |
199 |
10
|
game.cardToPlay=null; |
200 |
|
} |
201 |
|
else{ |
202 |
22
|
Toast.makeText(this, "Not your turn", Toast.LENGTH_SHORT).show(); |
203 |
|
} |
204 |
32
|
game.playing=false; |
205 |
32
|
game.p1.updateSuits(); |
206 |
32
|
gameView.deckHolder.updateDeck(game.p1.getDeck()); |
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
} |
211 |
|
} |
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|