Methods Summary |
---|
public boolean | contains(int x, int y)Returns true if the worm segment is at the given cell
switch (dir) {
case Worm.LEFT:
return ((y == this.y) && ((x <= this.x) && (x >= getEndX())));
case Worm.RIGHT:
return ((y == this.y) && ((x >= this.x) && (x <= getEndX())));
case Worm.UP:
return ((x == this.x) && ((y <= this.y) && (y >= getEndY())));
case Worm.DOWN:
return ((x == this.x) && ((y >= this.y) && (y <= getEndY())));
}
return false;
|
public void | decreaseLength()Remove one cell length from the tail of this segment.
len--;
switch (dir) {
case Worm.LEFT:
x--;
break;
case Worm.RIGHT:
x++;
break;
case Worm.UP:
y--;
break;
case Worm.DOWN:
y++;
break;
}
|
public byte | getDirection()Get the direction this worm segment is pointing.
return dir;
|
public int | getEndX()Get the X coordinate of the cell that contains the tail of this
worm segment.
if (dir == Worm.LEFT)
return x-len;
if (dir == Worm.RIGHT)
return x+len;
return x;
|
public int | getEndY()Get the Y coordinate of the cell that contains the tail of this
worm segment.
if (dir == Worm.DOWN)
return y+len;
if (dir == Worm.UP)
return y-len;
return y;
|
public int | getLength()Get the length, in cells, of this segment.
return len+1;
|
public int | getX()Get the X coordinate of the cell that contains the head of this
worm segment.
return x;
|
public int | getY()Get the Y coordinate of the cell that contains the head of this
worm segment.
return y;
|
public void | increaseLength()Add one cell length to the head of this segment.
len++;
|
public java.lang.String | toString()Debug method.
String dirString;
switch (dir) {
case Worm.LEFT:
dirString = "Left";
break;
case Worm.RIGHT:
dirString = "Right";
break;
case Worm.UP:
dirString = "Up";
break;
case Worm.DOWN:
dirString = "Down";
break;
default:
dirString = "UNKNOWN -- " + dir;
}
return " pos == [" + x + "," + y + "]" +
" - [" + getEndX() + "," + getEndY() + "]" +
" len == " + getLength() +
" dir == " + dirString;
|