public class Snake
extends java.lang.Object
SnakesGame
Constructor and Description |
---|
Snake(java.awt.Color c,
java.awt.Point sp,
int len,
int loc)
Construct a new snake with the given color and starting position.
|
Modifier and Type | Method and Description |
---|---|
int |
getScore()
Get the snake's score.
|
void |
move(SnakesGame game)
Move the snake one step.
|
boolean |
onPosition(java.awt.Point newPos)
Determine whether any part of the snake's body lies on the
given position.
|
void |
paint(java.awt.Graphics g)
Draw this snake on the given graphics pane and
draw its score in the appropriate location.
|
void |
setDirection(char d)
Set the direction of the head of the snake.
|
public Snake(java.awt.Color c, java.awt.Point sp, int len, int loc)
c
- this snake's colorsp
- this snake's starting position (a point on the grid)len
- the snake's length (number of body segments)loc
- the x coordinate of this snake's scorepublic void setDirection(char d)
d
- the direction (N, S, E, or W) or pause command (Z)public int getScore()
public void move(SnakesGame game)
game
- the current state of the snake gamepublic boolean onPosition(java.awt.Point newPos)
newPos
- the position to testpublic void paint(java.awt.Graphics g)
g
- the graphics pane on which to draw the snake