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

📄 dajiang.java

📁 java开发的华容道游戏的源码
💻 JAVA
字号:
package com.abc.hrd;

public class Dajiang extends Qizi {
	public Dajiang(Qipan qipan, int x, int y) {
		super(qipan, x, y);
		this.w = 1;
		this.h = 2;

	}

	public boolean inside(int x, int y) {
		if (y > this.y) {
			y = y - 1;
		}

		if (x == this.x && y == this.y) {
			return true;
		} else {
			return false;
		}

	}

	public boolean move(int x, int y) {

		// 原地不动
		if (inside(x, y)) {
			return false;
		}

		// 纵向移动
		if (this.x == x) {
			if (y == this.y + 2) { // 向下移动一格
				this.y++;
				return true;
			}
			if (y == this.y - 1) { // 向上移动一格
				this.y--;
				return true;
			}
			if (y == this.y + 3 && !qipan.exists(x, this.y + 2)) { // 向下移动二格
				this.y += 2;
				return true;
			}
			if (y == this.y - 2 && !qipan.exists(x, this.y - 1)) { // 向上移动二格
				this.y -= 2;
				return true;
			}
			return false;
		}
		// 横向移动
		else {
			if (x > this.x) { // 向右移动一格
				if (!qipan.exists(this.x + 1, this.y)
						&& !qipan.exists(this.x + 1, this.y + 1)) {
					this.x++;
					return true;
				}
			} else { // 向左移动
				if (!qipan.exists(this.x - 1, this.y)
						&& !qipan.exists(this.x - 1, this.y + 1)) {
					this.x--;
					return true;
				}
			}
			return false;
		}

	}

}

⌨️ 快捷键说明

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