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

📄 maze.java

📁 用J2ME写的一种七彩连珠(五子连线)的手机游戏 通用程序
💻 JAVA
字号:



class Maze {

	static final int[] dx = { 1, 0, -1, 0 };

	static final int[] dy = { 0, -1, 0, 1 };

	static final int[] queueX = new int[Cfg.SIZE * Cfg.SIZE];

	static final int[] queueY = new int[Cfg.SIZE * Cfg.SIZE];

	boolean[][] b;

	int x0, y0, x1, y1;

	public Maze(Object[][] objects, int x0, int y0, int x1, int y1) {
		// Rub.ob((Ball[][])objects);
		// System.out.println("x0y0x1y1: " + x0 + y0 + x1 + y1);
		this.b = new boolean[objects.length][objects[0].length];
		for (int i = 0; i < b.length; ++i) {
			for (int j = 0; j < b[0].length; ++j) {
				b[i][j] = (objects[i][j] != null);
			}
		}
		this.x0 = x0;
		this.y0 = y0;
		this.x1 = x1;
		this.y1 = y1;
	}

	boolean isConnect() {
		Maze.queueX[0] = x0;
		Maze.queueY[0] = y0;
		int qHead = 0;
		int qTail = 1;
		while (qHead < qTail) {

			int x = Maze.queueX[qHead];
			int y = Maze.queueY[qHead];
			++qHead;
			if (x == x1 && y == y1) {
				return true;
			}
			// b[x][y] = true;
			for (int i = 0; i < Maze.dx.length; ++i) {
				int nextX = x + dx[i];
				int nextY = y + dy[i];
				if (nextX < 0 || nextX >= Cfg.SIZE || nextY < 0
						|| nextY >= Cfg.SIZE || b[nextX][nextY]) {
					continue;
				}
				Maze.queueX[qTail] = nextX;
				Maze.queueY[qTail] = nextY;
				b[nextX][nextY] = true;
				++qTail;
			}
		}
		return false;
	}

}

⌨️ 快捷键说明

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