smithers.twisty
Class Snake

java.lang.Object
  extended by smithers.twisty.Snake
All Implemented Interfaces:
TwistyPuzzle

public class Snake
extends java.lang.Object
implements TwistyPuzzle

Represents a Rubik's Snake.


Constructor Summary
Snake()
          Creates a Rubik's Snake with 24 pieces.
Snake(int pieces)
          Creates a Rubik's Snake-like puzzle with the specified number of pieces.
 
Method Summary
 int getColor(int index)
          Gets the colour of the specified sticker.
 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 getTwist(int index, int dir)
          Gets the twist instance determined by the sticker clicked on, and the directon to 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Snake

public Snake()
Creates a Rubik's Snake with 24 pieces.


Snake

public Snake(int pieces)
Creates a Rubik's Snake-like puzzle with the specified number of pieces.

Parameters:
pieces - the number of pieces
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

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

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.

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