创建GameWin类
public class GameWin extends JFrame {
public void launch(){
this.setVisible(true);
this.setSize(500,500);
this.setLocationRelativeTo(null);
this.setTitle("黄金矿工");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
GameWin gameWin = new GameWin();
gameWin.launch();
}
}
先导入图片到项目中img文件夹中
创建Bg类
//背景类
public class Bg {
Image bg = Toolkit.getDefaultToolkit().getImage("img/bg.jpg");
Image bg1 = Toolkit.getDefaultToolkit().getImage("img/bg1.jpg");
Image peo = Toolkit.getDefaultToolkit().getImage("img/peo.png");
public void paintSelf(Graphics g){
g.drawImage(bg1,0,0,null);
g.drawImage(bg,0,200,null);
g.drawImage(peo,310,50,null);
}
}
在GameWin中绘制
Bg bg = new Bg();
@Override
public void paint(Graphics g) {
bg.paintSelf(g);
}
创建Line类
//红线类
public class Line {
//起点坐标
int x = 380,y=180;
//终点坐标
int endX = 500,endY = 500;
public void paintSelf(Graphics g){
g.setColor(Color.red);
g.drawLine(x,y,endX,endY);
}
}
在GameWin类中引用
Line line = new Line();
@Override
public void paint(Graphics g) {
bg.paintSelf(g);
line.paintSelf(g);
}
在Line类添加参数
//线长
double length = 100;
double n = 0;
//方向
int dir = 1;
public void paintSelf(Graphics g){
if(n < 0.1){
dir = 1;
}else if(n > 0.9){
dir = -1;
}
n = n + 0.005 * dir;
endX = (int) (x + length*Math.cos(n * Math.PI));
endY = (int) (y + length*Math.sin(n * Math.PI));
g.setColor(Color.red);
g.drawLine(x,y,endX,endY);
}
在GameWin类中launch方法添加死循环
public void launch(){
...
while (true){
repaint();
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
在Line类添加参数
//状态 0 左右摇摆 1 抓取 2 收回
int state;
public void paintSelf(Graphics g){
switch (state){
case 0:
if(n < 0.1){
dir = 1;
}else if(n > 0.9){
dir = -1;
}
n = n + 0.005 * dir;
lines(g);
break;
case 1:
if(length< 500){
length = length + 10;
lines(g);
}else { state = 2; }
break;
case 2:
if (length > 100) {
length = length - 10;
lines(g);
}else { state = 0; }
break;
default:
}
}
void lines(Graphics g){
endX = (int) (x + length*Math.cos(n * Math.PI));
endY = (int) (y + length*Math.sin(n * Math.PI));
g.setColor(Color.red);
g.drawLine(x,y,endX,endY);
}
在GameWin类中launch方法添加鼠标监听事件
public void launch(){
...
//鼠标监听事件
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
if(e.getButton() == 1){//鼠标左键点击
line.state = 1;
}
}
});
...
}
创建Object父类
//金矿、石头
public class Object {
//坐标
int x,y;
//宽高
int width,height;
//图片
Image img;
public void paintSelf(Graphics g){
g.drawImage(img,x,y,null);
}
}
创建Gold子类
//金矿类
public class Gold extends Object{
public Gold(){
this.x = 300;
this.y = 500;
this.width = 52;
this.height = 52;
this.img = Toolkit.getDefaultToolkit().getImage("img/gold1.gif");
}
}
在GameWin类引用
Gold gold = new Gold();
@Override
public void paint(Graphics g) {
bg.paintSelf(g);
line.paintSelf(g);
gold.paintSelf(g);
}
在GameWin类添加画布
Image offScreenImage;
@Override
public void paint(Graphics g) {
offScreenImage = this.createImage(768,1000);
Graphics graphics = offScreenImage.getGraphics();
bg.paintSelf(graphics);
line.paintSelf(graphics);
gold.paintSelf(graphics);
g.drawImage(offScreenImage,0,0,null);
}
在Line类添加判断
GameWin frame;
public Line(GameWin frame) {
this.frame = frame;
}
//碰撞检测,检测物体是否被抓取
void logic() {
if (endX > this.frame.gold.x && endX < this.frame.gold.x + this.frame.gold.width
&& endY > this.frame.gold.y && endY < this.frame.gold.y + this.frame.gold.height) {
System.out.println("11111111");
}
}
public void paintSelf(Graphics g) {
logic();
switch (state) {
....
在GameWin类修改Line对象
Line line = new Line(this);
在Line类添加判断
//状态 0 左右摇摆 1 抓取 2 收回 3 抓取返回
int state;
//碰撞检测,检测物体是否被抓取
void logic() {
if (endX > this.frame.gold.x && endX < this.frame.gold.x + this.frame.gold.width
&& endY > this.frame.gold.y && endY < this.frame.gold.y + this.frame.gold.height) {
state = 3;
}
}
public void paintSelf(Graphics g) {
logic();
switch (state) {
...
case 3:
if (length > 100) {
length = length - 10;
lines(g);
this.frame.gold.x = endX - 26;
this.frame.gold.y = endY;
} else {
this.frame.gold.x = -150;
this.frame.gold.y = -150;
state = 0;
}
break;
default:
}
}
在GameWin类添加集合
// Gold gold = new Gold();
//存储金块,石块
List<Object> objectList = new ArrayList<>();
{
for (int i = 0; i < 3; i++) {
objectList.add(new Gold());
}
}
@Override
public void paint(Graphics g) {
offScreenImage = this.createImage(768,1000);
Graphics graphics = offScreenImage.getGraphics();
bg.paintSelf(graphics);
line.paintSelf(graphics);
//gold.paintSelf(graphics);
for (Object obj : objectList) {
obj.paintSelf(graphics);
}
g.drawImage(offScreenImage,0,0,null);
}
在Line类修改
//碰撞检测,检测物体是否被抓取
void logic() {
for (Object gold : this.frame.objectList) {
if (endX > gold.x && endX < gold.x + gold.width
&& endY > gold.y && endY < gold.y + gold.height) {
state = 3;
}
}
}
public void paintSelf(Graphics g) {
logic();
switch (state) {
...
case 3:
if (length > 100) {
length = length - 10;
lines(g);
for (Object gold : this.frame.objectList) {
gold.x = endX - 26;
gold.y = endY;
if(length <= 100){
gold.x = -150;
gold.y = -150;
state = 0;
}
}
}
break;
default:
}
}
在Gold类修改
public Gold(){
this.x = (int)(Math.random()*700);
this.y = (int)(Math.random()*550 + 300);
...
}
在Object类添加参数
//标记是否可以移动 false 不可移动 true 可以移动
boolean flag = false;
在Gold类设置参数
public Gold(){
this.x = (int)(Math.random()*700);
this.y = (int)(Math.random()*550 + 300);
this.width = 52;
this.height = 52;
this.flag = false;
..
}
在Line类添加设置
//碰撞检测,检测物体是否被抓取
void logic() {
for (Object gold : this.frame.objectList) {
if (endX > gold.x && endX < gold.x + gold.width
&& endY > gold.y && endY < gold.y + gold.height) {
state = 3;
gold.flag = true;
}
}
}
public void paintSelf(Graphics g) {
logic();
switch (state) {
...
case 3:
if (length > 100) {
length = length - 10;
lines(g);
for (Object gold : this.frame.objectList) {
if(gold.flag){
gold.x = endX - 26;
gold.y = endY;
if(length <= 100){
gold.x = -150;
gold.y = -150;
gold.flag = false;
state = 0;
}
}
}
}
break;
default:
}
}
创建Rock类
//石块类
public class Rock extends Object{
public Rock(){
this.x = (int)(Math.random()*700);
this.y = (int)(Math.random()*550 + 300);
this.width = 71;
this.height = 71;
this.flag = false;
this.img = Toolkit.getDefaultToolkit().getImage("img/rock1.png");
}
}
在GameWin类中创建
{
for (int i = 0; i < 3; i++) {
objectList.add(new Gold());
}
for (int i = 0; i < 3; i++) {
objectList.add(new Rock());
}
}
在Object类添加方法
public int getWidth() {
return width;
}
在Line类中调用
public void paintSelf(Graphics g) {
logic();
switch (state) {
...
case 3:
if (length > 100) {
length = length - 10;
lines(g);
for (Object gold : this.frame.objectList) {
if(gold.flag){
gold.x = endX - gold.getWidth()/2;
gold.y = endY;
if(length <= 100){
gold.x = -150;
gold.y = -150;
gold.flag = false;
state = 0;
}
}
}
}
break;
default:
}
}
在Object类添加参数
//质量
int m;
在Gold类设值
public Gold(){
this.m = 80;
...
}
在Rock类设值
public Rock(){
this.m = 150;
...
}
在Linel类修改判断
public void paintSelf(Graphics g) {
logic();
switch (state) {
case 0:
if (n < 0.1) {
dir = 1;
} else if (n > 0.9) {
dir = -1;
}
n = n + 0.005 * dir;
lines(g);
break;
case 1:
if (length < 500) {
length = length + 5;
lines(g);
} else {
state = 2;
}
break;
case 2:
if (length > 100) {
length = length - 5;
lines(g);
} else {
state = 0;
}
break;
case 3:
int m = 1;
if (length > 100) {
length = length - 10;
lines(g);
for (Object gold : this.frame.objectList) {
if(gold.flag){
m = gold.m;
gold.x = endX - gold.getWidth()/2;
gold.y = endY;
if(length <= 100){
gold.x = -150;
gold.y = -150;
gold.flag = false;
state = 0;
}
}
}
}
try {
Thread.sleep(m);
} catch (InterruptedException e) {
e.printStackTrace();
}
break;
default:
}
}
在Gold类创建GoldMini外部类和GoldPlus外部类
public class Gold extends Object{
...
}
class GoldMini extends Gold{
public GoldMini(){
this.width = 36;
this.height = 36;
this.flag = false;
this.m = 30;
this.img = Toolkit.getDefaultToolkit().getImage("img/gold0.gif");
}
}
class GoldPlus extends Gold{
public GoldPlus(){
this.x = (int)(Math.random()*650);
this.width = 105;
this.height = 105;
this.flag = false;
this.m = 120;
this.img = Toolkit.getDefaultToolkit().getImage("img/gold2.gif");
}
}
在GameWin类随机生成多种金块
{
for (int i = 0; i < 11; i++) {
double random = Math.random();
if (random <0.3 ) {
objectList.add(new GoldMini());
}else if(random < 0.7 ){
objectList.add(new Gold());
} else {
objectList.add(new GoldPlus());
}
}
for (int i = 0; i < 3; i++) {
objectList.add(new Rock());
}
}
在Objectl类添加方法
//获取矩形,用于检测判断物体重叠
public Rectangle getRec(){
return new Rectangle(x,y,width,height);
}
在GameWin类修改生成金块代码
{
//是否可以放置
boolean ifPlace = true;
for (int i = 0; i < 11; i++) {
double random = Math.random();
Gold gold;//存放当前生成的金块
if (random <0.3 ) {
gold = new GoldMini();
}else if(random < 0.7 ){
gold = new Gold();
} else {
gold = new GoldPlus();
}
for (Object obj : objectList) {
if(gold.getRec().intersects(obj.getRec())){
//不能放置,需要重新生成
ifPlace = false;
}
}
if(ifPlace){
objectList.add(gold);
}else { ifPlace = true; i--; }
}
for (int i = 0; i < 5; i++) {
Rock rock = new Rock();
for (Object obj : objectList) {
if(rock.getRec().intersects(obj.getRec())){
//不能放置,需要重新生成
ifPlace = false;
}
}
if(ifPlace){
objectList.add(rock);
}else { ifPlace = true; i--; }
}
}
在Line类中修改
//线长最小值
double min_length = 100;
//线长最小值
double max_length = 750;
public void paintSelf(Graphics g) {
logic();
switch (state) {
case 0:
if (n < 0.1) {
dir = 1;
} else if (n > 0.9) {
dir = -1;
}
n = n + 0.005 * dir;
lines(g);
break;
case 1:
if (length < max_length) {
length = length + 5;
lines(g);
} else {
state = 2;
}
break;
case 2:
if (length > min_length) {
length = length - 5;
lines(g);
} else {
state = 0;
}
break;
case 3:
int m = 1;
if (length > min_length) {
length = length - 10;
lines(g);
for (Object gold : this.frame.objectList) {
if(gold.flag){
m = gold.m;
gold.x = endX - gold.getWidth()/2;
gold.y = endY;
if(length <= min_length){
gold.x = -150;
gold.y = -150;
gold.flag = false;
state = 0;
}
}
}
}
...
break;
default:
}
}
//绘制方法
void lines(Graphics g) {
endX = (int) (x + length * Math.cos(n * Math.PI));
endY = (int) (y + length * Math.sin(n * Math.PI));
g.setColor(Color.red);
g.drawLine(x-1, y, endX-1, endY);
g.drawLine(x, y, endX, endY);
g.drawLine(x+1, y, endX+1, endY);
g.drawImage(hook,endX-36,endY-2,null);
}
在Object类添加参数
//积分
int count;
在Gold类设值
public Gold(){
this.count = 4;
...
public GoldMini(){
this.count = 2;
...
public GoldPlus(){
this.count = 8;
在Rock类设值
public Rock(){
this.count = 1;
...
在Line类加分
public void paintSelf(Graphics g) {
logic();
switch (state) {
...
case 3:
int m = 1;
if (length > min_length) {
length = length - 10;
lines(g);
for (Object gold : this.frame.objectList) {
if(gold.flag){
m = gold.m;
gold.x = endX - gold.getWidth()/2;
gold.y = endY;
if(length <= min_length){
gold.x = -150;
gold.y = -150;
gold.flag = false;
state = 0;
//加分
Bg.count+=gold.count;
}
}
}
}
...
在Bg类绘制
//总分
static int count = 0;
//绘制
public void paintSelf(Graphics g){
g.drawImage(bg1,0,0,null);
g.drawImage(bg,0,200,null);
g.drawImage(peo,310,50,null);
drawWord(g,30,Color.black,"积分:" + count,30,150);
}
//绘制字符串
public static void drawWord(Graphics g,int size,Color color,String str,int x,int y){
g.setColor(color);
g.setFont(new Font("仿宋", Font.BOLD,size));
g.drawString(str,x,y);
}
在Bg类添加参数
//药水图片
Image water = Toolkit.getDefaultToolkit().getImage("img/water.png");
//药水数量
static int waterNmu = 3;
//药水状态 默认false 正在使用true
static boolean waterFlag = false;
//绘制
public void paintSelf(Graphics g){
g.drawImage(bg1,0,0,null);
g.drawImage(bg,0,200,null);
g.drawImage(peo,310,50,null);
drawWord(g,30,Color.black,"积分:" + count,30,150);
//药水组件
g.drawImage(water,450,40,null);
drawWord(g,30,Color.black,"*" + waterNmu,510,70);
}
在Object添加参数
//类型 1金块 2石块
int type;
在Gold类设值
public Gold(){
this.type = 1;
...
在Rock类设值
public Rock(){
this.type = 1;
...
在GameWin添加鼠标点击判断
public void launch(){
...
//鼠标监听事件
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
//左右摇摆,点击左键
if(e.getButton() == 1 && line.state == 0){//鼠标左键点击
line.state = 1;
}
//抓取返回,点击右键
if(e.getButton() == 3 && line.state == 3){//鼠标右键点击
if(Bg.waterNmu > 0){
Bg.waterFlag = true;
Bg.waterNmu--;
}
}
}
});
在Line类添加修改判断
public void paintSelf(Graphics g) {
logic();
switch (state) {
...
case 3:
int m = 1;
if (length > min_length) {
length = length - 10;
lines(g);
for (Object gold : this.frame.objectList) {
if(gold.flag){
m = gold.m;
gold.x = endX - gold.getWidth()/2;
gold.y = endY;
if(length <= min_length){
gold.x = -150;
gold.y = -150;
gold.flag = false;
state = 0;
//加分
Bg.count+=gold.count;
Bg.waterFlag= false;
}
if(Bg.waterFlag){
if(gold.type == 1){
m=1;
}
if(gold.type == 2){
gold.x = -150;
gold.y = -150;
gold.flag = false;
Bg.waterFlag= false;
state = 2;
}
}
}
}
}
在Bg类添加参数
//关卡数
static int level = 1;
//目标得分
int goal = level * 15;
//绘制
public void paintSelf(Graphics g){
...
//关卡数
drawWord(g,20,Color.black,"第" + level + "关",30,60);
//目标积分
drawWord(g,30,Color.black,"目标:" + goal,30,110);
}
在GameWin类添加判断
public void launch(){
...
while (true){
repaint();
nextLevel();
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
//下一关
public void nextLevel(){
if (Bg.count >= bg.goal) {
Bg.level++;
dispose();
GameWin gameWin1 = new GameWin();
gameWin1.launch();
}
}
在GameWin类添加状态
//0 未开始 1 运行中 2 商店 3 失败 4 胜利
static int state;
public void launch(){
...
//鼠标监听事件
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
switch (state){
case 0:
if(e.getButton() == 3){
state = 1;
}
break;
case 1:
//左右摇摆,点击左键
if(e.getButton() == 1 && line.state == 0){//鼠标左键点击
line.state = 1;
}
//抓取返回,点击右键
if(e.getButton() == 3 && line.state == 3){//鼠标右键点击
if(Bg.waterNmu > 0){
Bg.waterFlag = true;
Bg.waterNmu--;
}
}
break;
case 2:
break;
case 3:
break;
case 4:
break;
default:
}
}
});
...
}
@Override
public void paint(Graphics g) {
offScreenImage = this.createImage(768,1000);
Graphics graphics = offScreenImage.getGraphics();
bg.paintSelf(graphics);
if(state == 1){
//绘制物体
for (Object obj : objectList) {
obj.paintSelf(graphics);
}
line.paintSelf(graphics);
}
g.drawImage(offScreenImage,0,0,null);
}
//下一关
public void nextLevel(){
if (state == 1) {
if (Bg.count >= bg.goal) {
Bg.level++;
dispose();
GameWin gameWin1 = new GameWin();
gameWin1.launch();
}
}
}
在Bg类添加判断绘制
//绘制
public void paintSelf(Graphics g){
g.drawImage(bg1,0,0,null);
g.drawImage(bg,0,200,null);
switch (GameWin.state){
case 0:
drawWord(g,80,Color.green,"准备开始",200,400);
break;
case 1:
g.drawImage(peo,310,50,null);
drawWord(g,30,Color.black,"积分:" + count,30,150);
//药水组件
g.drawImage(water,450,40,null);
drawWord(g,30,Color.black,"*" + waterNmu,510,70);
//关卡数
drawWord(g,20,Color.black,"第" + level + "关",30,60);
//目标积分
drawWord(g,30,Color.black,"目标:" + goal,30,110);
break;
case 2:
break;
case 3:
break;
case 4:
break;
default:
}
}
在Bg类添加参数
//开始时间
long startTime;
//结束时间
long endTime;
//绘制
public void paintSelf(Graphics g){
g.drawImage(bg1,0,0,null);
g.drawImage(bg,0,200,null);
switch (GameWin.state){
case 0:
drawWord(g,80,Color.green,"准备开始",200,400);
break;
case 1:
g.drawImage(peo,310,50,null);
drawWord(g,30,Color.black,"积分:" + count,30,150);
//药水组件
g.drawImage(water,450,40,null);
drawWord(g,30,Color.black,"*" + waterNmu,510,70);
//关卡数
drawWord(g,20,Color.black,"第" + level + "关",30,60);
//目标积分
drawWord(g,30,Color.black,"目标:" + goal,30,110);
//时间组件
endTime = System.currentTimeMillis();
long time = 20 - (endTime - startTime)/1000;
drawWord(g,30,Color.black,"时间:" + (time > 0 ? time : 0) ,520,150);
break;
case 2:
...
}
在GameWin类初始值
public void launch(){
...
//鼠标监听事件
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
switch (state){
case 0:
if(e.getButton() == 3){
state = 1;
bg.startTime = System.currentTimeMillis();
}
break;
...
}
在Bg添加方法
//绘制
public void paintSelf(Graphics g){
g.drawImage(bg1,0,0,null);
g.drawImage(bg,0,200,null);
switch (GameWin.state){
...
case 3:
drawWord(g,80,Color.cyan,"失败",250,350);
drawWord(g,80,Color.cyan,"目标:" + count,200,450);
break;
case 4:
break;
default:
}
}
//true倒计时完成 false正在倒计时
public boolean gameTime(){
long time = (endTime - startTime)/1000;
if(time > 20){
return true;
}
return false;
}
在GameWin添加判断
//下一关
public void nextLevel(){
if (state == 1 && bg.gameTime()) {
if (Bg.count >= bg.goal) {
Bg.level++;
dispose();
GameWin gameWin1 = new GameWin();
gameWin1.launch();
}else {
state = 3;
}
}
}
在GameWin类添加
//下一关
public void nextLevel() {
if (state == 1 && bg.gameTime()) {
if (Bg.count >= bg.goal) {
if (Bg.level == 5) {
state = 4;
} else {
Bg.level++;
}
dispose();
GameWin gameWin1 = new GameWin();
gameWin1.launch();
} else {
state = 3;
}
}
}
在Bg类绘制
//绘制
public void paintSelf(Graphics g){
g.drawImage(bg1,0,0,null);
g.drawImage(bg,0,200,null);
switch (GameWin.state){
..
case 4:
drawWord(g,80,Color.red,"成功",250,350);
drawWord(g,80,Color.red,"目标:" + count,200,450);
break;
default:
}
}
在Bg类添加方法
//重置元素
void reGame(){
level = 1;
goal = level *15;
count = 0;
waterNmu = 3;
waterFlag = false;
}
在Line类添加方法
//重置线元素
void reGame() {
n =0;
length = 100;
}
在GameWin类添加判断
public void launch() {
...
//鼠标监听事件
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
switch (state) {
case 0:
if (e.getButton() == 3) {
state = 1;
bg.startTime = System.currentTimeMillis();
}
break;
case 1:
//左右摇摆,点击左键
if (e.getButton() == 1 && line.state == 0) {//鼠标左键点击
line.state = 1;
}
//抓取返回,点击右键
if (e.getButton() == 3 && line.state == 3) {//鼠标右键点击
if (Bg.waterNmu > 0) {
Bg.waterFlag = true;
Bg.waterNmu--;
}
}
break;
case 2:
break;
case 3:
case 4:
if(e.getButton() == 1){
state = 0;
bg.reGame();
line.reGame();
}
break;
default:
}
}
});
...
}
//下一关
public void nextLevel() {
if (state == 1 && bg.gameTime()) {
if (Bg.count >= bg.goal) {
if (Bg.level == 5) {
state = 4;
} else {
Bg.level++;
bg.startTime = System.currentTimeMillis();
}
} else {
state = 3;
}
dispose();
GameWin gameWin1 = new GameWin();
gameWin1.launch();
}
}
在Bg类添加绘制
//药水价格
int price = (int)(Math.random()*10);
//是否进入商店 false 不购买
boolean shop = false;
//绘制
public void paintSelf(Graphics g){
g.drawImage(bg1,0,0,null);
g.drawImage(bg,0,200,null);
switch (GameWin.state){
。。。
case 2:
g.drawImage(water,300,400,null);
drawWord(g,30,Color.black,"价格:" + price,300,500);
drawWord(g,30,Color.black,"是否购买?",300,550);
if(shop){
count = count - price;
waterNmu++;
shop = false;
GameWin.state = 1;
startTime = System.currentTimeMillis();
}
break;
case 3:
...
}
在GameWin类修改
public void launch() {
...
//鼠标监听事件
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
switch (state) {
..
case 2:
if(e.getButton() == 1){
bg.shop = true;
}
if(e.getButton() == 3){
state =1;
bg.startTime = System.currentTimeMillis();
}
break;
case 3:
case 4:
if(e.getButton() == 1){
state = 0;
bg.reGame();
line.reGame();
}
break;
default:
}
}
});
...
}
//下一关
public void nextLevel() {
if (state == 1 && bg.gameTime()) {
if (Bg.count >= bg.goal) {
if (Bg.level == 5) {
state = 4;
} else {
state =2;
Bg.level++;
}
} else {
state = 3;
}
dispose();
GameWin gameWin1 = new GameWin();
gameWin1.launch();
}
}