|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object smithers.twisty.RubiksCube
public class RubiksCube
Represents a Rubik's Cube, or similar larger/smaller twisty cube puzzle.
Constructor Summary | |
---|---|
RubiksCube()
Constructs a new 3x3x3 Rubik's Cube. |
|
RubiksCube(int side)
Constructs a new cube with a given side length. |
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. |
int |
getLocation(int index)
Gets the location of a sticker. |
Polygon3D |
getPolygon(int index)
Gets the 3-d polygon associated with the specified sticker. |
int |
getRotation(int index)
Gets the rotation of a sticker. |
double |
getScale()
Returns the absolute scale of the 3-d model of the puzzle. |
int |
getSticker(int loc)
Gets the index of the sticker in a specific location. |
int |
getStickerRotation(int loc)
Gets the rotation of the sticker in a location. |
Twist |
getTwist(int index,
int dir)
Gets the twist instance determined by the sticker clicked on, and the directon to twist. |
Twist |
getTwist(int face,
int d1,
int d2,
int dir)
Gets the twist instance defined by the parameters. |
boolean |
isAnimating()
Returns true iff the puzzle is partway through a twist. |
boolean |
isSolved()
Works out whether this puzzle is in the solved state. |
boolean |
isSolvedAligned()
Determines whether the puzzle is solved, including checking the orientation of each sticker. |
void |
reset()
Resets the cube. |
void |
scramble()
Scrambles the cube. |
int |
side()
Gets the side length. |
int |
side(int top,
int side,
int x,
int y)
Looks at one of the faces next to face top as if it is forwards
and face top is on top, and gives the index of the sticker in
position (x,y) . |
int |
stickerCount()
Gets the number of stickers on the puzzle. |
java.lang.String |
toString()
Returns a String representation of this cube. |
void |
twist(int face,
int d1,
int d2,
int dir)
Twists face face of the cube from layer d1 (inclusive)
to layer d2 (exclusive). |
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, wait, wait, wait |
Constructor Detail |
---|
public RubiksCube()
public RubiksCube(int side)
side
- the length of the sideMethod Detail |
---|
public int side()
public int stickerCount()
stickerCount
in interface TwistyPuzzle
public int getColor(int index)
getColor
in interface TwistyPuzzle
index
- the sticker index
public double getScale()
getScale
in interface TwistyPuzzle
public Polygon3D getPolygon(int index)
getPolygon
in interface TwistyPuzzle
index
- the sticker index
public int getLocation(int index)
getLocation
in interface StickerSwappingTwistyPuzzle
index
- the sticker index
getSticker(int)
,
getRotation(int)
public int getSticker(int loc)
getSticker
in interface StickerSwappingTwistyPuzzle
loc
- the location index
getLocation(int)
,
getStickerRotation(int)
public int getRotation(int index)
index
from 0 to 3. If the puzzle is partway through a
twist, this returns the value before the twist.
index
- the sticker index
getLocation(int)
public int getStickerRotation(int loc)
loc
from 0 to 3. If
the puzzle is partway through a twist, this returns the value before the
twist.
loc
- the location of the sticker
getSticker(int)
public Twist getTwist(int face, int d1, int d2, int dir)
twist(int,int,int,int)
for the description of the twist.
face
- the face to twist parallel tod1
- the first layer to turnd2
- the first layer not to turndir
- the direction
java.lang.IndexOutOfBoundsException
- if d1<0 || d2<d1 || s<d2
public Twist getTwist(int index, int dir)
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.
getTwist
in interface TwistyPuzzle
index
- the sticker which was clicked ondir
- the directon
public void twist(Twist twist)
twist
in interface TwistyPuzzle
twist
- the twistpublic void twist(Twist twist, double time)
twist
in interface AnimatedTwistyPuzzle
twist
- the twist to maketime
- the time to takepublic boolean isAnimating()
TwistyPuzzle
may fail with an
AnimatingException
.
isAnimating
in interface AnimatedTwistyPuzzle
true
iff the puzzle is animating a twistpublic void advanceAnimation(double time)
advanceAnimation
in interface AnimatedTwistyPuzzle
time
- the amount of time to advancepublic final void twist(int face, int d1, int d2, int dir)
face
of the cube from layer d1
(inclusive)
to layer d2
(exclusive). Notice of course that the face itself
is turned iff d1==0 && d2>0
, the opposite face is turned iff
d2==s && d1<s
. Nothing happens if d1==d2
. The direction
of the turn is specified by dir
(mod 4): 1 = anticlockwise, 2 =
half twist, 3 = clockwise.
face
- the face to twist parallel tod1
- the first layer to turnd2
- the first layer not to turndir
- the direction
java.lang.IndexOutOfBoundsException
- if d1<0 || d2<d1 || s<d2
AnimatingException
- if the puzzle is part way through an
animationpublic final int side(int top, int side, int x, int y)
top
as if it is forwards
and face top
is on top, and gives the index of the sticker in
position (x,y)
. x
and y
are interpreted modulo
the side length. The side is counted around anticlockwise by side
from the one on the left edge of face top
.
top
- the face to consider as the 'top'side
- which side of the top face to look next tox
- the position on the face counting parallel to 'top'y
- the position on the face counting away from 'top'
public void scramble()
scramble
in interface TwistyPuzzle
public void reset()
public java.lang.String toString()
String
representation of this cube.
toString
in class java.lang.Object
String
representing this cubepublic boolean isSolved()
isSolved
in interface TwistyPuzzle
true
iff the puzzle is solvedpublic boolean isSolvedAligned()
true
if the puzzle is solved with all stickers correctly
oriented
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |