java弹球小游戏代码 java弹球小游戏实验报告( 五 )


if (bally = (y - ballsize)bally(y + brickH)
ballx = (x - ballsize)ballx(x + brickW)) {
showbrick[j * brickNumOfLine + i] = false;
if (ingame)
iScroe += (line - j);
if (ballx = (x - ballsize)
ballx = (x - ballsize + 3)) {
balldx = -xspeed;
} else if (ballx = (x + brickW - 1)
ballx = (x + brickW - 4)) {
balldx = xspeed;
}
balldy = -ydir;
}
}
}
}
}
public void run() {
long starttime;
Graphics g = getGraphics();
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
while (true) {
starttime = System.currentTimeMillis();
try {
paint(g);
starttime += 20;
Thread.sleep(Math
.max(0, starttime - System.currentTimeMillis()));
} catch (InterruptedException e) {
break;
}
}
}
public void start() {
if (mThread == null) {
mThread = new Thread(this);
mThread.start();
}
}
public void stop() {
if (mThread != null) {
mThread.stop();
mThread = null;
}
}
public static void main(String[] args) {
Frame frame = new Frame("弹球游戏");
ballApplet app = new ballApplet();
frame.add("Center", app);
frame.setSize(270, 350);
frame.validate();
frame.setVisible(true);
frame.addWindowListener(new WindowControl(app));
app.init();
app.start();
}
class BallGameKeyListener implements KeyListener{
@Override
public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();
// TODO Auto-generated method stub
if (ingame) {
switch(key){
case KeyEvent.VK_ESCAPE:
ingame = false;
break;
case KeyEvent.VK_RIGHT:
batdpos = 4;
break;
case KeyEvent.VK_LEFT:
batdpos = -4;
break;
}
} else {
if (key == KeyEvent.VK_S) {
ingame = true;
GameInit();
}
}
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
int key = e.getKeyCode();
if (key == KeyEvent.VK_LEFT || key == KeyEvent.VK_RIGHT)
batdpos = 0;
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
}
}
class WindowControl extends WindowAdapter {
Applet app;
public WindowControl(Applet app) {
this.app = app;
}
public void WindowClosing(WindowEvent e) {
app.stop();
app.destroy();
System.exit(0);
}
}
给你+了个keyListener 然后按你的理念给你加入了按键判定 。按S按键可以开始游戏但方向键不能移动应该是你的方法错误了你自己修改去把懒得看了 。。太长了 一般画可以移动的物体是直接按坐标来画然后移动的时候+= 好哦这-= 控制坐标我发现你的错误是你用batdpos这个变量去控制移动 。。但你根本没用这个变量去画图 。。所以不能移动 。。你自己去改把 。。
谁帮我一下修改一个简单的java程序?关于多线程的弹球程序 。主要问题:编译运行以后就是不能出现小球.此种情况不应该使用多线程,要是开发像雷电一样射击类的游戏,岂不是线程多如牛毛?
关于java弹球小游戏代码和java弹球小游戏实验报告的介绍到此就结束了 , 不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。

推荐阅读