/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ball;
import java.awt.Canvas;
public class Mball extends Canvas implements Runnable {
private int x = 100, y = 100;
private int vx = 20, vy = 20;
private int color = 1;
int flag = 1;
public Mdangban Md;
public Mball(Mdangban a) {
this.Md = a;
}
// public int score=Md.sc;
//run()函数
@Override
public void run() {
while (true) {
System.out.print("");
if (flag == 1) {
x = x + vx;
y = y + vy;
try {
Thread.sleep(150);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//判断小球和墙壁的位置
if (x > 370) {
vx = -vx;
}
if (x < 10) {
vx = -vx;
}
if (y < 0) {
vy = -vy;
}
if (y > 400) {
vy = -vy;
}
if (Md.getx() < x && y == 280 && Md.getx() + 50 > x) {
vy = -vy;
}
if (y > 300) {
vx = 0;
vy = 0;
}
Md.geta(x);
Md.getb(y);
//设置小球的颜色随位置改变
if (Md.geta(x) < 50) {
color = 1;
} else if (Md.geta(x) >= 50 && Md.geta(x) < 100) {
color = 2;
} else if (Md.geta(x) >= 100 && Md.geta(x) < 200) {
color = 3;
} else if (Md.geta(x) >= 200 && Md.geta(x) < 300) {
color = 4;
} else if (Md.geta(x) >= 300 && Md.geta(x) < 400) {
color = 5;
}
Md.getcolor(color);
Md.repaint();
}
}
}
//flag用来判断小球状态是暂停还是开始
public void getflag(int a) {
flag = a;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
java挡板小球游戏
共50个文件
html:29个
xml:4个
class:4个
需积分: 49 7 下载量 45 浏览量
2020-10-20
20:13:52
上传
评论
收藏 77KB ZIP 举报
温馨提示
用java实现挡板接小球的游戏,小球按照随机轨迹运动,可左右移动挡板来接着小球,小球接触挡板后反弹,接不住则游戏失败
资源详情
资源评论
资源推荐
收起资源包目录
Ball.zip (50个子文件)
Ball
src
ball
Mlistener.java 900B
Mball.java 2KB
Mframe.java 1KB
Mdangban.java 2KB
build
classes
.netbeans_automatic_build 0B
.netbeans_update_resources 0B
ball
Mball.class 2KB
Mdangban.class 2KB
Mlistener.class 1KB
Mframe.class 2KB
dist
javadoc
constant-values.html 4KB
deprecated-list.html 4KB
script.js 857B
overview-tree.html 5KB
package-list 6B
index-files
index-9.html 6KB
index-5.html 7KB
index-8.html 5KB
index-1.html 5KB
index-2.html 4KB
index-4.html 5KB
index-3.html 5KB
index-6.html 5KB
index-7.html 5KB
allclasses-noframe.html 900B
help-doc.html 8KB
index.html 3KB
ball
package-tree.html 5KB
package-frame.html 1KB
package-summary.html 5KB
class-use
Mframe.html 4KB
Mdangban.html 6KB
Mball.html 5KB
Mlistener.html 4KB
Mframe.html 10KB
Mdangban.html 19KB
Mball.html 16KB
package-use.html 4KB
Mlistener.html 13KB
allclasses-frame.html 980B
serialized-form.html 5KB
stylesheet.css 13KB
nbproject
genfiles.properties 475B
build-impl.xml 78KB
project.properties 2KB
project.xml 512B
private
private.properties 111B
private.xml 439B
build.xml 4KB
manifest.mf 85B
test
共 50 条
- 1
客长安
- 粉丝: 125
- 资源: 30
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0