1 |
|
package game.shad.tempus.hearts; |
2 |
|
|
3 |
|
import android.content.Context; |
4 |
|
import android.graphics.Canvas; |
5 |
|
import android.graphics.Rect; |
6 |
|
import android.util.Log; |
7 |
|
import android.view.MotionEvent; |
8 |
|
import android.view.SurfaceHolder; |
9 |
|
import android.view.SurfaceHolder.Callback; |
10 |
|
import android.view.SurfaceView; |
11 |
|
import android.view.View; |
12 |
|
import android.view.View.OnTouchListener; |
13 |
|
import android.widget.Toast; |
14 |
|
|
|
|
| 86,3% |
Uncovered Elements: 14 (102) |
Complexity: 29 |
Complexity Density: 0,45 |
|
15 |
|
public class DeckHolder extends SurfaceView implements Callback, OnTouchListener |
16 |
|
{ |
17 |
|
public static final String TAG = "Hearts--DeckHolder"; |
18 |
|
|
19 |
|
private Deck deck; |
20 |
|
private Card Card; |
21 |
|
private int screenWidth; |
22 |
|
private int screenHeight; |
23 |
|
private int position=0; |
24 |
|
private boolean full=false; |
25 |
|
public boolean initialized = false; |
26 |
|
private SurfaceHolder surfaceHolder; |
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
private Context mContext; |
32 |
|
private GameView gameView; |
33 |
|
|
34 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0,11 |
|
35 |
8
|
public DeckHolder(Context context, GameView gameView, int sW, int sH){... |
36 |
8
|
super(context); |
37 |
8
|
this.mContext=context; |
38 |
8
|
this.gameView = gameView; |
39 |
8
|
surfaceHolder = this.getHolder(); |
40 |
8
|
surfaceHolder.addCallback(this); |
41 |
8
|
this.screenWidth = sW; |
42 |
8
|
this.screenHeight = sH; |
43 |
8
|
this.deck = new Deck(); |
44 |
8
|
addBlankCards(); |
45 |
|
|
46 |
|
|
47 |
|
} |
48 |
|
|
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0,33 |
|
50 |
8
|
public void addBlankCards(){... |
51 |
8
|
this.deck.clearALL(); |
52 |
8
|
this.position=0; |
53 |
8
|
int i = 0; |
54 |
104
|
while(i < 12){ |
55 |
96
|
this.deck.addCard(new Card(0,0, mContext)); |
56 |
96
|
i++; |
57 |
|
} |
58 |
|
} |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
60 |
0
|
public Card getCard(int i){... |
61 |
0
|
return this.deck.getCard(i); |
62 |
|
} |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
3785
|
public int getPosition() {... |
65 |
3785
|
return position; |
66 |
|
} |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
68 |
55
|
public void setPosition(int position) {... |
69 |
55
|
this.position = position; |
70 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
0
|
public Rect getBounds(){... |
72 |
0
|
return new Rect(0, this.screenHeight, this.screenWidth, this.screenHeight); |
73 |
|
} |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
75 |
8
|
public void addDeck(Deck deck){... |
76 |
8
|
this.deck.clearALL(); |
77 |
8
|
this.deck = deck; |
78 |
|
} |
79 |
|
|
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
81 |
23
|
public void swipeLeft(){... |
82 |
23
|
if(getPosition()<deck.getSize()-1) |
83 |
1
|
setPosition(getPosition() + 1); |
84 |
|
else |
85 |
22
|
setPosition(0); |
86 |
|
} |
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
87 |
32
|
public void swipeRight(){... |
88 |
32
|
if(getPosition()>=1) |
89 |
2
|
setPosition(getPosition() - 1); |
90 |
|
else{ |
91 |
30
|
setPosition(deck.getSize()-1); |
92 |
|
} |
93 |
|
|
94 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
95 |
0
|
public void addCard(Card c){... |
96 |
0
|
this.deck.addCard(c); |
97 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
98 |
0
|
public void removeAll(){... |
99 |
0
|
this.deck.clearALL(); |
100 |
|
} |
101 |
|
|
|
|
| 88,6% |
Uncovered Elements: 4 (35) |
Complexity: 8 |
Complexity Density: 0,35 |
|
102 |
216
|
@Override... |
103 |
|
protected void onDraw(Canvas canvas){ |
104 |
216
|
super.onDraw(canvas); |
105 |
|
|
106 |
216
|
full=false; |
107 |
216
|
int displayed=0; |
108 |
|
|
109 |
216
|
int cardWidth=screenWidth/7; |
110 |
216
|
int i=getPosition(); |
111 |
216
|
int loop=0; |
112 |
2160
|
while(!full){ |
113 |
1944
|
if(displayed>7){ |
114 |
|
|
115 |
|
|
116 |
216
|
full=true; |
117 |
|
} |
118 |
1944
|
if(!full){ |
119 |
1728
|
if(i>=deck.getSize()&&deck.getSize()>7){ |
120 |
102
|
loop=i; |
121 |
102
|
i=0; |
122 |
|
} |
123 |
1728
|
if(i>=deck.getSize()){ |
124 |
0
|
break; |
125 |
|
} |
126 |
1728
|
if(i<0){ |
127 |
0
|
i=deck.getSize()+i; |
128 |
|
} |
129 |
|
|
130 |
1728
|
Card c=deck.getCard(i); |
131 |
1728
|
c.resizeBitmap(cardWidth, screenHeight); |
132 |
1728
|
c.setCoords(cardWidth*((i+loop)-getPosition()), 0, cardWidth+cardWidth*((i+loop)-getPosition()), screenHeight); |
133 |
1728
|
c.draw(canvas); |
134 |
1728
|
i++; |
135 |
1728
|
displayed++; |
136 |
|
} |
137 |
|
} |
138 |
|
|
139 |
|
} |
140 |
|
|
141 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
142 |
56
|
public void updateDeck(Deck deck){... |
143 |
56
|
this.deck = deck; |
144 |
56
|
refreshDrawableState(); |
145 |
|
} |
146 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
147 |
20
|
public Deck getDeck(){... |
148 |
20
|
return this.deck; |
149 |
|
} |
150 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
151 |
0
|
public void updateCurrentCard(Card Card){... |
152 |
0
|
this.Card = Card; |
153 |
|
} |
154 |
|
|
155 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
156 |
8
|
@Override... |
157 |
|
public void surfaceChanged(SurfaceHolder holder, int format, int width, |
158 |
|
int height) { |
159 |
|
|
160 |
|
|
161 |
|
} |
162 |
|
|
163 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
164 |
8
|
@Override... |
165 |
|
public void surfaceCreated(SurfaceHolder holder) { |
166 |
8
|
Log.d(TAG, "surface Created"); |
167 |
8
|
initialized = true; |
168 |
8
|
setOnTouchListener(this); |
169 |
8
|
this.deck = gameView.game.p1.deck; |
170 |
|
|
171 |
|
|
172 |
|
} |
173 |
|
|
174 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
175 |
8
|
@Override... |
176 |
|
public void surfaceDestroyed(SurfaceHolder holder) { |
177 |
8
|
Log.d(TAG, "surface Created"); |
178 |
8
|
initialized = false; |
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
} |
183 |
|
|
184 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
185 |
20
|
@Override... |
186 |
|
public boolean onTouch(View v, MotionEvent event) { |
187 |
20
|
Log.d(TAG, "Touching at x="+event.getX()+", y="+event.getY()); |
188 |
20
|
gameView.deckViewTouched((int)event.getX(), (int)event.getY()); |
189 |
|
|
190 |
20
|
return false; |
191 |
|
} |
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
} |