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

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

私信源码获取及调试交流

运行环境

Java≥8、MySQL≥5.7

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

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

功能说明

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


	@Override

	public int hashCode() {

		final int prime = 31;

		main.add(namer1, 0);

		// 游戏模式选项层

		final ImageIcon img1 = new ImageIcon(

				IndexWin.class

						.getResource("/plantvsplant/index/SelectorScreen_Adventure_highlight.png"));

		final ImageIcon img11 = new ImageIcon(

				IndexWin.class

						.getResource("/plantvsplant/index/SelectorScreen_StartAdventure_Highlight.png"));

		ImageIcon img2 = new ImageIcon(

				IndexWin.class

						.getResource("/plantvsplant/index/SelectorScreen_Vasebreaker_button.png"));

		ImageIcon img3 = new ImageIcon(

				IndexWin.class

						.getResource("/plantvsplant/index/SelectorScreen_Challenges_button.png"));

		final JLabel lbl1 = new JLabel(img1);


		indexwin=new IndexWin(this);

		

	}

	public void start(){

		SunAdd.stop=false;

		this.x=15;

		this.y=80;

		grid=new Grid(this.x,this.y);

		sunValue=50;

		win=Win.getWin(this);

		timer=new Timer(this);

		//grid.start();

		indexwin.setVisible(false);

		sunAutoProduceThread = new SunAutoProduceThread(this);

		moneyEnoughThread = new MoneyEnoughThread(this);

		win.toShow();

		putSunValue(0);

		timer.start();	

		sunAutoProduceThread.start();

		moneyEnoughThread.start();

		grid.getBoard()[1][0]="31111";

		grid.getBoard()[4][0]="31111";

		grid.getBoard()[7][0]="31111";

		grid.getBoard()[10][0]="31111";

		grid.getBoard()[13][0]="31111";

		final ImageIcon img11 = new ImageIcon(

				IndexWin.class

						.getResource("/plantvsplant/index/SelectorScreen_StartAdventure_Highlight.png"));

		ImageIcon img2 = new ImageIcon(

				IndexWin.class

						.getResource("/plantvsplant/index/SelectorScreen_Vasebreaker_button.png"));

		ImageIcon img3 = new ImageIcon(

				IndexWin.class

						.getResource("/plantvsplant/index/SelectorScreen_Challenges_button.png"));

		final JLabel lbl1 = new JLabel(img1);

		lbl1.addMouseListener(new MouseAdapter() {

			public void mouseClicked(MouseEvent e) {

				controller.start();

			}

			public void mouseEntered(MouseEvent e) {

				lbl1.setIcon(img11);

			}

			public void mouseExited(MouseEvent e) {

				lbl1.setIcon(img1);

			}

		});


	private SunAutoProduceThread sunAutoProduceThread;

	private Map<Integer, Plant> plantList=new HashMap<Integer, Plant>();

	private Map<Integer,CarThread> carList=new HashMap<Integer, CarThread>();

	private Map<String,CorpseMoveThread> corpseList=new HashMap<String, CorpseMoveThread>();

	private Map<Integer,ProduceBullet> produceBulletTimer=new HashMap<Integer,ProduceBullet>();

	public Controller(){

		indexwin=new IndexWin(this);

		

	}

	public void start(){

		SunAdd.stop=false;

		this.x=15;

		this.y=80;

		grid=new Grid(this.x,this.y);

		sunValue=50;

		win=Win.getWin(this);

		timer=new Timer(this);

		//grid.start();

		indexwin.setVisible(false);

		sunAutoProduceThread = new SunAutoProduceThread(this);

		moneyEnoughThread = new MoneyEnoughThread(this);

		win.toShow();

		putSunValue(0);

		timer.start();	

		sunAutoProduceThread.start();


	private SunAutoProduceThread sunAutoProduceThread;

	private Map<Integer, Plant> plantList=new HashMap<Integer, Plant>();

	private Map<Integer,CarThread> carList=new HashMap<Integer, CarThread>();

	private Map<String,CorpseMoveThread> corpseList=new HashMap<String, CorpseMoveThread>();

	private Map<Integer,ProduceBullet> produceBulletTimer=new HashMap<Integer,ProduceBullet>();

	public Controller(){

		indexwin=new IndexWin(this);

		

	}

	public void start(){

		SunAdd.stop=false;

		this.x=15;

		this.y=80;

		grid=new Grid(this.x,this.y);

		sunValue=50;

		win=Win.getWin(this);

		timer=new Timer(this);

		//grid.start();

		indexwin.setVisible(false);

		sunAutoProduceThread = new SunAutoProduceThread(this);

		moneyEnoughThread = new MoneyEnoughThread(this);

		win.toShow();

		putSunValue(0);

		timer.start();	

			for (int j = 0; j < boardlbl[i].length; j++) {

				board.add(boardlbl[i][j]);

			}

		}

		board.setBounds(40, 85,width-100,height-100);

		width=width-100;

		height=height-100;

		mainwin.add(board,JLayeredPane.DEFAULT_LAYER);

		//mainwin.add(board,JLayeredPane.PALETTE_LAYER);

		createCard();

		return mainwin;

	}

	private void createCard() {//卡片框

		ImageIcon cardboard=new ImageIcon(Win.class.getResource("/plantvsplant/card/cardboard.png"));

		JLabel cardboardl=new JLabel(cardboard);

		cardboardl.setBounds(0, 2, 650, 98);

		mainwin.add(cardboardl,JLayeredPane.MODAL_LAYER);

		ImageIcon pic0=new ImageIcon(IndexWin.class.getResource("/plantvsplant/card/2.jpg"));

		ImageIcon pic1=new ImageIcon(IndexWin.class.getResource("/plantvsplant/card/3.jpg"));

		ImageIcon pic2=new ImageIcon(IndexWin.class.getResource("/plantvsplant/card/1.jpg"));

		ImageIcon pic3=new ImageIcon(IndexWin.class.getResource("/plantvsplant/card/4.jpg"));

		ImageIcon pic4=new ImageIcon(IndexWin.class.getResource("/plantvsplant/card/6.jpg"));

		//阳光

		sunnum=new JLabel(Integer.toString(controller.getSunValue()));

		sunnum.setBounds(30, 60, 100, 50);

		this.x=15;

		this.y=80;

		grid=new Grid(this.x,this.y);

		sunValue=50;

		win=Win.getWin(this);

		timer=new Timer(this);

		//grid.start();

		indexwin.setVisible(false);

		sunAutoProduceThread = new SunAutoProduceThread(this);

		moneyEnoughThread = new MoneyEnoughThread(this);

		win.toShow();

		putSunValue(0);

		timer.start();	

		sunAutoProduceThread.start();

		moneyEnoughThread.start();

		grid.getBoard()[1][0]="31111";

		grid.getBoard()[4][0]="31111";

		grid.getBoard()[7][0]="31111";

		grid.getBoard()[10][0]="31111";

		grid.getBoard()[13][0]="31111";

		corpseNum=grid.getNum();

	public int getX() {

		return x;

	}

	public void setX(int x) {

		this.x = x;

	}

	public int getY() {

		return y;

	}

	public void setY(int y) {

		this.y = y;

	}

	@Override

	public String toString() {

		return "Cell [x=" + x + ", y=" + y + "]";

	}

	@Override

	public int hashCode() {

		final int prime = 31;

	}

//			boardlbl[i][j].setIcon(wood);

//		}

		for (int i = 0; i < boardlbl.length; i++) {

			for (int j = 0; j < boardlbl[i].length; j++) {

				board.add(boardlbl[i][j]);

			}

		}

		board.setBounds(40, 85,width-100,height-100);

		width=width-100;

		height=height-100;

		mainwin.add(board,JLayeredPane.DEFAULT_LAYER);

		//mainwin.add(board,JLayeredPane.PALETTE_LAYER);

		createCard();

		return mainwin;

	}

	private void createCard() {//卡片框


			}

			public void mouseExited(MouseEvent e) {

				lbl1.setIcon(img1);

			}

		});

		JLabel lbl2 = new JLabel(img2);

		JLabel lbl3 = new JLabel(img3);

		lbl1.setBounds(330, 50, img1.getIconWidth(), img1.getIconHeight());

		lbl2.setBounds(340, 150, img2.getIconWidth(), img2.getIconHeight());

		lbl3.setBounds(340, 250, img3.getIconWidth(), img3.getIconHeight());

		main.add(lbl1, 0);

		main.add(lbl2, 0);

		main.add(lbl3, 0);

		// 选项,帮助,退出

		final ImageIcon option1 = new ImageIcon(

				IndexWin.class

						.getResource("/plantvsplant/index/SelectorScreen_Options1.png"));

		final ImageIcon help1 = new ImageIcon(

				IndexWin.class

						.getResource("/plantvsplant/index/SelectorScreen_Help1.png"));

		final ImageIcon quit1 = new ImageIcon(

				IndexWin.class

		}

		if (y - 1 != -1

				&& !("01,02,03,04,05".contains(grid.getBoard()[x][y-1].substring(0, 2)))

				&& ("11,12,13,14,15".contains(grid.getBoard()[x][y].substring(0, 2)))) {

			grid.getBoard()[x][y-1] = grid.getBoard()[x][y ];

			grid.getBoard()[x][y] = "00111";

			return y-1;

		}

		if (y - 1 != -1

				&& ("01,02,03,04,05".contains(grid.getBoard()[x][y-1].substring(0, 2)))

				&& ("11,12,13,14,15".contains(grid.getBoard()[x][y ].substring(0, 2)))) {

			plantList.get(x * 100 + y-1).setHp(plantList.get(x * 100 + y-1).getHp() - 1);

			if (plantList.get(x * 100 + y-1).getHp() == 0) {

				grid.getBoard()[x][y-1] = "00111";

			}

			return y;

		}

		return -1;

	}

//			boardlbl[i][j].setIcon(wood);

//		}


	public void setY(int y) {

		this.y = y;

	}

	@Override

	public String toString() {

		return "Cell [x=" + x + ", y=" + y + "]";

	}

	@Override

	public int hashCode() {

		final int prime = 31;

		main.add(namer1, 0);

		// 游戏模式选项层

		final ImageIcon img1 = new ImageIcon(

				IndexWin.class

						.getResource("/plantvsplant/index/SelectorScreen_Adventure_highlight.png"));

		final ImageIcon img11 = new ImageIcon(

				IndexWin.class

						.getResource("/plantvsplant/index/SelectorScreen_StartAdventure_Highlight.png"));
		this.x = x;

	}

	public int getY() {

		return y;

	}

	public void setY(int y) {

		this.y = y;

	}

	@Override

	public String toString() {

		return "Cell [x=" + x + ", y=" + y + "]";

	}

	@Override

	public int hashCode() {

		final int prime = 31;


			public void mouseEntered(MouseEvent e) {

				lbl1.setIcon(img11);

			}

			public void mouseExited(MouseEvent e) {

				lbl1.setIcon(img1);

			}

		});

		JLabel lbl2 = new JLabel(img2);

		JLabel lbl3 = new JLabel(img3);

		lbl1.setBounds(330, 50, img1.getIconWidth(), img1.getIconHeight());

		lbl2.setBounds(340, 150, img2.getIconWidth(), img2.getIconHeight());

		lbl3.setBounds(340, 250, img3.getIconWidth(), img3.getIconHeight());

		main.add(lbl1, 0);

		main.add(lbl2, 0);

		main.add(lbl3, 0);

		// 选项,帮助,退出

		final ImageIcon option1 = new ImageIcon(

			b+=3;

			if(a<200)

				a+=2;

			sun.setBounds(a, b, 80, 80);

			if(b>=650)

			{

				sun.setVisible(false);

				break;

			}

		}

	}

}

public class Cell {

	private int x;

	private int y;

	public Cell() {

	}

	public Cell(int x, int y) {

		this.x=x;
		return -1;

	}

	public int moveCorpse(int x,int y){

		if (y==0&&("11,12,13,14,15".contains(grid.getBoard()[x][y].substring(0, 2)))) {

			fail();

			return -1;

		}

		if (y - 1 != -1

				&& !("01,02,03,04,05".contains(grid.getBoard()[x][y-1].substring(0, 2)))

				&& ("11,12,13,14,15".contains(grid.getBoard()[x][y].substring(0, 2)))) {

			grid.getBoard()[x][y-1] = grid.getBoard()[x][y ];

			grid.getBoard()[x][y] = "00111";

			return y-1;

		}

		if (y - 1 != -1

				&& ("01,02,03,04,05".contains(grid.getBoard()[x][y-1].substring(0, 2)))

				&& ("11,12,13,14,15".contains(grid.getBoard()[x][y ].substring(0, 2)))) {

			plantList.get(x * 100 + y-1).setHp(plantList.get(x * 100 + y-1).getHp() - 1);

			if (plantList.get(x * 100 + y-1).getHp() == 0) {

				grid.getBoard()[x][y-1] = "00111";

			}

			return y;

		}


			{

				sun.setVisible(false);

				break;

			}

		}

	}

}

public class Cell {

	private int x;

	private int y;

	public Cell() {

	}

	public Cell(int x, int y) {

		this.x=x;

		this.y=y;

	}

	public int getX() {

		return x;

请添加图片描述
请添加图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

java毕业

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

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

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

打赏作者

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

抵扣说明:

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

余额充值