基于java+swing的植物大战僵尸游戏(java+swing)

基于java+swing的植物大战僵尸游戏(java+swing)

功能简介:
植物大战僵尸、冒险模式、生存模式、解谜模式请添加图片描述
请添加图片描述
请添加图片描述

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

			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.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
车服务类:
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){
		while(true){
			if(stop){
				sun.setVisible(false);
				break;
			}
			try {
				sleep(200);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		sun.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent e) {
				sun.setVisible(false);
				controller.putSunValue(25);
			}
		});
		while(true){
			if(stop){
				sun.setVisible(false);
				break;
			}
		while(true){
			if(stop){
				sun.setVisible(false);
				break;
			}
			try {
				sleep(200);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			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 void setCar(JLabel car) {
		this.car = car;
	}
	
}
阳光收取服务类:
public class SunAdd extends Thread{
	Controller controller;
	private JLabel sun;
	private int a;
车服务类:
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);
	}
		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)
			}
			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 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)
			}
			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;
			}
			}
			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;
			if(a<200)
				a+=2;
			sun.setBounds(a, b, 80, 80);
			if(b>=650)
			{
				sun.setVisible(false);
				break;
			}
		}
	}
}
阳光花服务类:
public class SunflowerProduceThread extends Thread{
	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;
	}
}
		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 {
				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;
			}
		}
	}
}
阳光花服务类:
		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;
//	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) {
车服务类:
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.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)
		this.car = car;
	}
	
}
阳光收取服务类:
public class SunAdd extends Thread{
	Controller controller;
	private JLabel sun;
	private int a;
	private int b;
		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();
		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);
			}
//		return flag;
//	}
//	public void setFlag(boolean flag) {
车服务类:
public class CarThread extends Thread{
	private boolean flag=true;
	private int x;
	private  int y;
	private JLabel car;
	private Controller controller;
	}
	public void setStop(boolean stop) {
		this.stop = stop;
	}
}
//package plantvsplant;
//
//public class sunflowerProduceThread extends Thread{
//	private boolean flag=true;
//	private int x;
			}
			controller.showGame();
			controller.stopRnuCar(x);
		}
		if(!flag){
			car.setVisible(false);
		}
	}
	public boolean isFlag() {
		return flag;
	}
	public void setFlag(boolean flag) {
		this.flag = flag;
			}
			try {
				sleep(200);
			} catch (Exception e) {
				e.printStackTrace();
			}
			controller.showGame();
			controller.stopRnuCar(x);
		}
		if(!flag){
			car.setVisible(false);
		}
	}
	public boolean isFlag() {
		return flag;
				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() {

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于Java Swing的推箱子游戏设计与实现主要包括以下几个步骤: 1. 游戏界面设计:利用Swing提供的组件进行界面设计,包括游戏地图、箱子、目标点、人物等元素的图形化展示,并添加按钮以及文本框等交互组件。 2. 游戏逻辑设计:设计游戏规则和逻辑,包括人物移动、箱子推动、胜利判断等核心功能。通过监听按钮事件以及键盘事件来实现玩家的操作,并根据操作进行游戏状态的更新。 3. 地图设计与关卡:设计游戏地图以及关卡,可以通过二维数组或者读取外部文件的方式来表示地图。每个关卡的地图布局和目标点位置可以通过代码或者配置文件进行定义。 4. 碰撞检测与移动处理:在游戏中需要处理地图、箱子、目标点以及人物之间的碰撞关系,通过判断下一步的位置是否可行来确定是否进行移动操作,避免发生错误的移动。 5. 游戏状态管理:设计游戏的状态管理机制,包括游戏开始、暂停、重新开始、胜利、失败等状态的切换和更新。同时需要记录游戏的当前状态,并在界面上进行相应的显示和提示。 6. 游戏界面布局和美化:通过合理的布局和设计来提高游戏的美观度和可操作性,可以考虑添加音效、动画效果等来增加游戏的趣味性。 7. 优化和测试:在开发完成后进行测试,包括对游戏逻辑和界面的测试、异常处理的测试以及性能优化的测试,保证游戏的稳定性和流畅性。 通过以上步骤的设计和实现,基于Java Swing的推箱子游戏可以有效地展示出游戏的功能和特色,提供给用户一个良好的游戏体验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值