Revision 41748f19
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/states/RubikStateSolver.java | ||
---|---|---|
45 | 45 |
|
46 | 46 |
public class RubikStateSolver extends RubikStateAbstract |
47 | 47 |
{ |
48 |
private static final int NUM_FACES = 6; |
|
49 | 48 |
private static final int BITMAP_SIZE = 35; |
50 | 49 |
|
51 |
private static final int[] FACE_COLORS = new int[] |
|
52 |
{ |
|
53 |
0xffffff00, 0xffffffff, |
|
54 |
0xff0000ff, 0xff00ff00, |
|
55 |
0xffff0000, 0xffb5651d |
|
56 |
}; |
|
50 |
private static final RubikObjectList OBJECT = RubikObjectList.CUBE; |
|
51 |
private static final int SIZE = 3; |
|
57 | 52 |
|
58 | 53 |
private static Bitmap[] mBitmap; |
59 | 54 |
private ImageButton[] mColorButton; |
60 | 55 |
private Button mBackButton, mSolveButton; |
61 | 56 |
private boolean mSolving; |
62 | 57 |
private int mCurrentColor; |
58 |
private int[] mFaceColors; |
|
59 |
private int mNumFaces; |
|
63 | 60 |
|
64 | 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
65 | 62 |
|
... | ... | |
74 | 71 |
{ |
75 | 72 |
mSolving = false; |
76 | 73 |
|
77 |
act.changeObject(RubikObjectList.CUBE,3,null);
|
|
74 |
act.changeObject(OBJECT,SIZE,null);
|
|
78 | 75 |
RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass(); |
79 |
play.setObjectAndSize(RubikObjectList.CUBE,3);
|
|
76 |
play.setObjectAndSize(OBJECT,SIZE);
|
|
80 | 77 |
|
81 |
int[] colors = RubikObjectList.retFaceColors(RubikObjectList.CUBE); |
|
82 |
|
|
83 |
if( colors != null ) |
|
84 |
{ |
|
85 |
int len = colors.length; |
|
86 |
|
|
87 |
android.util.Log.e("solver", "retColors len="+len+" first: "+colors[0]); |
|
88 |
} |
|
89 |
else |
|
90 |
{ |
|
91 |
android.util.Log.e("solver", "retColors null"); |
|
92 |
} |
|
78 |
mFaceColors = RubikObjectList.retFaceColors(OBJECT); |
|
79 |
mNumFaces = mFaceColors!=null ? mFaceColors.length : 0; |
|
93 | 80 |
|
94 | 81 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
95 | 82 |
final float scale = metrics.density; |
... | ... | |
98 | 85 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar); |
99 | 86 |
layoutTop.removeAllViews(); |
100 | 87 |
|
101 |
if( mBitmap ==null ) setupBitmaps(scale); |
|
102 |
if( mColorButton==null ) setupColorButtons(act,scale); |
|
88 |
if( mNumFaces>0 ) |
|
89 |
{ |
|
90 |
if( mBitmap ==null ) setupBitmaps(scale); |
|
91 |
if( mColorButton==null ) setupColorButtons(act,scale); |
|
103 | 92 |
|
104 |
markButton(act); |
|
93 |
markButton(act); |
|
94 |
} |
|
105 | 95 |
|
106 | 96 |
for(ImageButton button: mColorButton) layoutTop.addView(button); |
107 | 97 |
|
... | ... | |
127 | 117 |
final float R = SIZE*0.10f; |
128 | 118 |
final float M = SIZE*0.05f; |
129 | 119 |
|
130 |
mBitmap = new Bitmap[NUM_FACES];
|
|
120 |
mBitmap = new Bitmap[mNumFaces];
|
|
131 | 121 |
|
132 | 122 |
Paint paint = new Paint(); |
133 | 123 |
paint.setColor(0xff008800); |
... | ... | |
137 | 127 |
paint.setTextAlign(Paint.Align.CENTER); |
138 | 128 |
paint.setStyle(Paint.Style.FILL); |
139 | 129 |
|
140 |
for(int i=0; i<NUM_FACES; i++)
|
|
130 |
for(int i=0; i<mNumFaces; i++)
|
|
141 | 131 |
{ |
142 | 132 |
mBitmap[i] = Bitmap.createBitmap(SIZE, SIZE, Bitmap.Config.ARGB_8888); |
143 | 133 |
Canvas canvas = new Canvas(mBitmap[i]); |
... | ... | |
145 | 135 |
paint.setColor(0xff000000); |
146 | 136 |
canvas.drawRect(0, 0, SIZE, SIZE, paint); |
147 | 137 |
|
148 |
paint.setColor(FACE_COLORS[i]);
|
|
138 |
paint.setColor(mFaceColors[i]);
|
|
149 | 139 |
canvas.drawRoundRect( M, M, SIZE-M, SIZE-M, R, R, paint); |
150 | 140 |
} |
151 | 141 |
} |
... | ... | |
154 | 144 |
|
155 | 145 |
private void setupColorButtons(final RubikActivity act, final float scale) |
156 | 146 |
{ |
157 |
mColorButton = new ImageButton[NUM_FACES];
|
|
147 |
mColorButton = new ImageButton[mNumFaces];
|
|
158 | 148 |
|
159 |
for(int i=0; i<NUM_FACES; i++)
|
|
149 |
for(int i=0; i<mNumFaces; i++)
|
|
160 | 150 |
{ |
161 | 151 |
final int ii = i; |
162 | 152 |
int padding = (int)(3*scale + 0.5f); |
... | ... | |
233 | 223 |
|
234 | 224 |
private void markButton(RubikActivity act) |
235 | 225 |
{ |
236 |
for(int b=0; b<NUM_FACES; b++)
|
|
226 |
for(int b=0; b<mNumFaces; b++)
|
|
237 | 227 |
{ |
238 | 228 |
Drawable d = mColorButton[b].getBackground(); |
239 | 229 |
|
Also available in: Unified diff
Progress making the Solver state more abstract.