⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wall.java

📁 基于尚学堂坦克大战的基础上开发,支持多人对战,在线聊天,坦克大战网络版.
💻 JAVA
字号:
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.util.HashMap;

public class Wall {

	public int x, y;

	private int width = 43, height = 43;

	private static Toolkit tk = Toolkit.getDefaultToolkit();

	Image youtong,tie;
	
	int style=0;
	
	int step=0;  
	
	int life=12;

	private TankClient tc;
	
	private Image[] zhuangkuai;
	private HashMap<String,Image> wallImgs = new HashMap<String,Image>();

	{
		zhuangkuai = new Image[]{
				tk.getImage(Explode.class.getClassLoader().getResource(
				"images/wall0.png")),
				tk.getImage(Explode.class.getClassLoader().getResource(
				"images/wall1.png")),
				tk.getImage(Explode.class.getClassLoader().getResource(
				"images/wall2.png")),
				tk.getImage(Explode.class.getClassLoader().getResource(
				"images/wall3.png"))
		};
		
		tie = tk.getImage(Explode.class.getClassLoader().getResource(
		"images/tie.gif"));
		
		youtong = tk.getImage(Explode.class.getClassLoader().getResource(
		"images/youtong.png"));
	}

	public Wall(int x, int y) {
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
	}

	public Wall(int x, int y,int style, TankClient tc) {
		this(x, y);
		this.style=style;
		this.tc = tc;
	}

	public void draw(Graphics g) {
		Color c = g.getColor();
		switch (style){
		case 0:
		g.drawImage(zhuangkuai[step], x, y, null);
		break;
		case 1:
		g.drawImage(tie,x,y,null);
		break;
		case 2:
		g.drawImage(youtong,x,y,null);
		}
	}

	public Rectangle getRect() {
		return new Rectangle(x, y, width - 10, height - 10);
	}

	public boolean isHitTanks() {
		boolean hit = false;
		for (int i = 0; i < tc.badTanks.size(); i++) {
			if (((Tank) tc.badTanks.get(i)).getRect()
					.intersects(this.getRect())) {
				hit = true;
				break;
			}
		}
		if (!hit) {
			for (int i = 0; i < tc.playerTanks.size(); i++) {
				if (((Tank) tc.playerTanks.get(i)).getRect().intersects(
						this.getRect())) {
					hit=true;
				}
			}
		}
		
		if (!hit){
			tc.tank.getRect().intersects(this.getRect());
		}
		
		return hit;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -