1 |
|
package game.shad.tempus.hearts; |
2 |
|
|
3 |
|
import android.content.Context; |
4 |
|
import android.graphics.Canvas; |
5 |
|
import android.graphics.Paint; |
6 |
|
import android.graphics.RectF; |
7 |
|
import android.util.Log; |
8 |
|
import android.view.GestureDetector; |
9 |
|
import android.view.MotionEvent; |
10 |
|
import android.view.SurfaceHolder; |
11 |
|
import android.view.SurfaceHolder.Callback; |
12 |
|
import android.view.SurfaceView; |
13 |
|
import android.view.View; |
14 |
|
import android.view.View.OnTouchListener; |
15 |
|
import android.widget.LinearLayout; |
16 |
|
import android.widget.TextView; |
17 |
|
import android.widget.Toast; |
18 |
|
|
19 |
|
|
|
|
| 58,9% |
Uncovered Elements: 58 (141) |
Complexity: 28 |
Complexity Density: 0,27 |
|
20 |
|
public class GameView implements Callback, OnTouchListener{ |
21 |
|
public static final String TAG = "Hearts--GameView"; |
22 |
|
public String eol = System.getProperty("line.separator"); |
23 |
|
|
24 |
|
Context context; |
25 |
|
private MainActivity main; |
26 |
|
public Game game; |
27 |
|
private boolean initialized = false; |
28 |
|
private boolean userUpdate = false; |
29 |
|
private Canvas canvas; |
30 |
|
Canvas deckHolderCanvas = null; |
31 |
|
Canvas tableHolderCanvas = null; |
32 |
|
private GestureDetector gestures; |
33 |
|
private int screenWidth; |
34 |
|
private int screenHeight; |
35 |
|
LinearLayout bottomLayout; |
36 |
|
LinearLayout deckHolderLayout; |
37 |
|
LinearLayout tableHolderLayout; |
38 |
|
public SurfaceView deckHolderSV; |
39 |
|
public SurfaceView tableHolderSV; |
40 |
|
|
41 |
|
public DeckHolder deckHolder; |
42 |
|
public TableHolder tableHolder; |
43 |
|
|
44 |
|
LinearLayout.LayoutParams tableHolderlayoutParams; |
45 |
|
LinearLayout.LayoutParams deckHolderlayoutParams; |
46 |
|
public TextView clubsPlayed; |
47 |
|
public TextView diamondsPlayed; |
48 |
|
public TextView spadesPlayed; |
49 |
|
public TextView heartsPlayed; |
50 |
|
public TextView roundView; |
51 |
|
TextView totalPlayed; |
52 |
|
|
53 |
|
public TextView p1tvScore; |
54 |
|
public TextView p2tvScore; |
55 |
|
public TextView p3tvScore; |
56 |
|
public TextView p4tvScore; |
57 |
|
|
58 |
|
public TextView bottomText; |
59 |
|
public TextView bottomText2; |
60 |
|
public RectF rect = new RectF(); |
61 |
|
public Paint paint = new Paint(); |
62 |
|
|
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0,14 |
|
64 |
8
|
public GameView(Context context, MainActivity main, Game game, int width, int height) {... |
65 |
8
|
this.context = context; |
66 |
8
|
this.main = main; |
67 |
8
|
this.game = game; |
68 |
|
|
69 |
8
|
screenWidth = width; |
70 |
8
|
screenHeight = height; |
71 |
8
|
canvas = new Canvas(); |
72 |
8
|
firstStart(); |
73 |
|
|
74 |
|
} |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0,07 |
|
83 |
8
|
public void firstStart() {... |
84 |
8
|
Log.d(TAG, "firstStart()"); |
85 |
|
|
86 |
8
|
p1tvScore = (TextView) main.findViewById(R.id.p1tvScore); |
87 |
8
|
p2tvScore = (TextView) main.findViewById(R.id.p2tvScore); |
88 |
8
|
p3tvScore = (TextView) main.findViewById(R.id.p3tvScore); |
89 |
8
|
p4tvScore = (TextView) main.findViewById(R.id.p4tvScore); |
90 |
|
|
91 |
8
|
roundView = (TextView) main.findViewById(R.id.roundView); |
92 |
8
|
bottomText = (TextView) main.findViewById(R.id.bottomTV); |
93 |
8
|
bottomText2 = (TextView) main.findViewById(R.id.bottomTV2); |
94 |
|
|
95 |
8
|
clubsPlayed = (TextView) main.findViewById(R.id.clubsPlayed); |
96 |
8
|
diamondsPlayed = (TextView) main.findViewById(R.id.diamondsPlayed); |
97 |
8
|
spadesPlayed = (TextView) main.findViewById(R.id.spadesPlayed); |
98 |
8
|
heartsPlayed = (TextView) main.findViewById(R.id.heartsPlayed); |
99 |
8
|
totalPlayed = (TextView) main.findViewById(R.id.totalPlayed); |
100 |
8
|
deckHolderLayout = (LinearLayout) main.findViewById(R.id.DeckHolderLayout); |
101 |
8
|
tableHolderLayout = (LinearLayout) main.findViewById(R.id.TableHolderLayout); |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
} |
107 |
|
|
108 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0,1 |
|
109 |
8
|
public void createViews(){... |
110 |
8
|
Log.d(TAG, "CreateViews"); |
111 |
|
|
112 |
8
|
deckHolder = new DeckHolder(context, this, screenWidth, screenHeight/8); |
113 |
8
|
deckHolderlayoutParams = new LinearLayout.LayoutParams(screenWidth, screenHeight/8); |
114 |
|
|
115 |
8
|
tableHolder = new TableHolder(context, this, (int) (screenWidth*.6), screenHeight/8); |
116 |
8
|
tableHolderlayoutParams = new LinearLayout.LayoutParams((int) (screenWidth*.7), screenHeight/8); |
117 |
|
|
118 |
8
|
deckHolder.setLayoutParams(deckHolderlayoutParams); |
119 |
8
|
tableHolder.setLayoutParams(tableHolderlayoutParams); |
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
8
|
main.gameView.deckHolderLayout.addView(this.deckHolder); |
125 |
8
|
main.gameView.tableHolderLayout.addView(this.tableHolder); |
126 |
|
|
127 |
8
|
this.initialized=true; |
128 |
|
} |
129 |
|
|
130 |
|
|
131 |
|
|
|
|
| 66,7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
132 |
224
|
public synchronized void update() {... |
133 |
224
|
if(this.initialized){ |
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
224
|
updateDH(); |
139 |
224
|
updateTH(); |
140 |
|
} |
141 |
|
else{ |
142 |
0
|
Log.d(TAG, "not Initialized"); |
143 |
|
} |
144 |
|
} |
145 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0,4 |
|
146 |
224
|
public synchronized void updateDH(){... |
147 |
224
|
if (!deckHolder.initialized){ |
148 |
8
|
Log.d(TAG, "DeckHolder not initialized"); |
149 |
|
} |
150 |
|
else{ |
151 |
216
|
deckHolderCanvas = deckHolder.getHolder().lockCanvas(); |
152 |
216
|
deckHolder.onDraw(deckHolderCanvas); |
153 |
216
|
deckHolder.getHolder().unlockCanvasAndPost(deckHolderCanvas); |
154 |
|
|
155 |
|
} |
156 |
|
} |
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0,4 |
|
157 |
224
|
public synchronized void updateTH(){... |
158 |
224
|
if (!tableHolder.initialized){ |
159 |
8
|
Log.d(TAG, "TableHolder not initialized"); |
160 |
|
} |
161 |
|
else{ |
162 |
216
|
tableHolderCanvas = tableHolder.getHolder().lockCanvas(); |
163 |
216
|
tableHolder.onDraw(tableHolderCanvas); |
164 |
216
|
tableHolder.getHolder().unlockCanvasAndPost(tableHolderCanvas); |
165 |
|
} |
166 |
|
} |
167 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 1 |
Complexity Density: 0,07 |
|
168 |
0
|
public void UserUpdate(){... |
169 |
0
|
displayCards(game.p1); |
170 |
0
|
p1tvScore.invalidate(); |
171 |
0
|
p2tvScore.invalidate(); |
172 |
0
|
p3tvScore.invalidate(); |
173 |
0
|
p4tvScore.invalidate(); |
174 |
|
|
175 |
0
|
roundView.invalidate(); |
176 |
0
|
bottomText.invalidate(); |
177 |
0
|
bottomText2.invalidate(); |
178 |
|
|
179 |
0
|
clubsPlayed.invalidate(); |
180 |
0
|
diamondsPlayed.invalidate(); |
181 |
0
|
spadesPlayed.invalidate(); |
182 |
0
|
heartsPlayed.invalidate(); |
183 |
0
|
totalPlayed.invalidate(); |
184 |
0
|
userUpdate=false; |
185 |
|
} |
186 |
|
|
187 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 5 |
Complexity Density: 0,31 |
|
188 |
0
|
public void displayCards(Player p){ ... |
189 |
0
|
Deck c = p.getClubs(); |
190 |
0
|
Deck d = p.getDiamonds(); |
191 |
0
|
Deck s = p.getSpades(); |
192 |
0
|
Deck h = p.getHearts(); |
193 |
0
|
String clubs = ""; |
194 |
0
|
String diamonds = ""; |
195 |
0
|
String spades = ""; |
196 |
0
|
String hearts = ""; |
197 |
0
|
for(int i=0; i<c.getSize();i++){ |
198 |
0
|
clubs+=c.getCard(i).getValue()+", "; |
199 |
|
} |
200 |
0
|
for(int i=0; i<d.getSize();i++){ |
201 |
0
|
diamonds+=d.getCard(i).getValue()+", "; |
202 |
|
} |
203 |
0
|
for(int i=0; i<s.getSize();i++){ |
204 |
0
|
spades+=s.getCard(i).getValue()+", "; |
205 |
|
} |
206 |
0
|
for(int i=0; i<h.getSize();i++){ |
207 |
0
|
hearts+=h.getCard(i).getValue()+", "; |
208 |
|
} |
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
} |
214 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
215 |
0
|
@Override... |
216 |
|
public boolean onTouch(View v, MotionEvent event) { |
217 |
0
|
Log.d(TAG, "Touching at x="+event.getX()+", y="+event.getY()); |
218 |
|
|
219 |
0
|
return false; |
220 |
|
} |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
221 |
0
|
@Override... |
222 |
|
public void surfaceChanged(SurfaceHolder holder, int format, int width, |
223 |
|
int height) { |
224 |
|
|
225 |
|
|
226 |
|
} |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
227 |
0
|
@Override... |
228 |
|
public void surfaceCreated(SurfaceHolder holder) { |
229 |
0
|
Log.d(TAG, "surface Created"); |
230 |
0
|
initialized = true; |
231 |
|
|
232 |
|
|
233 |
|
} |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
234 |
0
|
@Override... |
235 |
|
public void surfaceDestroyed(SurfaceHolder holder) { |
236 |
0
|
Log.d(TAG, "surface Created"); |
237 |
0
|
initialized = false; |
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
} |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
242 |
24
|
public void setInitializedTo(boolean b) {... |
243 |
24
|
Log.d(TAG, "Set Initialized to "+b); |
244 |
24
|
initialized = b; |
245 |
|
} |
246 |
|
|
247 |
|
|
248 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
249 |
8
|
public void clearTableCards(){... |
250 |
|
|
251 |
8
|
tableHolder.removeAll(); |
252 |
8
|
tableHolder.addBlankCards(); |
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
|
|
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
} |
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
|
269 |
|
|
270 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
271 |
0
|
public DeckHolder getDeckHolder() {... |
272 |
0
|
return deckHolder; |
273 |
|
} |
274 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
275 |
0
|
public TableHolder getTableHolder() {... |
276 |
0
|
return tableHolder; |
277 |
|
} |
278 |
|
|
|
|
| 90% |
Uncovered Elements: 2 (20) |
Complexity: 4 |
Complexity Density: 0,29 |
|
279 |
20
|
public void deckViewTouched(int x, int y) {... |
280 |
20
|
for(Card c :deckHolder.getDeck().getDeck()){ |
281 |
68
|
if(c.getBounds().contains(x, y)){ |
282 |
20
|
if(game.trading){ |
283 |
|
|
284 |
|
} |
285 |
|
else{ |
286 |
20
|
if(game.cardToPlay==null){ |
287 |
10
|
game.cardToPlay=c; |
288 |
10
|
game.cardToPlay.setTouched(true); |
289 |
10
|
Toast.makeText(context, "You picked the "+c.cardToString(), Toast.LENGTH_SHORT).show(); |
290 |
10
|
break; |
291 |
|
} |
292 |
|
else{ |
293 |
10
|
game.cardToPlay.setTouched(false); |
294 |
10
|
game.cardToPlay=c; |
295 |
10
|
game.cardToPlay.setTouched(true); |
296 |
10
|
Toast.makeText(context, "You picked the "+c.cardToString(), Toast.LENGTH_SHORT).show(); |
297 |
10
|
break; |
298 |
|
} |
299 |
|
} |
300 |
0
|
updateDH(); |
301 |
|
|
302 |
|
} |
303 |
|
|
304 |
|
} |
305 |
|
} |
306 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
307 |
49
|
public void addTableCard(Card r) {... |
308 |
49
|
tableHolder.addCard(r); |
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 |
|
} |