Revision 373fa45f
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/states/RubikStateSolver.java | ||
---|---|---|
39 | 39 |
import org.distorted.main.RubikPostRender; |
40 | 40 |
import org.distorted.objects.RubikObject; |
41 | 41 |
import org.distorted.objects.RubikObjectList; |
42 |
import org.distorted.solvers.ImplementedSolversList; |
|
42 | 43 |
import org.distorted.solvers.Solver; |
43 | 44 |
|
45 |
import java.lang.ref.WeakReference; |
|
46 |
|
|
44 | 47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
45 | 48 |
|
46 | 49 |
public class RubikStateSolver extends RubikStateAbstract |
47 | 50 |
{ |
48 | 51 |
private static final int BITMAP_SIZE = 35; |
49 | 52 |
|
50 |
private static final RubikObjectList OBJECT = RubikObjectList.CUBE; |
|
51 |
private static final int SIZE = 3; |
|
52 |
|
|
53 | 53 |
private static Bitmap[] mBitmap; |
54 | 54 |
private ImageButton[] mColorButton; |
55 | 55 |
private Button mBackButton, mSolveButton; |
... | ... | |
58 | 58 |
private int[] mFaceColors; |
59 | 59 |
private int mNumFaces; |
60 | 60 |
|
61 |
private RubikObjectList mCurrentObject; |
|
62 |
private int mCurrentObjectSize; |
|
63 |
|
|
64 |
private WeakReference<RubikActivity> mWeakAct; |
|
65 |
|
|
61 | 66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
62 | 67 |
|
63 | 68 |
void leaveState(RubikActivity act) |
... | ... | |
69 | 74 |
|
70 | 75 |
void enterState(final RubikActivity act) |
71 | 76 |
{ |
77 |
mWeakAct = new WeakReference<>(act); |
|
78 |
|
|
72 | 79 |
mSolving = false; |
73 | 80 |
|
74 |
act.changeObject(OBJECT,SIZE,null); |
|
81 |
mCurrentObject = ImplementedSolversList.getObject(0); |
|
82 |
mCurrentObjectSize = ImplementedSolversList.getObjectSize(0); |
|
83 |
|
|
84 |
act.changeObject(mCurrentObject, mCurrentObjectSize, null); |
|
75 | 85 |
RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass(); |
76 |
play.setObjectAndSize(OBJECT,SIZE);
|
|
86 |
play.setObjectAndSize(mCurrentObject, mCurrentObjectSize);
|
|
77 | 87 |
|
78 |
mFaceColors = RubikObjectList.retFaceColors(OBJECT);
|
|
88 |
mFaceColors = RubikObjectList.retFaceColors(mCurrentObject);
|
|
79 | 89 |
mNumFaces = mFaceColors!=null ? mFaceColors.length : 0; |
80 | 90 |
|
81 | 91 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
... | ... | |
189 | 199 |
mSolving = true; |
190 | 200 |
RubikObject object = act.getObject(); |
191 | 201 |
String objectString = object.retObjectString(); |
192 |
Solver solver = new Solver( act, objectString ); |
|
202 |
Solver solver = new Solver( act.getResources(), mCurrentObject, mCurrentObjectSize, objectString );
|
|
193 | 203 |
solver.start(); |
194 | 204 |
} |
195 | 205 |
} |
... | ... | |
265 | 275 |
|
266 | 276 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
267 | 277 |
|
268 |
public void setSolved( final RubikActivity act, final int numMoves, final String moves)
|
|
278 |
public void setSolved(final String moves) |
|
269 | 279 |
{ |
270 | 280 |
mSolving = false; |
281 |
final RubikActivity act = mWeakAct.get(); |
|
271 | 282 |
|
272 |
act.runOnUiThread(new Runnable()
|
|
283 |
if( act!=null )
|
|
273 | 284 |
{ |
274 |
@Override |
|
275 |
public void run() |
|
285 |
act.runOnUiThread(new Runnable() |
|
276 | 286 |
{ |
277 |
RubikState.switchState(act,RubikState.SOLU); |
|
278 |
RubikStateSolution solution = (RubikStateSolution) RubikState.SOLU.getStateClass(); |
|
279 |
solution.setupMoves(act, numMoves, moves); |
|
280 |
} |
|
281 |
}); |
|
287 |
@Override |
|
288 |
public void run() |
|
289 |
{ |
|
290 |
RubikState.switchState(act,RubikState.SOLU); |
|
291 |
RubikStateSolution solution = (RubikStateSolution) RubikState.SOLU.getStateClass(); |
|
292 |
solution.setupMoves(act, moves); |
|
293 |
} |
|
294 |
}); |
|
295 |
} |
|
282 | 296 |
} |
283 | 297 |
|
284 | 298 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
285 | 299 |
|
286 |
public void displayErrorDialog( final RubikActivity act, String message)
|
|
300 |
public void displayErrorDialog( String message) |
|
287 | 301 |
{ |
288 | 302 |
mSolving = false; |
303 |
RubikActivity act = mWeakAct.get(); |
|
289 | 304 |
|
290 |
RubikDialogSolverError dialog = new RubikDialogSolverError(); |
|
291 |
Bundle bundle = new Bundle(); |
|
292 |
bundle.putString("error", message ); |
|
293 |
dialog.setArguments(bundle); |
|
294 |
dialog.show( act.getSupportFragmentManager(), null); |
|
305 |
if( act!=null ) |
|
306 |
{ |
|
307 |
RubikDialogSolverError dialog = new RubikDialogSolverError(); |
|
308 |
Bundle bundle = new Bundle(); |
|
309 |
bundle.putString("error", message ); |
|
310 |
dialog.setArguments(bundle); |
|
311 |
dialog.show( act.getSupportFragmentManager(), null); |
|
312 |
} |
|
295 | 313 |
} |
296 | 314 |
} |
Also available in: Unified diff
Progress making the Solver state more abstract.