Project

General

Profile

« Previous | Next » 

Revision 0c233a9a

Added by Leszek Koltunski about 2 years ago

Partly merge the 'iap' branch.

View differences:

src/main/java/org/distorted/external/RubikScores.java
21 21
import org.distorted.main.BuildConfig;
22 22
import org.distorted.objects.RubikObject;
23 23
import org.distorted.objects.RubikObjectList;
24
import org.distorted.screens.RubikScreenPlay;
24 25

  
25 26
import static org.distorted.objectlib.main.ObjectType.MAX_SCRAMBLES;
26 27

  
......
29 30

  
30 31
public class RubikScores
31 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

  
32 37
  public static final int MAX_RECORD = 10;
33 38
  public static final int MULT = 1000000;
34 39
  public static final long NO_RECORD = Long.MAX_VALUE;
......
40 45
  private int mNumPlays;
41 46
  private int mNumWins;
42 47
  private int mDeviceID;
48
  private int mNumStars;
43 49

  
44 50
  private static class MapValue
45 51
    {
......
70 76
    mNumRuns = -1;
71 77
    mDeviceID= -1;
72 78
    mNumWins =  0;
79
    mNumStars=  0;
73 80
    }
74 81

  
75 82
///////////////////////////////////////////////////////////////////////////////////////////////////
......
228 235
    return mNumWins;
229 236
    }
230 237

  
238
///////////////////////////////////////////////////////////////////////////////////////////////////
239

  
240
  public void changeNumStars(int stars)
241
    {
242
    mNumStars += stars;
243
    }
244

  
245
///////////////////////////////////////////////////////////////////////////////////////////////////
246

  
247
  public int getNumStars()
248
    {
249
    return mNumStars;
250
    }
251

  
231 252
///////////////////////////////////////////////////////////////////////////////////////////////////
232 253

  
233 254
  public void setName(String newName)
......
237 258

  
238 259
///////////////////////////////////////////////////////////////////////////////////////////////////
239 260

  
240
  public synchronized boolean setRecord(int object, int level, long record)
261
  public synchronized int setRecord(int object, int level, long record)
241 262
    {
242 263
    int key = mapKey(object,level);
243 264
    MapValue oldValue = mMap.get(key);
......
246 267
      {
247 268
      MapValue value = new MapValue(record,0);
248 269
      mMap.put(key,value);
249
      return true;
270
      return RECORD_FIRST;
250 271
      }
251 272

  
252 273
    long oldRecord = oldValue.record;
......
255 276
      {
256 277
      MapValue value = new MapValue(record,0);
257 278
      mMap.put(key,value);
258
      return true;
279
      return RECORD_NEW;
259 280
      }
260 281

  
261
    return false;
282
    return RECORD_NOT_NEW;
262 283
    }
284

  
263 285
///////////////////////////////////////////////////////////////////////////////////////////////////
264 286

  
265 287
  public synchronized long getRecord(int object, int level)
......
355 377
    editor.putInt("scores_numRuns" , mNumRuns );
356 378
    editor.putInt("scores_deviceid", mDeviceID);
357 379
    editor.putInt("scores_review"  , mNumWins );
380
    editor.putInt("scores_review"  , mNumWins );   // legacy name
381
    editor.putInt("scores_numStars", mNumStars );
358 382
    }
359 383

  
360 384
///////////////////////////////////////////////////////////////////////////////////////////////////
......
425 449
    mNumRuns        = preferences.getInt("scores_numRuns" , 0);
426 450
    mDeviceID       = preferences.getInt("scores_deviceid",-1);
427 451
    mNumWins        = preferences.getInt("scores_review"  , 0);
452
    mNumStars       = preferences.getInt("scores_numStars", 0);
428 453

  
429 454
    if( mDeviceID==-1 ) mDeviceID = privateGetDeviceID();
430 455

  
431 456
    if( thereWasError ) recordDBError(errorStr);
432 457
    }
433 458

  
459
///////////////////////////////////////////////////////////////////////////////////////////////////
460

  
461
  public int numberOfSolvedMAXes()
462
    {
463
    int numObjects = RubikObjectList.getNumObjects();
464
    int ret=0, level = RubikScreenPlay.LEVELS_SHOWN;
465

  
466
    for(int obj=0; obj<numObjects; obj++)
467
      {
468
      if( isSolved(obj,level) ) ret++;
469
      }
470

  
471
    return ret;
472
    }
473

  
434 474
///////////////////////////////////////////////////////////////////////////////////////////////////
435 475

  
436 476
  public void recordDBError(String message)
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