资源简介
java台球源代码,国外作品,容易理解,有兴趣的下载,改进。
代码片段和文件信息
public class Billard4K extends JPanel implements Runnable MouseListener MouseMotionListener {
// GAME STATES
public final int WAITING_TO_START = 0;
public final int WAITING_TO_HIT = 1;
public final int MOVING = 2;
public final int FINISHING = 3;
public int state = 0;
// TABLE
double hR;
double[] tableX;
double[] tableY;
double[] holesX;
double[] holesY;
// BALLS
public int nballs;
public int nBallsOn;
double[] x;
double[] y;
double[] vx;
double[] vy;
double[] nextX;
double[] nextY;
double[] nextVx;
double[] nextVy;
boolean[] borderCollision;
boolean[][] collision;
boolean[] onTable;
double r = 10;
// RENDERING
Image backBuffer;
Image backGround;
// MOUSE
int mX;
int mY;
int mXPost;
int mYPost;
boolean clicked;
// STICK
public final int MAX_STRENGTH = 1000;
int sL = 300;
int actualStep = 0;
public Billard4K() {
super();
this.setBounds(50 50 700 350);
//this.setResizable(false);
//this.setUndecorated(true);
//this.setVisible(true);
Jframe f = new Jframe(“Billard4K“);
f.add(this);
f.setBounds(0 0 700 380);
f.setResizable(false);
f.setVisible(true);
f.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
this.requestFocus();
init();
}
public void init() {
initTable();
initBalls();
backBuffer = this.createImage(this.getWidth() this.getHeight());
//gBackBuffer = backBuffer.getGraphics();
//gBackBuffer.setFont(new Font(“Courier“ Font.BOLD 20));
createBackGround();
this.addMouseListener(this);
this.addMouseMotionListener(this);
start();
}
public void initTable() {
hR = 16;
tableX = new double[] {
40
this.getWidth()-40
};
tableY = new double[] {
tableX[0]
this.getHeight()-tableX[0]
};
holesX = new double[] {
tableX[0] + 20
this.getWidth()/2
tableX[1]-20
};
holesY = new double[] {
tableY[0] + 20
this.tableY[1]-20
};
}
public void initBalls() {
nballs = 16;
x = new double[nballs];
y = new double[nballs];
vx = new double[nballs];
vy = new double[nballs];
nextX = new double[nballs];
nextY = new double[nballs];
nextVx = new double[nballs];
nextVy = new double[nballs];
borderCollision = new boolean[nballs];
collision = new boolean[nballs][nballs];
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 302 2009-08-13 16:47 deskball\.classpath
文件 384 2009-08-13 16:47 deskball\.project
文件 629 2009-08-13 16:47 deskball\.settings\org.eclipse.jdt.core.prefs
文件 11873 2009-08-13 17:33 deskball\bin\Billard4K.class
文件 19218 2009-09-08 14:59 deskball\src\Billard4K.java
目录 0 2009-09-08 14:59 deskball\.settings
目录 0 2009-09-08 14:59 deskball\bin
目录 0 2009-09-08 14:59 deskball\src
目录 0 2009-09-08 14:59 deskball
----------- --------- ---------- ----- ----
32406 9
评论
共有 条评论