example.wormgame
Class WormLink

java.lang.Object
  extended by example.wormgame.WormLink

public class WormLink
extends java.lang.Object

WormLink represents one sub-section of a worm. Because the worm will usually contain a few straight segments, this is a relatively cost effective way to store the entire worm. The [X,Y] coordinates are the "tail" of the worm. The link is drawn starting at the tail and proceeding "len" spaces in direction "dir".


Constructor Summary
WormLink(int startX, int startY, byte direction)
          Create a worm link with a length of 1.
WormLink(int startX, int startY, int length, byte direction)
           
 
Method Summary
 boolean contains(int x, int y)
          Returns true if the worm segment is at the given cell
 void decreaseLength()
          Remove one cell length from the tail of this segment.
 byte getDirection()
          Get the direction this worm segment is pointing.
 int getEndX()
          Get the X coordinate of the cell that contains the tail of this worm segment.
 int getEndY()
          Get the Y coordinate of the cell that contains the tail of this worm segment.
 int getLength()
          Get the length, in cells, of this segment.
 int getX()
          Get the X coordinate of the cell that contains the head of this worm segment.
 int getY()
          Get the Y coordinate of the cell that contains the head of this worm segment.
 void increaseLength()
          Add one cell length to the head of this segment.
 java.lang.String toString()
          Debug method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WormLink

public WormLink(int startX,
                int startY,
                int length,
                byte direction)

WormLink

public WormLink(int startX,
                int startY,
                byte direction)
Create a worm link with a length of 1. This constructor is used when the worm changes direction.

Method Detail

increaseLength

public void increaseLength()
Add one cell length to the head of this segment.


decreaseLength

public void decreaseLength()
Remove one cell length from the tail of this segment.


getLength

public int getLength()
Get the length, in cells, of this segment.


getX

public int getX()
Get the X coordinate of the cell that contains the head of this worm segment.


getY

public int getY()
Get the Y coordinate of the cell that contains the head of this worm segment.


getEndX

public int getEndX()
Get the X coordinate of the cell that contains the tail of this worm segment.


getEndY

public int getEndY()
Get the Y coordinate of the cell that contains the tail of this worm segment.


getDirection

public byte getDirection()
Get the direction this worm segment is pointing.


contains

public boolean contains(int x,
                        int y)
Returns true if the worm segment is at the given cell


toString

public java.lang.String toString()
Debug method.

Overrides:
toString in class java.lang.Object