Project

General

Profile

« Previous | Next » 

Revision 4888e97c

Added by Leszek Koltunski about 4 years ago

Major restructuring around making it possible to include different kinds of RubikObjects in the UI.

View differences:

src/main/java/org/distorted/uistate/RubikStateSolving.java
28 28

  
29 29
import org.distorted.magic.R;
30 30
import org.distorted.magic.RubikActivity;
31
import org.distorted.object.RubikObjectList;
31 32

  
32 33
import java.util.Timer;
33 34
import java.util.TimerTask;
34 35

  
35 36
import static android.view.View.INVISIBLE;
36
import static org.distorted.object.RubikObjectList.LENGTH;
37
import static org.distorted.object.RubikObjectList.NUM_OBJECTS;
38
import static org.distorted.object.RubikObjectList.MAX_SIZE;
37 39
import static org.distorted.uistate.RubikStatePlay.MAX_SCRAMBLE;
38 40

  
39 41
///////////////////////////////////////////////////////////////////////////////////////////////////
......
47 49
  private long mStartTime;
48 50
  private boolean mRunning;
49 51

  
50
  private long[][] mRecords;
52
  private long[][][] mRecords;
51 53

  
52 54
///////////////////////////////////////////////////////////////////////////////////////////////////
53 55

  
54 56
  RubikStateSolving()
55 57
    {
56
    mRecords = new long[LENGTH][MAX_SCRAMBLE];
58
    mRecords = new long[NUM_OBJECTS][MAX_SIZE][MAX_SCRAMBLE];
57 59

  
58
    for(int i=0; i<LENGTH; i++)
59
      for(int j=0; j<MAX_SCRAMBLE; j++)
60
        {
61
        mRecords[i][j] = NO_RECORD;
62
        }
60
    for(int i=0; i<NUM_OBJECTS; i++)
61
      for(int j=0; j<MAX_SIZE; j++)
62
        for(int k=0; k<MAX_SCRAMBLE; k++)
63
          {
64
          mRecords[i][j][k] = NO_RECORD;
65
          }
63 66
    }
64 67

  
65 68
///////////////////////////////////////////////////////////////////////////////////////////////////
......
115 118

  
116 119
  public void savePreferences(SharedPreferences.Editor editor)
117 120
    {
118
    for(int i=0; i<LENGTH; i++)
119
      for(int j=0; j<MAX_SCRAMBLE; j++)
120
        {
121
        if( mRecords[i][j]!=NO_RECORD)
121
    for(int i=0; i<NUM_OBJECTS; i++)
122
      for(int j=0; j<MAX_SIZE; j++)
123
        for(int k=0; k<MAX_SCRAMBLE; k++)
122 124
          {
123
          editor.putLong("record_"+i+"_"+j, mRecords[i][j]);
125
          if( mRecords[i][j][k]!=NO_RECORD)
126
            {
127
            editor.putLong("record_"+i+"_"+j+"_"+k, mRecords[i][j][k]);
128
            }
124 129
          }
125
        }
126 130
    }
127 131

  
128 132
///////////////////////////////////////////////////////////////////////////////////////////////////
129 133

  
130 134
  public void restorePreferences(SharedPreferences preferences)
131 135
    {
132
    for(int i=0; i<LENGTH; i++)
133
      for(int j=0; j<MAX_SCRAMBLE; j++)
134
        {
135
        mRecords[i][j] = preferences.getLong("record_"+i+"_"+j, NO_RECORD );
136
        }
136
    for(int i=0; i<NUM_OBJECTS; i++)
137
      for(int j=0; j<MAX_SIZE; j++)
138
        for(int k=0; k<MAX_SCRAMBLE; k++)
139
          {
140
          mRecords[i][j][k] = preferences.getLong("record_"+i+"_"+j+"_"+k, NO_RECORD );
141
          }
137 142
    }
138 143

  
139 144
///////////////////////////////////////////////////////////////////////////////////////////////////
......
181 186
      long timeTaken = System.currentTimeMillis()-mStartTime;
182 187

  
183 188
      RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
184
      int object  = play.getButton();
189
      int object  = play.getObject();
190
      int size    = play.getSize();
185 191
      int scramble= play.getPicker();
192
      int maxsize = RubikObjectList.getObject(object).getSizes().length;
186 193

  
187
      if( object>=0 && object<LENGTH && scramble>=0 && scramble<MAX_SCRAMBLE )
194
      if( object>=0 && object< NUM_OBJECTS && size>=0 && size<maxsize && scramble>=0 && scramble<MAX_SCRAMBLE )
188 195
        {
189
        if( mRecords[object][scramble]> timeTaken )
196
        if( mRecords[object][size][scramble]> timeTaken )
190 197
          {
191
          mRecords[object][scramble] = timeTaken;
198
          mRecords[object][size][scramble] = timeTaken;
192 199
          android.util.Log.e("solv","new record!");
193 200
          }
194 201
        }

Also available in: Unified diff