Revision 8becce57
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/patterns/RubikPattern.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.patterns; |
21 | 21 |
|
22 |
import org.distorted.magic.RubikPostRender; |
|
22 | 23 |
import org.distorted.object.RubikObject; |
23 | 24 |
|
24 | 25 |
import java.util.Vector; |
... | ... | |
27 | 28 |
|
28 | 29 |
public class RubikPattern |
29 | 30 |
{ |
31 |
private static final int DURATION_MILLIS = 1000; |
|
32 |
|
|
30 | 33 |
public static final int MIN_CUBE = 2; |
31 | 34 |
public static final int MAX_CUBE = 5; |
32 | 35 |
public static final int NUM_CUBES = MAX_CUBE-MIN_CUBE+1; |
... | ... | |
113 | 116 |
|
114 | 117 |
///////////////////////////////////////////////////////////// |
115 | 118 |
|
116 |
void makeMove(RubikObject object, int pattern)
|
|
119 |
void makeMove(RubikPostRender post, int pattern)
|
|
117 | 120 |
{ |
118 | 121 |
if( pattern>=0 && pattern<numPatterns ) |
119 | 122 |
{ |
120 | 123 |
Pattern p = patterns.elementAt(pattern); |
121 |
if( p!=null ) p.makeMove(object);
|
|
124 |
if( p!=null ) p.makeMove(post);
|
|
122 | 125 |
} |
123 | 126 |
} |
124 | 127 |
|
125 | 128 |
///////////////////////////////////////////////////////////// |
126 | 129 |
|
127 |
void backMove(RubikObject object, int pattern)
|
|
130 |
void backMove(RubikPostRender post, int pattern)
|
|
128 | 131 |
{ |
129 | 132 |
if( pattern>=0 && pattern<numPatterns ) |
130 | 133 |
{ |
131 | 134 |
Pattern p = patterns.elementAt(pattern); |
132 |
if( p!=null ) p.backMove(object);
|
|
135 |
if( p!=null ) p.backMove(post);
|
|
133 | 136 |
} |
134 | 137 |
} |
135 | 138 |
|
... | ... | |
149 | 152 |
|
150 | 153 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
151 | 154 |
|
152 |
private static class Pattern |
|
155 |
private static class Pattern implements RubikPostRender.ActionFinishedListener
|
|
153 | 156 |
{ |
154 | 157 |
private String name; |
155 | 158 |
private String moves; |
156 | 159 |
private int curMove; |
157 | 160 |
private int numMove; |
158 | 161 |
|
162 |
private boolean mCanRotate; |
|
163 |
private RubikObject mObject; |
|
164 |
|
|
159 | 165 |
///////////////////////////////////////////////////////////// |
160 | 166 |
|
161 | 167 |
Pattern(String n, String m) |
... | ... | |
164 | 170 |
moves=m; |
165 | 171 |
numMove = moves.length()/4; |
166 | 172 |
curMove=numMove; |
173 |
|
|
174 |
mCanRotate = true; |
|
167 | 175 |
} |
168 | 176 |
|
169 | 177 |
///////////////////////////////////////////////////////////// |
... | ... | |
176 | 184 |
///////////////////////////////////////////////////////////// |
177 | 185 |
|
178 | 186 |
int getNumMove() |
179 |
{ |
|
180 |
return numMove; |
|
181 |
} |
|
187 |
{
|
|
188 |
return numMove;
|
|
189 |
}
|
|
182 | 190 |
|
183 | 191 |
///////////////////////////////////////////////////////////// |
184 | 192 |
|
185 | 193 |
int getCurMove() |
186 |
{ |
|
187 |
return curMove; |
|
188 |
} |
|
194 |
{
|
|
195 |
return curMove;
|
|
196 |
}
|
|
189 | 197 |
|
190 | 198 |
///////////////////////////////////////////////////////////// |
191 | 199 |
|
192 |
void makeMove(RubikObject object)
|
|
200 |
void makeMove(RubikPostRender post)
|
|
193 | 201 |
{ |
194 | 202 |
curMove++; |
203 |
RubikObject object = post.getObject(); |
|
195 | 204 |
|
196 |
if( curMove>numMove) |
|
205 |
if( curMove>numMove )
|
|
197 | 206 |
{ |
198 | 207 |
curMove= 0; |
199 | 208 |
object.initializeObject(moves.substring(0,4*curMove)); |
200 | 209 |
} |
201 | 210 |
else |
202 | 211 |
{ |
203 |
if( !object.makeMove(moves.substring(4*curMove-4,4*curMove)) )
|
|
212 |
if( mCanRotate )
|
|
204 | 213 |
{ |
214 |
mCanRotate = false; |
|
215 |
mObject = object; |
|
216 |
|
|
217 |
String move = moves.substring(4*curMove-4,4*curMove); |
|
218 |
int a1=move.charAt(1)-'0'; |
|
219 |
int a2=move.charAt(2)-'0'; |
|
220 |
int a3=move.charAt(3)-'0'; |
|
221 |
|
|
222 |
int axis = (10*a1+a2)/32; |
|
223 |
int rowBitmap = (10*a1+a2)%32; |
|
224 |
int angle = (2-a3)*(360/object.getBasicAngle()); |
|
225 |
int numRot = Math.abs(2-a3); |
|
226 |
|
|
227 |
post.addRotation(this, axis, rowBitmap, angle, numRot*DURATION_MILLIS); |
|
228 |
} |
|
229 |
else |
|
230 |
{ |
|
231 |
android.util.Log.e("pattern", "failed to make Move!"); |
|
232 |
|
|
205 | 233 |
curMove--; |
206 | 234 |
} |
207 | 235 |
} |
... | ... | |
209 | 237 |
|
210 | 238 |
///////////////////////////////////////////////////////////// |
211 | 239 |
|
212 |
void backMove(RubikObject object)
|
|
240 |
void backMove(RubikPostRender post)
|
|
213 | 241 |
{ |
214 | 242 |
curMove--; |
243 |
RubikObject object = post.getObject(); |
|
215 | 244 |
|
216 |
if( curMove<0) |
|
245 |
if( curMove<0 )
|
|
217 | 246 |
{ |
218 | 247 |
curMove=numMove; |
219 | 248 |
object.initializeObject(moves.substring(0,4*curMove)); |
220 | 249 |
} |
221 | 250 |
else |
222 | 251 |
{ |
223 |
if( !object.backMove(moves.substring(4*curMove,4*curMove+4)) )
|
|
252 |
if( mCanRotate )
|
|
224 | 253 |
{ |
254 |
mCanRotate = false; |
|
255 |
mObject = object; |
|
256 |
|
|
257 |
String move = moves.substring(4*curMove,4*curMove+4); |
|
258 |
int a1=move.charAt(1)-'0'; |
|
259 |
int a2=move.charAt(2)-'0'; |
|
260 |
int a3=move.charAt(3)-'0'; |
|
261 |
|
|
262 |
int axis = (10*a1+a2)/32; |
|
263 |
int rowBitmap = (10*a1+a2)%32; |
|
264 |
int angle = (2-a3)*(360/object.getBasicAngle()); |
|
265 |
int numRot = Math.abs(2-a3); |
|
266 |
|
|
267 |
post.addRotation(this, axis, rowBitmap, -angle, numRot*DURATION_MILLIS); |
|
268 |
} |
|
269 |
else |
|
270 |
{ |
|
271 |
android.util.Log.e("pattern", "failed to back Move!"); |
|
225 | 272 |
curMove++; |
226 | 273 |
} |
227 | 274 |
} |
... | ... | |
233 | 280 |
{ |
234 | 281 |
return moves.substring(0,4*curMove); |
235 | 282 |
} |
283 |
|
|
284 |
///////////////////////////////////////////////////////////// |
|
285 |
|
|
286 |
public void onActionFinished(final long effectID) |
|
287 |
{ |
|
288 |
mObject.removeRotationNow(); |
|
289 |
mCanRotate = true; |
|
290 |
} |
|
236 | 291 |
} |
237 | 292 |
|
238 | 293 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
384 | 439 |
|
385 | 440 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
386 | 441 |
|
387 |
public void makeMove(RubikObject object, int size, int cat, int pat)
|
|
442 |
public void makeMove(RubikPostRender post, int size, int cat, int pat)
|
|
388 | 443 |
{ |
389 | 444 |
if( size>=0 && size<NUM_CUBES && cat>=0 && cat< numCategories[size] ) |
390 | 445 |
{ |
391 | 446 |
Category c = mCategories[size].elementAt(cat); |
392 |
if( c!=null ) c.makeMove(object,pat);
|
|
447 |
if( c!=null ) c.makeMove(post,pat);
|
|
393 | 448 |
} |
394 | 449 |
} |
395 | 450 |
|
396 | 451 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
397 | 452 |
|
398 |
public void backMove(RubikObject object, int size, int cat, int pat)
|
|
453 |
public void backMove(RubikPostRender post, int size, int cat, int pat)
|
|
399 | 454 |
{ |
400 | 455 |
if( size>=0 && size<NUM_CUBES && cat>=0 && cat< numCategories[size] ) |
401 | 456 |
{ |
402 | 457 |
Category c = mCategories[size].elementAt(cat); |
403 |
if( c!=null ) c.backMove(object,pat);
|
|
458 |
if( c!=null ) c.backMove(post,pat);
|
|
404 | 459 |
} |
405 | 460 |
} |
406 | 461 |
|
Also available in: Unified diff
Major progress with Prretty Patterns - hopefully only initializing the Object remains!