import java.awt.*;
import javax.swing.*;
import java.awt.event.*; // needed for event handling
public class Snake {
final int SCREEN_SIZE_X = 20;
final int SCREEN_SIZE_Y = 20;
final int SNAKE_LENGTH = 10;
SnakeSection [] snakeSecs = new SnakeSection[SNAKE_LENGTH];
int headIndex = 0;
int dirX = 1;
int dirY = 0;
public Snake() {
for (int i=0; i<SNAKE_LENGTH; i++) {
snakeSecs[i]=new SnakeSection(10+i,10);
}
}
// The idea behind moving the snake is as follows.
// First, the "front" of the snake is the head position.
//
// The only really new part of the snake will be the
// SnakeSection in the head position.
// To obtain the new location of the head, just take the
// previous SnakeSection from the head position and add the
// current direction variables to its coordinates.
//
// Update the rest of the positions if needed.
//
public void move() {
/****** YOUR CODE HERE!!! ******/
}
public void paint(Graphics g) {
for (int i=0; i<SNAKE_LENGTH; i++) {
g.drawRect(snakeSecs[i].x*20,snakeSecs[i].y*20,20,20);
}
}
}
Please help me complete the move method
This post has been edited by pbl: 31 March 2009 - 05:01 PM

New Topic/Question
Reply




MultiQuote




|