javaÖеÄ̰ʳÉßÀý³Ì
×î½üÒªÖØÐÂѧϰJava£¬ÕÒ¸öÀý×ÓÀ´Êµ¼ù£¬ÔÚÍøÉÏÕÒÁ˺ܶàÀý³ÌÀ´¿´£¬×Ô¼ºÖØбàдÁËÒ»¸ö̰ʳÉßµÄÀý×Ó£¬¼ÇÔÚÕâÀï¡£
1.SnakeModel.java
import java.util.Observable;
import java.util.LinkedList;
import java.util.Arrays;
import java.util.Random;
import javax.swing.*;
//ObservableÀàÒ»°ã´ú±íÊý¾Ý£¬ÊµÏÖ½Ó¿ÚRunnable±íÃ÷´´½¨Ò»¸ö½ø³Ì
public class SnakeModel extends Observable implements Runnable {
boolean[][] matrix; //ָʾλÖÃÉÏÊÇ·ñÓÐÉßÌå»òʳÎ
LinkedList nodeArray = new LinkedList(); //ÉßÌå
Node food;
int maxX; //XÖá±ßÏߣ¬¼´Îª»²¼ÖÐXÖá¸öÊý
int maxY; //yÖá±ßÏߣ¬¼´Îª»²¼ÖÐYÖá¸öÊý
int direction = UP; //ÉßÔËÐеķ½Ïò,³õʼΪÏòÉÏ£¨UP£©
boolean isRunning = false; //ÔËÐÐ״̬
int timeInterval = 200; //ʱ¼ä¼ä¸ô£¬ºÁÃ뼶
double speedChangeRate = 0.75; //ÿ´ÎµÄËٶȱ仯ÂÊ
boolean isPaused = false ;//ÔÝÍ£±êÖ¾
int score = 0; //µÃ·Ö
int countMove = 0; //³Ôµ½Ê³ÎïÇ°Òƶ¯µÄ´ÎÊý
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(int maxX, int maxY){
this.maxX = maxX;
this.maxY = maxY;
reset();
}
public void reset(){
direction = SnakeModel.UP;
timeInterval = 200;
isPaused = false;
score = 0;
countMove = 0;
//³õʼ»¯¾ØÕó
matrix = new boolean[maxX][];
for(int i = 0; i < maxX; ++i){
//¹ØÓÚÊý×éµÄн¨
matrix[i] = new boolean[maxY];
Arrays.fill(matrix[i],false);
}
//³õʼ»¯ÉßÌå
//³õʼÉßÌ峤¶È°´ÕÕºáÖáµÄ³¤¶È£¬ÈôºáÖá>20,ÔòÉßÌ峤¶ÈΪ10£¬·ñÔòΪºáÖáÒ»°ë
int initArrayLength = maxX > 20 ? 10 : maxX / 2;
nodeArray.clear();
for(int i = 0; i < initArrayLength; ++i){
int x = maxX / 2;
int y = maxY / 2;
nodeArray.addLast(new Node(x, y));
matrix[x][y] = true;
}
//´´½¨Ê³Îï
food = createFood();
matrix[food.x][food.y] = true;
}
public void changeDirection(int newDirection){
//¸Ä±ä·½Ïò²»ÄÜÓëÔ·½ÏòͬÏò»ò·´Ïò
if((direction & 1
Ïà¹ØÎĵµ£º
Á½¸ötomcat Java¶¨Ê±ÈÎÎñµÄÀý×Ó
ÀýÒ»£º
±¾ÀýÒÀ¾ÝJava×ÔÉíÌṩµÄ½Ó¿ÚʵÏÖ£¬Í¨¹ý¼àÌýÆ÷£¨Listener£©ºÍ¶¨Ê±Æ÷£¨Timer£©¶¨Ê±Ö´ÐÐij¸öÈÎÎñ£¨Task£©¡£
רҵµÄ¿ªÔ´¹¤¾ß¿É²Î¿¼Quartz£ºhttp://www.opensymphony.com/quartz/
MyListener£º
import
java.util.Timer;
import
javax.servlet.ServletContextEvent;
i ......
1.[http://www.javaalmanac.com] – Java¿ª·¢ÕßÄê¼øÒ»ÊéµÄÔÚÏß°æ±¾. ÒªÏë¿ìËٲ鵽ijÖÖJava¼¼ÇɵÄÓ÷¨¼°Ê¾Àý´úÂë, ÕâÊÇÒ»¸ö²»´íµÄÈ¥´¦.
2.[http://www.onjava.com] – O’ReillyµÄJavaÍøÕ¾. ÿÖܶ¼ÓÐÐÂÎÄÕÂ.
3.[http://java.sun.com] – ¹Ù·½µÄJava¿ª·¢ÕßÍøÕ¾ – ÿÖܶ¼ÓÐÐÂÎÄÕ·¢±í.
4.[http ......
ÓÐÁ½ÖÖ·½·¨£º
·½·¨Ò»£ºÓÃjava.util.DateÀàÀ´ÊµÏÖ£¬²¢½áºÏjava.text.DateFormatÀàÀ´ÊµÏÖʱ¼äµÄ¸ñʽ»¯£¬¿´ÏÂÃæ´úÂ룺
import java.util.*;
import java.text.*;
//ÒÔÏÂĬÈÏʱ¼äÈÕÆÚÏÔʾ·½Ê½¶¼ÊǺºÓïÓïÑÔ·½Ê½
//Ò»°ãÓïÑÔ¾ÍĬÈϺºÓï¾Í¿ÉÒÔÁË£¬Ê±¼äÈÕÆڵĸñʽĬÈÏΪMEDIUM·ç¸ñ£¬±ÈÈ磺2008-6-16 20:54:53
//ÒÔÏÂÏÔʾµÄÈ ......
<!--
/* Font Definitions */
@font-face
{font-family:SimSun;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:ËÎÌå;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@SimSun&qu ......
ÏÂÃæÕâƪÎÄÕÂÊÇ̨ÍåÖøÃûJavaÂÛ̳“Javaworld”µÄÒ»¸ö×ÊÉî°æÖ÷дµÄÒ»·â¶ÔJavaÐÂÊÖµÄÐÅ£¬Ï£ÍûС×é³ÉÔ±×Ðϸ¿´Ï Äã»áѧµ½ºÜ¶àµÄ¡¢¡¢¡¢¡¢
親愛µÄ java ÐÂÊÖ們 :
ºÜ¸ß興Äã們願Òâ來這裡¹²Í¬學習,
Java 這個語ÑÔ, ÒÑ ......