Project

General

Profile

« Previous | Next » 

Revision 2e8ec627

Added by Leszek Koltunski over 4 years ago

Fixes for the fact that one could easily cheat - just pause the app while solving and come back to it, the time would reset to 0 and the object to unscrambled :(

View differences:

src/main/java/org/distorted/dialogs/RubikDialogPatternView.java
159 159
          RubikObjectList list = RubikPatternList.getObject(mTab);
160 160
          int size             = RubikPatternList.getSize(mTab);
161 161

  
162
          act.changeObject( list, size, moves);
162
          act.setupObject( list, size, moves);
163 163

  
164 164
          RubikStatePattern state = (RubikStatePattern) RubikState.PATT.getStateClass();
165 165
          state.setPattern(act, mTab, category, ii);
src/main/java/org/distorted/main/RubikActivity.java
102 102
        if( sizeIndex>=0 && sizeIndex<sizes.length )
103 103
          {
104 104
          success = true;
105
          view.getPostRender().changeObject( obj, size, null );
105
          view.getPostRender().changeObject(obj,size);
106 106
          }
107 107

  
108 108
        }
......
113 113
        int s = RubikStatePlay.DEF_SIZE;
114 114

  
115 115
        play.setObjectAndSize(obj,s);
116
        view.getPostRender().changeObject(obj,s, null);
116
        view.getPostRender().changeObject(obj,s);
117 117
        }
118 118
      }
119 119
    
......
193 193

  
194 194
///////////////////////////////////////////////////////////////////////////////////////////////////
195 195

  
196
    public void changeObject(RubikObjectList object, int size, int[][] moves)
196
    public void changeObject(RubikObjectList object, int size)
197 197
      {
198 198
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
199 199
      RubikPostRender post = view.getPostRender();
200
      post.changeObject(object,size,moves);
200
      post.changeObject(object,size);
201
      }
202

  
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204

  
205
    public void setupObject(RubikObjectList object, int size, int[][] moves)
206
      {
207
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
208
      RubikPostRender post = view.getPostRender();
209
      post.setupObject(object,size,moves);
201 210
      }
202 211

  
203 212
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/main/RubikPostRender.java
43 43

  
44 44
  private RubikSurfaceView mView;
45 45
  private boolean mFinishRotation, mRemoveRotation, mRemovePatternRotation, mAddRotation,
46
                  mSetQuatCurrent, mSetQuatAccumulated, mChangeObject, mSolveObject,
46
                  mSetQuatCurrent, mSetQuatAccumulated, mChangeObject, mSetupObject, mSolveObject,
47 47
                  mScrambleObject, mInitializeObject, mSetTextureMap, mResetAllTextureMaps;
48 48
  private boolean mCanRotate, mCanPlay;
49 49
  private boolean mIsSolved;
......
77 77
    mSetQuatCurrent       = false;
78 78
    mSetQuatAccumulated   = false;
79 79
    mChangeObject         = false;
80
    mSetupObject          = false;
80 81
    mSolveObject          = false;
81 82
    mScrambleObject       = false;
82 83

  
......
233 234
    {
234 235
    mChangeObject = false;
235 236

  
237
    if ( mNewObject==null || mNewObject.getObjectList()!=mNextObject || mNewObject.getSize()!=mNextSize)
238
      {
239
      mCanRotate= false;
240
      mCanPlay  = false;
241
      createObjectNow(mNextObject, mNextSize, null);
242
      doEffectNow( BaseEffect.Type.SIZECHANGE );
243
      }
244
    }
245

  
246
///////////////////////////////////////////////////////////////////////////////////////////////////
247

  
248
  private void setupObjectNow()
249
    {
250
    mSetupObject = false;
251

  
236 252
    if ( mNewObject==null || mNewObject.getObjectList()!=mNextObject || mNewObject.getSize()!=mNextSize)
237 253
      {
238 254
      mCanRotate= false;
......
352 368

  
353 369
///////////////////////////////////////////////////////////////////////////////////////////////////
354 370

  
355
  void changeObject(RubikObjectList object, int size, int[][] moves)
371
  void changeObject(RubikObjectList object, int size)
356 372
    {
357 373
    if( size>0 )
358 374
      {
359 375
      mChangeObject = true;
360 376
      mNextObject = object;
361 377
      mNextSize   = size;
378
      }
379
    }
380

  
381
///////////////////////////////////////////////////////////////////////////////////////////////////
382

  
383
  void setupObject(RubikObjectList object, int size, int[][] moves)
384
    {
385
    if( size>0 )
386
      {
387
      mSetupObject= true;
388
      mNextObject = object;
389
      mNextSize   = size;
362 390
      mNextMoves  = moves;
363 391
      }
364 392
    }
......
412 440
    if( mRemoveRotation        ) removeRotationNow();
413 441
    if( mRemovePatternRotation ) removePatternRotationNow();
414 442
    if( mChangeObject          ) changeObjectNow();
443
    if( mSetupObject           ) setupObjectNow();
415 444
    if( mSolveObject           ) solveObjectNow();
416 445
    if( mScrambleObject        ) scrambleObjectNow();
417 446
    if( mAddRotation           ) addRotationNow();
src/main/java/org/distorted/main/RubikSurfaceView.java
375 375

  
376 376
                                           if( RubikState.getCurrentState()==RubikState.READ )
377 377
                                             {
378
                                             RubikStateSolving solving = (RubikStateSolving)RubikState.SOLV.getStateClass();
379
                                             solving.resetElapsed();
380

  
378 381
                                             final RubikActivity act = (RubikActivity)getContext();
379 382

  
380 383
                                             act.runOnUiThread(new Runnable()
......
385 388
                                                 RubikState.switchState( act, RubikState.SOLV);
386 389
                                                 }
387 390
                                               });
388

  
389
                                             RubikStateSolving solving = (RubikStateSolving)RubikState.SOLV.getStateClass();
390
                                             solving.startCounting( (RubikActivity)getContext() );
391 391
                                             }
392 392

  
393 393
                                           mBeginningRotation = false;
src/main/java/org/distorted/states/RubikStatePattern.java
71 71
      int objectPlay= play.getObject();
72 72
      int sizePlay  = play.getSize();
73 73

  
74
      act.changeObject(RubikObjectList.getObject(objectPlay),sizePlay,null);
74
      act.changeObject(RubikObjectList.getObject(objectPlay),sizePlay);
75 75
      }
76 76
    }
77 77

  
src/main/java/org/distorted/states/RubikStatePlay.java
280 280
              {
281 281
              mObject = obj;
282 282
              mSize   = sizes[size];
283
              act.changeObject(list,sizes[size],null);
283
              act.changeObject(list,sizes[size]);
284 284

  
285 285
              int sizeIndex = RubikObjectList.getSizeIndex(mObject,mSize);
286 286
              int maxLevel  = RubikObjectList.getMaxLevel(mObject, sizeIndex);
src/main/java/org/distorted/states/RubikStateSolver.java
81 81
    mCurrentObject     = ImplementedSolversList.getObject(0);
82 82
    mCurrentObjectSize = ImplementedSolversList.getObjectSize(0);
83 83

  
84
    act.changeObject(mCurrentObject, mCurrentObjectSize, null);
84
    act.setupObject(mCurrentObject, mCurrentObjectSize, null);
85 85
    RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
86 86
    play.setObjectAndSize(mCurrentObject, mCurrentObjectSize);
87 87

  
src/main/java/org/distorted/states/RubikStateSolving.java
53 53
  private ImageButton mPrevButton;
54 54
  private boolean mCanPrevMove;
55 55
  private ArrayList<Move> mMoves;
56
  private long mElapsed;
56 57

  
57 58
  private static class Move
58 59
    {
......
86 87
    {
87 88
    mCanPrevMove = true;
88 89

  
90
    startCounting(act);
91

  
89 92
    if( mMoves==null ) mMoves = new ArrayList<>();
90 93
    else               mMoves.clear();
91 94

  
......
97 100
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);
98 101
    layoutTop.removeAllViews();
99 102
    mTime = (TextView)inflater.inflate(R.layout.upper_text, null);
100
    mTime.setText(act.getString(R.string.tm_placeholder,0,0));
103
    int elapsed = (int)mElapsed/1000;
104
    mTime.setText(act.getString(R.string.tm_placeholder,elapsed/60,elapsed%60));
101 105
    layoutTop.addView(mTime);
102 106

  
103 107
    // BOT ////////////////////////////
......
212 216
    {
213 217
    mPrevButton = null;
214 218

  
215
    editor.putLong("stateSolving_startTime" , mStartTime);
219
    mElapsed = System.currentTimeMillis()-mStartTime;
220
    editor.putLong("stateSolving_elapsed" , mElapsed);
216 221
    mScores.savePreferences(editor);
217 222
    }
218 223

  
......
220 225

  
221 226
  public void restorePreferences(SharedPreferences preferences)
222 227
    {
223
    mStartTime = preferences.getLong("stateSolving_startTime" , 0 );
228
    mElapsed = preferences.getLong("stateSolving_elapsed" , 0 );
224 229
    mScores.restorePreferences(preferences);
225 230
    }
226 231

  
227 232
///////////////////////////////////////////////////////////////////////////////////////////////////
228 233

  
229
  public void startCounting(final RubikActivity act)
234
  private void startCounting(final RubikActivity act)
230 235
    {
231 236
    if( !mRunning )
232 237
      {
233 238
      mRunning = true;
234
      mStartTime = System.currentTimeMillis();
239
      mStartTime = System.currentTimeMillis() - mElapsed;
235 240
      mTimer = new Timer();
236 241

  
237 242
      mTimer.scheduleAtFixedRate(new TimerTask()
......
266 271
        }
267 272
      mRunning = false;
268 273

  
269
      long timeTaken = System.currentTimeMillis()-mStartTime;
274
      mElapsed = System.currentTimeMillis()-mStartTime;
270 275

  
271 276
      RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
272 277
      int object  = play.getObject();
......
274 279
      int level   = play.getLevel();
275 280
      int realSize= RubikObjectList.getSizeIndex(object,size);
276 281

  
277
      boolean isNew = mScores.setRecord(object, realSize, level, timeTaken);
282
      boolean isNew = mScores.setRecord(object, realSize, level, mElapsed);
278 283

  
279
      return isNew ? timeTaken : -timeTaken;
284
      return isNew ? mElapsed : -mElapsed;
280 285
      }
281 286

  
282 287
    return 0;
283 288
    }
284 289

  
290
///////////////////////////////////////////////////////////////////////////////////////////////////
291

  
292
  public void resetElapsed()
293
    {
294
    mElapsed = 0;
295
    }
296

  
285 297
///////////////////////////////////////////////////////////////////////////////////////////////////
286 298

  
287 299
  public void onActionFinished(final long effectID)

Also available in: Unified diff