Project

General

Profile

« Previous | Next » 

Revision ca280c3f

Added by Leszek Koltunski almost 2 years ago

Make the BandagedPlay use FastScramble. (static 500 times)

View differences:

src/main/java/org/distorted/bandaged/BandagedPlayScreen.java
19 19

  
20 20
package org.distorted.bandaged;
21 21

  
22
import java.util.Random;
23

  
24 22
import android.app.Activity;
25 23
import android.content.SharedPreferences;
26
import android.os.Bundle;
27 24
import android.view.View;
28 25
import android.widget.LinearLayout;
29 26

  
30
import org.distorted.dialogs.RubikDialogBandagedSettings;
31 27
import org.distorted.helpers.LockController;
32 28
import org.distorted.helpers.MovesController;
33 29
import org.distorted.helpers.TransparentImageButton;
34 30
import org.distorted.main.R;
35 31
import org.distorted.objectlib.main.ObjectControl;
36
import org.distorted.objectlib.main.TwistyObject;
37 32

  
38 33
///////////////////////////////////////////////////////////////////////////////////////////////////
39 34

  
40 35
public class BandagedPlayScreen
41 36
{
42
  public static final int[] DEPTHS = new int[] {20,50,100,200,500,1000};
43
  public static final int ANIMATION_ON  = 0;
44
  public static final int ANIMATION_OFF = 1;
37
  private static final int NUM_SCRAMBLES = 500;
45 38

  
46
  private TransparentImageButton mBackButton, mScrambleButton, mSolveButton, mSettingsButton;
39
  private TransparentImageButton mBackButton, mScrambleButton, mSolveButton;
47 40
  private final LockController mLockController;
48 41
  private final MovesController mMovesController;
49 42
  private String mKey;
50
  private int[][] mMoves;
51
  private Random mRnd;
52

  
53
  private int mAnimationMode;
54
  private int mScrambleDepth;
55 43

  
56 44
///////////////////////////////////////////////////////////////////////////////////////////////////
57 45

  
......
81 69
      });
82 70
    }
83 71

  
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

  
86
  private void setupSettingsButton(final BandagedPlayActivity act)
87
    {
88
    int icon = BandagedPlayActivity.getDrawable(R.drawable.ui_small_settings,R.drawable.ui_medium_settings, R.drawable.ui_big_settings, R.drawable.ui_huge_settings);
89
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
90
    mSettingsButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
91

  
92
    mSettingsButton.setOnClickListener( new View.OnClickListener()
93
      {
94
      @Override
95
      public void onClick(View v)
96
        {
97
        Bundle bundle = new Bundle();
98
        bundle.putInt("scraPos", mScrambleDepth );
99
        bundle.putInt("animPos", mAnimationMode );
100

  
101
        RubikDialogBandagedSettings setDiag = new RubikDialogBandagedSettings();
102
        setDiag.setArguments(bundle);
103
        setDiag.show(act.getSupportFragmentManager(), null);
104
        }
105
      });
106
    }
107

  
108 72
///////////////////////////////////////////////////////////////////////////////////////////////////
109 73

  
110 74
  private void setupSolveButton(final BandagedPlayActivity act)
......
119 83
      public void onClick(View v)
120 84
        {
121 85
        ObjectControl control = act.getControl();
122
        if( mAnimationMode==ANIMATION_OFF ) control.solveOnly();
123
        if( mAnimationMode==ANIMATION_ON  ) control.solveObject();
86
        control.solveObject();
124 87
        mMovesController.clearMoves(act);
125 88
        }
126 89
      });
......
140 103
      public void onClick(View v)
141 104
        {
142 105
        ObjectControl control = act.getControl();
143
        TwistyObject object = control.getObject();
144

  
145
        int depth = DEPTHS[mScrambleDepth];
146

  
147
        if( mAnimationMode==ANIMATION_OFF )
148
          {
149
          if( mMoves==null || mMoves.length<depth ) mMoves = new int[depth][3];
150
          if( mRnd==null ) mRnd = new Random();
151

  
152
          for(int move=0; move<depth; move++)
153
            {
154
            object.randomizeNewScramble(mMoves, mRnd, move, depth);
155
            }
156
          for(int move=0; move<depth; move++)
157
            {
158
            int row = mMoves[move][1];
159
            mMoves[move][1] = (1<<row);
160
            }
161

  
162
          control.initializeObject(mMoves);
163
          }
164

  
165
        if( mAnimationMode==ANIMATION_ON )
166
          {
167
          control.scrambleObject(depth);
168
          }
106
        control.fastScrambleObject(NUM_SCRAMBLES);
107
        mMovesController.clearMoves(act);
169 108
        }
170 109
      });
171 110
    }
......
205 144
    layoutLower.addView(layoutRight);
206 145

  
207 146
    setupSolveButton(act);
208
    setupSettingsButton(act);
209 147
    setupScrambleButton(act);
210 148

  
211 149
    LinearLayout layoutUpper = act.findViewById(R.id.upperBar);
......
218 156
    layoutRightU.setLayoutParams(paramsR);
219 157

  
220 158
    layoutLeftU.addView(mSolveButton);
221
    layoutMidU.addView(mSettingsButton);
222 159
    layoutRightU.addView(mScrambleButton);
223 160

  
224 161
    layoutUpper.removeAllViews();
......
257 194
    mMovesController.savePreferences(mKey,editor);
258 195
    ObjectControl control = act.getControl();
259 196
    control.savePreferences(editor);
260

  
261
    editor.putInt("playScreen_scramble" , mScrambleDepth);
262
    editor.putInt("playScreen_animation", mAnimationMode);
263 197
    }
264 198

  
265 199
///////////////////////////////////////////////////////////////////////////////////////////////////
......
269 203
    mMovesController.restorePreferences(act,mKey,preferences);
270 204
    ObjectControl control = act.getControl();
271 205
    control.restorePreferences(preferences);
272

  
273
    mScrambleDepth = preferences.getInt("playScreen_scramble" ,3);
274
    mAnimationMode = preferences.getInt("playScreen_animation",ANIMATION_OFF);
275
    }
276

  
277
///////////////////////////////////////////////////////////////////////////////////////////////////
278

  
279
  public void setAnimationMode(int mode)
280
    {
281
    mAnimationMode = mode;
282
    }
283

  
284
///////////////////////////////////////////////////////////////////////////////////////////////////
285

  
286
  public void setScrambleDepth(int depth)
287
    {
288
    mScrambleDepth = depth;
289 206
    }
290 207
}

Also available in: Unified diff