Ô´´úÂë--ÓÃJavaд"ÍÌʳÉß"

ʱ¼ä:2008-06-27 22:27:06  À´Ô´:  ×÷Õß:

¡¡¡¡g.setColor(Color.WHITE);
¡¡¡¡g.fillRect(0,0,canvasWidth,canvasHeight);
¡¡¡¡
¡¡¡¡// draw the snake
¡¡¡¡g.setColor(Color.BLACK);
¡¡¡¡LinkedList na = snakeModel.nodeArray;
¡¡¡¡Iterator it = na.iterator();
¡¡¡¡while(it.hasNext()){
¡¡¡¡Node n = (Node)it.next();
¡¡¡¡drawNode(g,n);
¡¡¡¡}
¡¡¡¡
¡¡¡¡// draw the food
¡¡¡¡g.setColor(Color.RED);
¡¡¡¡Node n = snakeModel.food;
¡¡¡¡drawNode(g,n);
¡¡¡¡
¡¡¡¡updateScore();
¡¡¡¡}
¡¡¡¡
¡¡¡¡private void drawNode(Graphics g, Node n){
¡¡¡¡g.fillRect(n.x*nodeWidth,
¡¡¡¡n.y*nodeHeight,
¡¡¡¡nodeWidth-1,
¡¡¡¡nodeHeight-1);
¡¡¡¡}
¡¡¡¡
¡¡¡¡public void updateScore(){
¡¡¡¡String s = "Score: " + snakeModel.score;
¡¡¡¡labelScore.setText(s);
¡¡¡¡}
¡¡¡¡
¡¡¡¡void begin(){
¡¡¡¡if (snakeModel == null !snakeModel.running){
¡¡¡¡snakeModel = new SnakeModel(this,
¡¡¡¡canvasWidth/nodeWidth,
¡¡¡¡canvasHeight/nodeHeight);
¡¡¡¡(new Thread(snakeModel)).start();
¡¡¡¡}
¡¡¡¡}
¡¡¡¡
¡¡¡¡public static void main(String[] args){
¡¡¡¡GreedSnake gs = new GreedSnake();
¡¡¡¡}
¡¡¡¡}
¡¡¡¡
¡¡¡¡///////////////////////////////////////////////////
¡¡¡¡// Îļþ2
Tags£º


ÉÏһƪ£ºÃ»ÓÐÁË   ÏÂһƪ£ºÃ»ÓÐÁË

ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0ÈË·¢±íÁËÆÀÂÛ ²é¿´ÍêÕûÄÚÈÝ

ÍÆ¼ö½Ì³Ì

×îн̳Ì