Java项目:植物大战僵尸(java+swing)
源码获取:博客首页 "资源" 里下载!功能简介:植物大战僵尸、冒险模式、生存模式、解谜模式小车服务类:public class CarThread extends Thread{private boolean flag=true;private int x;privateint y;private JLabel car;private Controller controller;public Ca
·
源码获取:博客首页 "资源" 里下载!
功能简介:
植物大战僵尸、冒险模式、生存模式、解谜模式
小车服务类:
public class CarThread extends Thread{
private boolean flag=true;
private int x;
private int y;
private JLabel car;
private Controller controller;
public CarThread(Controller controller,int x,int y){
this.x=x;
this.y=y;
this.controller=controller;
controller.getWin().putBomp(x, y, 1);
car=controller.getWin().getCarMap().get(100*x+y);
}
public void run() {
while(flag){
car.setVisible(false);
int aa=controller.runCar(x,y);
if(aa!=-1){
car.setVisible(false);
controller.getWin().putBomp(x, aa, 1);
car=controller.getWin().getCarMap().get(100*x+aa);
controller.getWin().getCarMap().remove(100*x+y);
y=aa;
}
else{
flag=false;
}
try {
sleep(200);
} catch (Exception e) {
e.printStackTrace();
}
controller.showGame();
controller.stopRnuCar(x);
}
if(!flag){
car.setVisible(false);
}
}
public boolean isFlag() {
return flag;
}
public void setFlag(boolean flag) {
this.flag = flag;
}
public JLabel getCar() {
return car;
}
public void setCar(JLabel car) {
this.car = car;
}
}
阳光收取服务类:
public class SunAdd extends Thread{
Controller controller;
private JLabel sun;
private int a;
private int b;
public static boolean stop=false;
public SunAdd(int x,int y,Controller controller,JLabel sun){
this.controller=controller;
this.a=x;
this.b=y;
this.sun=sun;
}
public void run(){
sun.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e) {
sun.setVisible(false);
controller.putSunValue(25);
}
});
while(true){
if(stop){
sun.setVisible(false);
break;
}
try {
sleep(200);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
b+=3;
if(a<200)
a+=2;
sun.setBounds(a, b, 80, 80);
if(b>=650)
{
sun.setVisible(false);
break;
}
}
}
}
阳光花服务类:
public class SunflowerProduceThread extends Thread{
private boolean stop=false;
private int x;
private int y;
private Controller controller;
public SunflowerProduceThread(int x,int y,Controller controller){
this.controller=controller;
this.x=80+32*(y-1);
this.y=60 +40*(x-1);
}
public void run() {
while(true){
try {
sleep(10000);
} catch (Exception e) {
e.printStackTrace();
}
if(stop){
break;
}
controller.putSun(x, y);
}
}
public void setStop(boolean stop) {
this.stop = stop;
}
}
//package plantvsplant;
//
//public class sunflowerProduceThread extends Thread{
// private boolean flag=true;
// private int x;
// private Controller controller;
// public sunflowerProduceThread(int x,Controller controller){
// this.controller=controller;
// this.x=x;
// }
// public void run() {
// while(flag){
// try {
// sleep(2000);
// controller.produceSun(x);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// }
// public boolean isFlag() {
// return flag;
// }
// public void setFlag(boolean flag) {
// this.flag = flag;
// }
//
//}
源码获取:博客首页 "资源" 里下载!
更多推荐
已为社区贡献15条内容
所有评论(0)