|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectCaterpillar
Caterpillar class. Represents the caterpillar and barriers in the grid where the caterpillar is moving.
Field Summary | |
static int |
TO_DOWN
Constant representing caterpillar moving direction downwards. |
static int |
TO_LEFT
Constant representing caterpillar moving direction from right to left. |
static int |
TO_RIGHT
Constant representing caterpillar moving direction from left to right. |
static int |
TO_UP
Constant representing caterpillar moving direction upwards. |
Constructor Summary | |
Caterpillar(int width,
int height,
int positionX,
int positionY,
java.awt.Color backgroundColor,
Grid grid,
int numberOfBarriers,
java.awt.Graphics g)
Creates a new instance of Caterpillar |
Method Summary | |
void |
Delete(java.awt.Graphics g)
Call this method to remove caterpillar from grid correctly. |
boolean |
IsCorrectHeadPosition()
Tests if caterpillar's head is on a barrier or not in a grid (incorrect position) or is somewhere else in a grid (correct position). |
void |
Move(java.awt.Graphics g)
Moves caterpillar's body one cell in direction that has been set by force of SetMoveDirection(int) . |
void |
paint(java.awt.Graphics g)
Repaints whole caterpillar and all barriers. |
void |
SetMoveDirection(int direction)
Sets future moving direction of caterpillar. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int TO_RIGHT
public static final int TO_LEFT
public static final int TO_DOWN
public static final int TO_UP
Constructor Detail |
public Caterpillar(int width, int height, int positionX, int positionY, java.awt.Color backgroundColor, Grid grid, int numberOfBarriers, java.awt.Graphics g)
width
- Width of grid where caterpillar can move. (Number of cells.)height
- Height of grid where caterpillar can move. (Number of cells.)positionX
- x-coordinate in pixels of upper-left corner of a grid.positionY
- y-coordinate in pixels of upper-left corner of a grid.backgroundColor
- Background color of a form.grid
- Refererence to Grid object instance where caterpillar is moving.numberOfBarriers
- Number of barriers that will be created in a grid.g
- Graphics object that is used to paint caterpillar and barriers.Method Detail |
public void paint(java.awt.Graphics g)
g
- Graphics object that is used to painting.public void Move(java.awt.Graphics g)
SetMoveDirection(int)
. If this movement causes that head is on a
barrier or not in a grid, head isn't painted.
If is not correct head position, Move(Graphics)
does nothing.
g
- Graphics object that is used to repaint caterpillar's positionpublic boolean IsCorrectHeadPosition()
public void Delete(java.awt.Graphics g)
g
- Graphics object used to painting.public void SetMoveDirection(int direction)
direction
- Direction. Use constants provided by this class (TO_RIGHT etc.)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |