1 |
|
package game.shad.tempus.hearts; |
2 |
|
|
3 |
|
import java.util.ArrayList; |
4 |
|
|
5 |
|
import android.app.Activity; |
6 |
|
import android.content.Context; |
7 |
|
import android.content.Intent; |
8 |
|
import android.gesture.Gesture; |
9 |
|
import android.graphics.Canvas; |
10 |
|
import android.graphics.Color; |
11 |
|
import android.graphics.Paint; |
12 |
|
import android.graphics.Rect; |
13 |
|
import android.graphics.drawable.Drawable; |
14 |
|
import android.os.Bundle; |
15 |
|
import android.util.Log; |
16 |
|
import android.view.Display; |
17 |
|
import android.view.GestureDetector; |
18 |
|
import android.view.GestureDetector.OnGestureListener; |
19 |
|
import android.view.Menu; |
20 |
|
import android.view.MenuInflater; |
21 |
|
import android.view.MenuItem; |
22 |
|
import android.view.MotionEvent; |
23 |
|
import android.view.SurfaceView; |
24 |
|
import android.view.View; |
25 |
|
import android.view.Window; |
26 |
|
import android.view.WindowManager; |
27 |
|
import android.view.inputmethod.InputMethodManager; |
28 |
|
import android.widget.Button; |
29 |
|
import android.widget.EditText; |
30 |
|
import android.widget.LinearLayout; |
31 |
|
import android.widget.TableRow; |
32 |
|
import android.widget.TextView; |
33 |
|
import android.widget.Toast; |
34 |
|
import android.widget.LinearLayout.LayoutParams; |
35 |
|
|
36 |
|
|
|
|
| 18,2% |
Uncovered Elements: 108 (132) |
Complexity: 27 |
Complexity Density: 0,28 |
|
37 |
|
public class Game extends Activity{ |
38 |
|
public static final String TAG = "Hearts--Game"; |
39 |
|
private Context context; |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
public String eol = System.getProperty("line.separator"); |
48 |
|
public String name; |
49 |
|
public Deck deck=new Deck(); |
50 |
|
public int[] cardArrayRes= new int[52]; |
51 |
|
public Card[] deckCards=new Card[4]; |
52 |
|
public ArrayList<Card> pile=new ArrayList<Card>(); |
53 |
|
public Deck blankCards=new Deck(); |
54 |
|
|
55 |
|
public ArrayList<ArrayList<Card>> roundHands= new ArrayList<ArrayList<Card>>(); |
56 |
|
|
57 |
|
public Player p1; |
58 |
|
public Player p2; |
59 |
|
public Player p3; |
60 |
|
public Player p4; |
61 |
|
public Player curPlayer; |
62 |
|
public Card cardToPlay; |
63 |
|
public Bundle gameIntent; |
64 |
|
public Canvas canvas = new Canvas(); |
65 |
|
public Paint paint = new Paint(); |
66 |
|
|
67 |
|
public int selectedCard=0; |
68 |
|
public int selectedCardSuit=-1; |
69 |
|
|
70 |
|
int clubsPlayedInt=0; |
71 |
|
int diamondsPlayedInt=0; |
72 |
|
int spadesPlayedInt=0; |
73 |
|
int heartsPlayedInt=0; |
74 |
|
|
75 |
|
|
76 |
|
public EditText et1; |
77 |
|
|
78 |
|
public boolean debug = false; |
79 |
|
public boolean playing = false; |
80 |
|
public boolean heartsBroken; |
81 |
|
public boolean restart = false; |
82 |
|
public boolean voidHelper; |
83 |
|
public boolean playerHelper; |
84 |
|
public boolean newRound=false; |
85 |
|
public boolean trading =false; |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
public int round=1; |
90 |
|
public int count=0; |
91 |
|
public int players=4; |
92 |
|
public int difficulty=1; |
93 |
|
int size; |
94 |
|
|
95 |
|
public int shuffleType; |
96 |
|
int playerHelperInt=0; |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
|
|
| 87,5% |
Uncovered Elements: 2 (16) |
Complexity: 3 |
Complexity Density: 0,21 |
|
101 |
8
|
public Game(Bundle gameIntent2, Context context) {... |
102 |
8
|
Bundle b = gameIntent2; |
103 |
8
|
this.context = context; |
104 |
8
|
this.name=(String) b.get("name").toString().trim(); |
105 |
8
|
this.voidHelper = (Boolean) b.get("voidHelper"); |
106 |
8
|
this.playerHelper = (Boolean) b.get("playerHelper"); |
107 |
8
|
Log.d(TAG, "player helper is "+playerHelper); |
108 |
8
|
Log.d(TAG, this.name); |
109 |
8
|
if (this.name.equalsIgnoreCase("Your name")||this.name.equals("")){ |
110 |
0
|
this.name = "You"; |
111 |
|
} |
112 |
8
|
this.difficulty = (Integer) b.get("diff"); |
113 |
8
|
this.shuffleType = (Integer) b.get("shuffle"); |
114 |
8
|
Log.d(TAG, "shuffle type= "+shuffleType); |
115 |
|
|
116 |
8
|
Log.d(TAG, "difficulty= "+difficulty); |
117 |
|
|
118 |
8
|
this.restart = (Boolean) b.get("restart"); |
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0,12 |
|
126 |
0
|
public void clearALL(){... |
127 |
|
|
128 |
|
|
129 |
0
|
p1 = null; |
130 |
0
|
p2 = null; |
131 |
0
|
p3 = null; |
132 |
0
|
p4 = null; |
133 |
0
|
playing = false; |
134 |
0
|
heartsBroken=false; |
135 |
0
|
round=1; |
136 |
0
|
count=0; |
137 |
|
|
138 |
|
} |
139 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0,33 |
|
140 |
0
|
public void createBlankHand(){ ... |
141 |
0
|
Deck deck = new Deck(); |
142 |
0
|
for(int value=0;value<7;value++){ |
143 |
0
|
Card cd = new Card(0, 0, context); |
144 |
0
|
deck.addCard(cd); |
145 |
|
} |
146 |
0
|
for(int value=0;value<6;value++){ |
147 |
0
|
Card cd = new Card(3, 0, context); |
148 |
0
|
deck.addCard(cd); |
149 |
|
} |
150 |
0
|
blankCards.clearALL(); |
151 |
0
|
blankCards.addAllCards(deck); |
152 |
|
} |
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
|
|
| 0% |
Uncovered Elements: 48 (48) |
Complexity: 8 |
Complexity Density: 0,24 |
|
157 |
0
|
public Player winnerCheck(){... |
158 |
0
|
int scorep1 = p1.getScore(); |
159 |
0
|
int scorep2 = p2.getScore(); |
160 |
0
|
int scorep3 = p3.getScore(); |
161 |
0
|
int scorep4 = p4.getScore(); |
162 |
|
|
163 |
0
|
if(scorep1<=scorep2){ |
164 |
0
|
if(scorep1<=scorep3){ |
165 |
0
|
if(scorep1<=scorep4){ |
166 |
0
|
Log.d(TAG, "YOU WON"); |
167 |
0
|
p1.winner=true; |
168 |
0
|
return p1; |
169 |
|
} |
170 |
|
else{ |
171 |
0
|
Log.d(TAG, "P4 WON"); |
172 |
0
|
p4.winner=true; |
173 |
0
|
return p4; |
174 |
|
} |
175 |
|
} |
176 |
0
|
else if(scorep3<=scorep4){ |
177 |
0
|
Log.d(TAG, "P3 WON"); |
178 |
0
|
p3.winner=true; |
179 |
0
|
return p3; |
180 |
|
} |
181 |
|
|
182 |
|
} |
183 |
0
|
else if(scorep2<=scorep3){ |
184 |
0
|
if(scorep2<=scorep4){ |
185 |
0
|
Log.d(TAG, "P2 WON"); |
186 |
0
|
p2.winner=true; |
187 |
0
|
return p2; |
188 |
|
} |
189 |
|
else{ |
190 |
0
|
Log.d(TAG, "P4 WON"); |
191 |
0
|
p4.winner=true; |
192 |
0
|
return p4; |
193 |
|
|
194 |
|
} |
195 |
|
} |
196 |
0
|
else if(scorep3<=scorep4){ |
197 |
0
|
Log.d(TAG, "P3 WON"); |
198 |
0
|
p3.winner=true; |
199 |
0
|
return p3; |
200 |
|
} |
201 |
|
else{ |
202 |
0
|
Log.d(TAG, "P4 WON"); |
203 |
0
|
p4.winner=true; |
204 |
0
|
return p4; |
205 |
|
|
206 |
|
} |
207 |
0
|
Log.d(TAG, "returning null on winner"); |
208 |
0
|
return null; |
209 |
|
} |
210 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 5 |
Complexity Density: 0,38 |
|
211 |
0
|
public boolean endGameCheck(){... |
212 |
0
|
if(p1.getScore()>=100){ |
213 |
0
|
Log.d(TAG, "Player 1 LOOSES"); |
214 |
0
|
return true; |
215 |
|
} |
216 |
0
|
if(p2.getScore()>=100){ |
217 |
0
|
Log.d(TAG, "Player 2 LOOSES"); |
218 |
0
|
return true; |
219 |
|
|
220 |
|
} |
221 |
0
|
if(p3.getScore()>=100){ |
222 |
0
|
Log.d(TAG, "Player 3 LOOSES"); |
223 |
0
|
return true; |
224 |
|
|
225 |
|
} |
226 |
0
|
if(p4.getScore()>=100){ |
227 |
0
|
Log.d(TAG, "Player 4 LOOSES"); |
228 |
0
|
return true; |
229 |
|
|
230 |
|
} |
231 |
0
|
return false; |
232 |
|
|
233 |
|
} |
234 |
|
|
235 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 5 |
Complexity Density: 0,45 |
|
236 |
0
|
public Player nextPlayer(Player p){... |
237 |
0
|
switch(p.getSeat()){ |
238 |
0
|
case 1: |
239 |
0
|
return this.p2; |
240 |
0
|
case 2: |
241 |
0
|
return this.p3; |
242 |
0
|
case 3: |
243 |
0
|
return this.p4; |
244 |
0
|
case 4: |
245 |
0
|
playing=true; |
246 |
0
|
return this.p1; |
247 |
|
} |
248 |
0
|
return null; |
249 |
|
} |
250 |
|
|
251 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0,33 |
|
252 |
96
|
public void showHand(Player p){... |
253 |
96
|
Deck hand = p.gethand(); |
254 |
96
|
String wholeHand=p.getRealName()+" "; |
255 |
1253
|
for(int i=0;i<hand.getSize();i++){ |
256 |
1157
|
wholeHand+=hand.getCard(i).name+", "; |
257 |
|
} |
258 |
96
|
Log.d(TAG, wholeHand); |
259 |
96
|
Log.d(TAG, "total="+hand.getSize()); |
260 |
|
} |
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
} |
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
|
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
|
275 |
|
|
276 |
|
|
277 |
|
|
278 |
|
|
279 |
|
|