example.pushpuzzle
Class Board

java.lang.Object
  extended by example.pushpuzzle.Board

public class Board
extends java.lang.Object

The class Board knows how the pieces move, handles undo, and handles reading of screens.


Field Summary
static int DOWN
           
static byte GROUND
           
static int LEFT
           
static int MOVEPACKET
           
static byte PACKET
           
static byte PUSHER
           
static int RIGHT
           
static byte STORE
           
static int UP
           
static byte WALL
           
 
Constructor Summary
Board()
          Creates new Board initialized to a simple puzzle.
 
Method Summary
 byte get(int x, int y)
          Return the pieces at the location.
 int getHeight()
          Get the height of the board.
 int getMoves()
          Get the number of moves to get this far.
 int getPusherLocation()
          Get the location of the pusher.
 int getPushes()
          Get the number of packets pushed around.
 int getStored()
          Get the number of packets stored.
 int getWidth()
          Get the width of the game board.
 int move(int move)
          Move the pusher in the direction indicated.
 void read(java.io.InputStream is, int l)
          Read a board from a stream.
 int runTo(int x, int y, int max)
          Move the player to the position (x,y), if possible.
 void screen0()
          Create the hard coded simple game board.
 boolean solved()
          Determine if the screen has been solved.
 int undoMove()
          Undo the most recent move
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEFT

public static final int LEFT
See Also:
Constant Field Values

RIGHT

public static final int RIGHT
See Also:
Constant Field Values

UP

public static final int UP
See Also:
Constant Field Values

DOWN

public static final int DOWN
See Also:
Constant Field Values

MOVEPACKET

public static final int MOVEPACKET
See Also:
Constant Field Values

GROUND

public static final byte GROUND
See Also:
Constant Field Values

STORE

public static final byte STORE
See Also:
Constant Field Values

PACKET

public static final byte PACKET
See Also:
Constant Field Values

WALL

public static final byte WALL
See Also:
Constant Field Values

PUSHER

public static final byte PUSHER
See Also:
Constant Field Values
Constructor Detail

Board

public Board()
Creates new Board initialized to a simple puzzle.

Method Detail

screen0

public void screen0()
Create the hard coded simple game board.


move

public int move(int move)
Move the pusher in the direction indicated. If there is a wall, don't move. if there is a packet in that direction, try to move it.

Parameters:
move - the direction; one of LEFT, RIGHT, UP, DOWN
Returns:
the direction actually moved, -1 if not moved

undoMove

public int undoMove()
Undo the most recent move

Returns:
the move undone; if none -1 is returned; See LEFT, RIGHT, UP, DOWN, and MOVEPACKET

solved

public boolean solved()
Determine if the screen has been solved.


runTo

public int runTo(int x,
                 int y,
                 int max)
Move the player to the position (x,y), if possible. Return the direction it moved if successful, otherwise -1. The position (x,y) must be empty.

Parameters:
x - window coordinate
y - window coordinate
Returns:
the direction that it moved, -1 is not moved; See LEFT, RIGHT, UP, DOWN, MOVEPACKET

get

public byte get(int x,
                int y)
Return the pieces at the location.

Parameters:
x - location in the board.
y - location in the board.
Returns:
flags indicating what pieces are in this board location. Bit flags; combinations of WALL, PUSHER, STORE, PACKET.

getPusherLocation

public int getPusherLocation()
Get the location of the pusher. It is returned as an int with the lower 16 bits being the x index and the upper 16 bits being the y index.

Returns:
the encoded location of the pusher.

read

public void read(java.io.InputStream is,
                 int l)
Read a board from a stream. Read it into a fixed size array and then shrink to fit.


getWidth

public int getWidth()
Get the width of the game board.


getHeight

public int getHeight()
Get the height of the board.


getMoves

public int getMoves()
Get the number of moves to get this far.


getPushes

public int getPushes()
Get the number of packets pushed around.


getStored

public int getStored()
Get the number of packets stored.