Java项目:植物大战僵尸(java+swing)

源码获取:博客首页 "资源" 里下载!

功能简介:

植物大战僵尸、冒险模式、生存模式、解谜模式

 

 

小车服务类:

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;
//	}
//	
//}

 源码获取:博客首页 "资源" 里下载!

  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 16
    评论
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

OldWinePot

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值