smithers.twisty
Class SquareOne

java.lang.Object
  extended by smithers.twisty.SquareOne
All Implemented Interfaces:
AnimatedTwistyPuzzle, TwistyPuzzle

public class SquareOne
extends java.lang.Object
implements AnimatedTwistyPuzzle

Represents the twisty puzzle Square One/Cube 21.


Constructor Summary
SquareOne()
          Constructs a new Square One puzzle.
 
Method Summary
 void advanceAnimation(double time)
          Advances the animation by a certain amount of time.
 int getColor(int index)
          Gets the colour of the specified sticker.
 Twist getFlip(int which)
           
 Polygon3D getPolygon(int index)
          Gets the 3-d polygon associated with the specified sticker.
 double getScale()
          Returns the absolute scale of the 3-d model of the puzzle.
 Twist getTurn(int top, int bottom)
           
 Twist getTwist(int index, int dir)
          Gets the twist instance determined by the sticker clicked on, and the directon to twist.
 boolean isAnimating()
          Returns true iff the puzzle is partway through a twist.
 boolean isSolved()
          Works out whether this puzzle is in the solved state.
 void scramble()
          Scrambles the puzzle.
 int stickerCount()
          Gets the number of stickers on the puzzle.
 void twist(Twist twist)
          Applies a twist.
 void twist(Twist twist, double time)
          Twists the puzzle over a specified amount of time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SquareOne

public SquareOne()
Constructs a new Square One puzzle.

Method Detail

stickerCount

public int stickerCount()
Gets the number of stickers on the puzzle.

Specified by:
stickerCount in interface TwistyPuzzle
Returns:
the number of stickers

getColor

public int getColor(int index)
Gets the colour of the specified sticker. The colour returned is specified as ARGB.

Specified by:
getColor in interface TwistyPuzzle
Parameters:
index - the sticker index
Returns:
the colour of the sticker

getScale

public double getScale()
Returns the absolute scale of the 3-d model of the puzzle. Essentially, this should return the recommended 3-d width of the viewing window.

Specified by:
getScale in interface TwistyPuzzle
Returns:
the scale

getPolygon

public Polygon3D getPolygon(int index)
Gets the 3-d polygon associated with the specified sticker.

Specified by:
getPolygon in interface TwistyPuzzle
Parameters:
index - the sticker index
Returns:
the polygon of the sticker

getTurn

public Twist getTurn(int top,
                     int bottom)

getFlip

public Twist getFlip(int which)

getTwist

public Twist getTwist(int index,
                      int dir)
Gets the twist instance determined by the sticker clicked on, and the directon to twist. This should always return an instance which will be accepted by TwistyPuzzle.twist(smithers.twisty.Twist) (i.e. will not throw ClassCastException, although the move may not be possible). The dir argument should be: 0 for anticlockwise, 1 for clockwise or 2 for a half twist.

Specified by:
getTwist in interface TwistyPuzzle
Parameters:
index - the sticker which was clicked on
dir - the directon
Returns:
the twist instance

twist

public void twist(Twist twist)
Applies a twist.

Specified by:
twist in interface TwistyPuzzle
Parameters:
twist - the twist

twist

public void twist(Twist twist,
                  double time)
Twists the puzzle over a specified amount of time. Using a time of 0 should apply the twist immediately. Supplying a negative number for the time allows the puzzle to choose the time based on the twist using the absolute value of the time as a maximum.

Specified by:
twist in interface AnimatedTwistyPuzzle
Parameters:
twist - the twist to make
time - the time to take

isAnimating

public boolean isAnimating()
Returns true iff the puzzle is partway through a twist. If this method returns true, any modifier in TwistyPuzzle may fail with an AnimatingException.

Specified by:
isAnimating in interface AnimatedTwistyPuzzle
Returns:
true iff the puzzle is animating a twist

advanceAnimation

public void advanceAnimation(double time)
Advances the animation by a certain amount of time.

Specified by:
advanceAnimation in interface AnimatedTwistyPuzzle
Parameters:
time - the amount of time to advance

scramble

public void scramble()
Scrambles the puzzle.

Specified by:
scramble in interface TwistyPuzzle

isSolved

public boolean isSolved()
Works out whether this puzzle is in the solved state.
This puzzle is considered solved if it is in a cube shape and each face is entirely one colour. Equivalently, it is solved if each piece is in its original position, or if each piece is in its original position except that the entire cube has been flipped over.

Specified by:
isSolved in interface TwistyPuzzle
Returns:
true iff the puzzle is solved