Revision 24679c47
Added by Leszek Koltunski about 3 years ago
| src/main/java/org/distorted/external/RubikScores.java | ||
|---|---|---|
| 30 | 30 |
|
| 31 | 31 |
public class RubikScores |
| 32 | 32 |
{
|
| 33 |
public static final int RECORD_FIRST = 0; |
|
| 34 |
public static final int RECORD_NEW = 1; |
|
| 35 |
public static final int RECORD_NOT_NEW = 2; |
|
| 36 |
|
|
| 33 | 37 |
public static final int MAX_RECORD = 10; |
| 34 | 38 |
public static final int MULT = 1000000; |
| 35 | 39 |
public static final long NO_RECORD = Long.MAX_VALUE; |
| ... | ... | |
| 238 | 242 |
|
| 239 | 243 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 240 | 244 |
|
| 241 |
public synchronized boolean setRecord(int object, int level, long record)
|
|
| 245 |
public synchronized int setRecord(int object, int level, long record)
|
|
| 242 | 246 |
{
|
| 243 | 247 |
int key = mapKey(object,level); |
| 244 | 248 |
MapValue oldValue = mMap.get(key); |
| ... | ... | |
| 247 | 251 |
{
|
| 248 | 252 |
MapValue value = new MapValue(record,0); |
| 249 | 253 |
mMap.put(key,value); |
| 250 |
return true;
|
|
| 254 |
return RECORD_FIRST;
|
|
| 251 | 255 |
} |
| 252 | 256 |
|
| 253 | 257 |
long oldRecord = oldValue.record; |
| ... | ... | |
| 256 | 260 |
{
|
| 257 | 261 |
MapValue value = new MapValue(record,0); |
| 258 | 262 |
mMap.put(key,value); |
| 259 |
return true;
|
|
| 263 |
return RECORD_NEW;
|
|
| 260 | 264 |
} |
| 261 | 265 |
|
| 262 |
return false;
|
|
| 266 |
return RECORD_NOT_NEW;
|
|
| 263 | 267 |
} |
| 268 |
|
|
| 264 | 269 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 265 | 270 |
|
| 266 | 271 |
public synchronized long getRecord(int object, int level) |
| src/main/java/org/distorted/main/RubikObjectLibInterface.java | ||
|---|---|---|
| 44 | 44 |
|
| 45 | 45 |
import java.lang.ref.WeakReference; |
| 46 | 46 |
|
| 47 |
import static org.distorted.external.RubikScores.RECORD_FIRST; |
|
| 48 |
import static org.distorted.external.RubikScores.RECORD_NOT_NEW; |
|
| 49 |
|
|
| 47 | 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 48 | 51 |
|
| 49 | 52 |
public class RubikObjectLibInterface implements ObjectLibInterface |
| 50 | 53 |
{
|
| 51 | 54 |
private final WeakReference<RubikActivity> mAct; |
| 52 |
private boolean mIsNewRecord;
|
|
| 55 |
private int mIsNewRecord;
|
|
| 53 | 56 |
private long mNewRecord; |
| 54 | 57 |
private int mLastCubitColor, mLastCubit, mLastCubitFace; |
| 55 | 58 |
|
| ... | ... | |
| 195 | 198 |
reportRecord(act,startTime,endTime,debug,scrambleNum); |
| 196 | 199 |
requestReview(act); |
| 197 | 200 |
|
| 198 |
if( mIsNewRecord ) |
|
| 201 |
if( mIsNewRecord!=RECORD_NOT_NEW )
|
|
| 199 | 202 |
{
|
| 200 |
RubikDialogNewRecord dialog = new RubikDialogNewRecord(); |
|
| 201 |
dialog.setArguments(bundle); |
|
| 202 |
dialog.show( act.getSupportFragmentManager(), RubikDialogNewRecord.getDialogTag() ); |
|
| 203 |
if( mIsNewRecord==RECORD_FIRST && RubikObjectList.thereAreLockedObjects() ) |
|
| 204 |
{
|
|
| 205 |
|
|
| 206 |
} |
|
| 207 |
else |
|
| 208 |
{
|
|
| 209 |
RubikDialogNewRecord dialog = new RubikDialogNewRecord(); |
|
| 210 |
dialog.setArguments(bundle); |
|
| 211 |
dialog.show( act.getSupportFragmentManager(), RubikDialogNewRecord.getDialogTag() ); |
|
| 212 |
} |
|
| 203 | 213 |
} |
| 204 | 214 |
else |
| 205 | 215 |
{
|
| ... | ... | |
| 308 | 318 |
if( ScreenList.getCurrentScreen()== ScreenList.SOLV ) |
| 309 | 319 |
{
|
| 310 | 320 |
RubikScreenSolving solving = (RubikScreenSolving) ScreenList.SOLV.getScreenClass(); |
| 311 |
mNewRecord = solving.getRecord(); |
|
| 312 |
|
|
| 313 |
if( mNewRecord< 0 ) |
|
| 314 |
{
|
|
| 315 |
mNewRecord = -mNewRecord; |
|
| 316 |
mIsNewRecord = false; |
|
| 317 |
} |
|
| 318 |
else |
|
| 319 |
{
|
|
| 320 |
mIsNewRecord = true; |
|
| 321 |
} |
|
| 321 |
mNewRecord = solving.stopTimerAndGetRecord(); |
|
| 322 |
mIsNewRecord = solving.setRecord(); |
|
| 322 | 323 |
} |
| 323 | 324 |
} |
| 324 | 325 |
|
| src/main/java/org/distorted/objects/RubikObjectList.java | ||
|---|---|---|
| 358 | 358 |
return mFreeBoughtObjects.equals("*");
|
| 359 | 359 |
} |
| 360 | 360 |
|
| 361 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 362 |
|
|
| 363 |
public static boolean thereAreLockedObjects() |
|
| 364 |
{
|
|
| 365 |
for(int i=0; i<mNumObjects; i++) |
|
| 366 |
{
|
|
| 367 |
RubikObject o = mObjects.get(i); |
|
| 368 |
if( !o.isFree() ) return true; |
|
| 369 |
} |
|
| 370 |
|
|
| 371 |
return false; |
|
| 372 |
} |
|
| 373 |
|
|
| 361 | 374 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 362 | 375 |
|
| 363 | 376 |
public static boolean objectAlreadyBought(String shortName) |
| src/main/java/org/distorted/screens/RubikScreenSolving.java | ||
|---|---|---|
| 167 | 167 |
|
| 168 | 168 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 169 | 169 |
|
| 170 |
public long getRecord()
|
|
| 170 |
public long stopTimerAndGetRecord()
|
|
| 171 | 171 |
{
|
| 172 | 172 |
if( mRunning ) |
| 173 | 173 |
{
|
| 174 | 174 |
stopCounting(); |
| 175 |
|
|
| 176 | 175 |
mElapsed = System.currentTimeMillis()-mStartTime; |
| 177 |
|
|
| 178 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass(); |
|
| 179 |
int object = RubikObjectList.getCurrObject(); |
|
| 180 |
int level = play.getLevel()-1; |
|
| 181 |
boolean isNew = mScores.setRecord(object, level, mElapsed); |
|
| 182 |
|
|
| 183 |
return isNew ? mElapsed : -mElapsed; |
|
| 176 |
return mElapsed; |
|
| 184 | 177 |
} |
| 185 | 178 |
|
| 186 | 179 |
return 0; |
| 187 | 180 |
} |
| 188 | 181 |
|
| 182 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 183 |
|
|
| 184 |
public int setRecord() |
|
| 185 |
{
|
|
| 186 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass(); |
|
| 187 |
int object = RubikObjectList.getCurrObject(); |
|
| 188 |
int level = play.getLevel()-1; |
|
| 189 |
return mScores.setRecord(object, level, mElapsed); |
|
| 190 |
} |
|
| 191 |
|
|
| 189 | 192 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 190 | 193 |
|
| 191 | 194 |
public void resetElapsed() |
Also available in: Unified diff
Progress with marking objects as free.