bomb.java

来自「一个关于沉船的J2ME小游戏」· Java 代码 · 共 92 行

JAVA
92
字号
// Bomb class

import javax.microedition.lcdui.*;

class Bomb
{
	public int		x;
	public int		y;
	public int		oldX;
	public int		oldY;
	public int		width;
	public int		height;
	public int		status;
	public int		dropDistance;
	public int		strength;
	public boolean	redraw;		// Redraw the backgound
	public int		columnHit;		// City column hit (Used to redraw the broken block after background redraw)
	public int		maxDrop;
	public int		xOffset;
	public int		yOffset;

	Bomb()
	{
		this.init();
	}

	void init()
	{
		this.x = 0;
		this.y = 0;
		this.oldX = this.x;
		this.oldY = this.y;
		this.width  = 0;
		this.height = 0;
		this.dropDistance = 0;
		this.columnHit = -1;
		this.xOffset = 0;
		this.yOffset = 0;
	}

	void setSize(int xSize, int ySize, int iDrop, int xOff, int yOff)
	{
		this.width = xSize;
		this.height = ySize;
		this.dropDistance = iDrop;
		this.xOffset = xOff;
		this.yOffset = yOff;
	}

	// Drop a bomb in if available
	void drop(int dropX, int dropY)
	{
		if (this.status != 0) return;
		dropX /= this.width;
		dropX++;
		dropX *= this.width;
		this.status = 1;
		this.x = dropX + this.xOffset;
		this.y = dropY + this.yOffset;
		this.strength = 4;
		this.oldX = this.x;
		this.oldY = this.y;
		this.columnHit = -1;
	}

	// Move the bomb down the screen
	void move()
	{
		if (this.status == 0) return;

		// Save the location and set redraw background to true
		this.oldX = this.x;
		this.oldY = this.y;
		this.redraw = true;

		// Move the bomb
		this.y += dropDistance;
		if (this.y > maxDrop) this.status = 0;
	}

	void killBomb()
	{
		// Save the location and set redraw background to true
		this.oldX = this.x;
		this.oldY = this.y;
		this.redraw = true;
		this.status = 0;
	}


}

⌨️ 快捷键说明

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