Revision bee1d997
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/effect/win/WinEffect.java | ||
---|---|---|
37 | 37 |
{ |
38 | 38 |
NONE (WinEffectNone.class), |
39 | 39 |
SPIN (WinEffectSpin.class), |
40 |
GLOW (WinEffectGlow.class), |
|
40 | 41 |
; |
41 | 42 |
|
42 | 43 |
final Class<? extends WinEffect> effect; |
... | ... | |
48 | 49 |
} |
49 | 50 |
|
50 | 51 |
private static final int NUM_EFFECTS = Type.values().length; |
51 |
private static final int NUM_PHASES = 2; |
|
52 | 52 |
private static final int FAKE_EFFECT_ID = -2; |
53 | 53 |
private static final Type[] types; |
54 | 54 |
|
... | ... | |
66 | 66 |
private EffectListener mListener; |
67 | 67 |
private int mDuration; |
68 | 68 |
private int mEffectReturned; |
69 |
private int[] mCubeEffectNumber, mNodeEffectNumber; |
|
70 |
private int mPhase; |
|
69 |
private int mCubeEffectNumber, mNodeEffectNumber; |
|
71 | 70 |
|
72 | 71 |
RubikCube mCube; |
73 | 72 |
DistortedScreen mScreen; |
74 |
Effect[][] mCubeEffects; |
|
75 |
int[][] mCubeEffectPosition; |
|
76 |
Effect[][] mNodeEffects; |
|
77 |
int[][] mNodeEffectPosition; |
|
78 |
|
|
79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
80 |
|
|
81 |
WinEffect() |
|
82 |
{ |
|
83 |
mPhase = 0; |
|
84 |
|
|
85 |
mCubeEffectNumber = new int[NUM_PHASES]; |
|
86 |
mNodeEffectNumber = new int[NUM_PHASES]; |
|
87 |
mCubeEffectPosition = new int[NUM_PHASES][]; |
|
88 |
mNodeEffectPosition = new int[NUM_PHASES][]; |
|
89 |
mCubeEffects = new Effect[NUM_PHASES][]; |
|
90 |
mNodeEffects = new Effect[NUM_PHASES][]; |
|
91 |
} |
|
73 |
Effect[] mCubeEffects; |
|
74 |
int[] mCubeEffectPosition; |
|
75 |
Effect[] mNodeEffects; |
|
76 |
int[] mNodeEffectPosition; |
|
92 | 77 |
|
93 | 78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
94 | 79 |
|
... | ... | |
113 | 98 |
|
114 | 99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
115 | 100 |
|
116 |
abstract void createEffectsPhase0(int duration); |
|
117 |
abstract void createEffectsPhase1(int duration); |
|
101 |
abstract void createEffects(int duration); |
|
118 | 102 |
|
119 | 103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
120 | 104 |
|
121 | 105 |
public void effectFinished(final long effectID) |
122 | 106 |
{ |
123 |
int total = mCubeEffectNumber[mPhase]+mNodeEffectNumber[mPhase];
|
|
107 |
int total = mCubeEffectNumber+mNodeEffectNumber;
|
|
124 | 108 |
|
125 |
for(int i=0; i<mCubeEffectNumber[mPhase]; i++)
|
|
109 |
for(int i=0; i<mCubeEffectNumber; i++) |
|
126 | 110 |
{ |
127 |
long id = mCubeEffects[mPhase][i].getID();
|
|
111 |
long id = mCubeEffects[i].getID(); |
|
128 | 112 |
|
129 | 113 |
if( effectID == id ) |
130 | 114 |
{ |
131 |
if( ++mEffectReturned == total ) effectAction(mPhase);
|
|
115 |
if( ++mEffectReturned == total ) mListener.effectFinished(FAKE_EFFECT_ID);
|
|
132 | 116 |
mCube.remove(id); |
133 | 117 |
return; |
134 | 118 |
} |
135 | 119 |
} |
136 |
for(int i=0; i<mNodeEffectNumber[mPhase]; i++)
|
|
120 |
for(int i=0; i<mNodeEffectNumber; i++) |
|
137 | 121 |
{ |
138 |
long id = mNodeEffects[mPhase][i].getID();
|
|
122 |
long id = mNodeEffects[i].getID(); |
|
139 | 123 |
|
140 | 124 |
if( effectID == id ) |
141 | 125 |
{ |
142 |
if( ++mEffectReturned == total ) effectAction(mPhase);
|
|
126 |
if( ++mEffectReturned == total ) mListener.effectFinished(FAKE_EFFECT_ID);
|
|
143 | 127 |
mCube.getEffects().abortById(id); |
144 | 128 |
return; |
145 | 129 |
} |
146 | 130 |
} |
147 | 131 |
} |
148 | 132 |
|
149 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
150 |
|
|
151 |
private void effectAction(int phase) |
|
152 |
{ |
|
153 |
switch(phase) |
|
154 |
{ |
|
155 |
case 0: mEffectReturned = 0; |
|
156 |
mPhase = 1; |
|
157 |
mCube.solve(); |
|
158 |
createEffectsPhase1(mDuration); |
|
159 |
assignEffects(mPhase); |
|
160 |
break; |
|
161 |
case 1: mListener.effectFinished(FAKE_EFFECT_ID); |
|
162 |
break; |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 | 133 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
167 | 134 |
|
168 | 135 |
public long start(int duration, RubikRenderer renderer) |
... | ... | |
172 | 139 |
mListener = renderer; |
173 | 140 |
mDuration = duration; |
174 | 141 |
|
175 |
createEffectsPhase0(mDuration);
|
|
176 |
assignEffects(mPhase);
|
|
142 |
createEffects(mDuration); |
|
143 |
assignEffects(); |
|
177 | 144 |
|
178 | 145 |
return FAKE_EFFECT_ID; |
179 | 146 |
} |
180 | 147 |
|
181 | 148 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
182 | 149 |
|
183 |
private void assignEffects(int phase)
|
|
150 |
private void assignEffects() |
|
184 | 151 |
{ |
185 |
mCubeEffectNumber[phase] = ( mCubeEffects[phase]!=null ) ? mCubeEffects[phase].length : 0;
|
|
186 |
mNodeEffectNumber[phase] = ( mNodeEffects[phase]!=null ) ? mNodeEffects[phase].length : 0;
|
|
152 |
mCubeEffectNumber = ( mCubeEffects!=null ) ? mCubeEffects.length : 0;
|
|
153 |
mNodeEffectNumber = ( mNodeEffects!=null ) ? mNodeEffects.length : 0;
|
|
187 | 154 |
|
188 |
if( mCubeEffectNumber[phase]==0 && mNodeEffectNumber[phase]==0 )
|
|
155 |
if( mCubeEffectNumber==0 && mNodeEffectNumber==0 )
|
|
189 | 156 |
{ |
190 |
throw new RuntimeException("Cube and Node Effects ("+phase+" phase) both not created!");
|
|
157 |
throw new RuntimeException("Cube and Node Effects both not created!"); |
|
191 | 158 |
} |
192 | 159 |
|
193 |
for(int i=0; i<mCubeEffectNumber[phase]; i++)
|
|
160 |
for(int i=0; i<mCubeEffectNumber; i++) |
|
194 | 161 |
{ |
195 |
mCube.apply(mCubeEffects[phase][i],mCubeEffectPosition[phase][i]);
|
|
196 |
mCubeEffects[phase][i].notifyWhenFinished(this);
|
|
162 |
mCube.apply(mCubeEffects[i],mCubeEffectPosition[i]);
|
|
163 |
mCubeEffects[i].notifyWhenFinished(this); |
|
197 | 164 |
} |
198 | 165 |
|
199 | 166 |
DistortedEffects nodeEffects = mCube.getEffects(); |
200 | 167 |
|
201 |
for(int i=0; i<mNodeEffectNumber[phase]; i++)
|
|
168 |
for(int i=0; i<mNodeEffectNumber; i++) |
|
202 | 169 |
{ |
203 |
nodeEffects.apply(mNodeEffects[phase][i],mNodeEffectPosition[phase][i]);
|
|
204 |
mNodeEffects[phase][i].notifyWhenFinished(this);
|
|
170 |
nodeEffects.apply(mNodeEffects[i],mNodeEffectPosition[i]);
|
|
171 |
mNodeEffects[i].notifyWhenFinished(this); |
|
205 | 172 |
} |
206 | 173 |
} |
207 | 174 |
|
... | ... | |
220 | 187 |
} |
221 | 188 |
catch(NoSuchMethodException ex) |
222 | 189 |
{ |
223 |
android.util.Log.e("SolveEffect", type.effect.getSimpleName()+": exception getting method: "+ex.getMessage());
|
|
190 |
android.util.Log.e("WinEffect", type.effect.getSimpleName()+": exception getting method: "+ex.getMessage());
|
|
224 | 191 |
method = null; |
225 | 192 |
} |
226 | 193 |
|
... | ... | |
230 | 197 |
} |
231 | 198 |
catch(Exception ex) |
232 | 199 |
{ |
233 |
android.util.Log.e("SolveEffect", type.effect.getSimpleName()+": exception invoking method: "+ex.getMessage());
|
|
200 |
android.util.Log.e("WinEffect", type.effect.getSimpleName()+": exception invoking method: "+ex.getMessage());
|
|
234 | 201 |
} |
235 | 202 |
} |
236 | 203 |
} |
Also available in: Unified diff
RubikCube: add new WinEffectGlow