【文章內(nèi)容簡(jiǎn)介】
0。 snakeModel = new SnakeModel(this,canvasWidth/nodeWidth,canvasHeight/nodeHeight)。 (new Thread(snakeModel)).start()。 } } public static void main(String[] args){ GreedSnake gs = new GreedSnake()。 } } class SnakeModel implements Runnable{ GreedSnake gs。 boolean[][] matrix。 LinkedList nodeArray = new LinkedList()。 Node food。 int maxX。 int maxY。 int direction = 2。 boolean running = false。 int timeInterval = 200。 double speedChangeRate = 。 boolean paused = false。 int score = 0。 int countMove = 0。 // UP and DOWN should be even // RIGHT and LEFT should be odd public static final int UP = 2。public static final int DOWN = 4。public static final int LEFT = 1。public static final int RIGHT = 3。public SnakeModel(GreedSnake gs, int maxX, int maxY){ = gs。 = maxX。 = maxY。 // initial matirx 沈 陽(yáng) 大 學(xué)課程設(shè)計(jì)說(shuō)明書 matrix = new boolean[maxX][]。 for(int i=0。 imaxX。 ++i){ matrix[i] = new boolean[maxY]。 (matrix[i],false)。 } // initial the snake int initArrayLength = maxX 20 ? 10 : maxX/2。 for(int i = 0。 i initArrayLength。 ++i){ int x = maxX/2+i。 int y = maxY/2。 (new Node(x, y))。 matrix[x][y] = true。 } food = createFood()。 matrix[][] = true。 } public void changeDirection(int newDirection){ if (direction % 2 != newDirection % 2){direction = newDirection。 } } public boolean moveOn(){ Node n = (Node)()。 int x = 。 int y = 。