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

📄 autoplay.java

📁 一个简单的JAVA五子棋游戏
💻 JAVA
字号:
package cn.pzhu.lxb.chess;

public class AutoPlay {
	int x, y;

	void autoPlay(int chesspad[][], int a, int b) {
		int randomNumber = (int) (Math.random() * 8) + 1;          //Math.random()产生0.0~1.0之间的随机数字
		switch (randomNumber) {
		case (1):
			if (chesspad[a - 1][b - 1] == 0) {
				x = a - 1;
				y = b - 1;
			} else if (chesspad[a - 2][b - 2] == 0) {
				x = a - 2;
				y = b - 2;
			} else {
				x = a - 3;
				y = b - 3;
			}
			break;

		case (2):
			if (chesspad[a - 1][b] == 0) {
				x = a - 1;
				y = b;
			} else if (chesspad[a - 2][b] == 0) {
				x = a - 2;
				y = b;
			} else {
				x = a - 3;
				y = b;
			}
			break;
		case (3):
			if (chesspad[a - 1][b + 1] == 0) {
				x = a - 1;
				y = b + 1;
			} else if (chesspad[a - 2][b + 2] == 0) {
				x = a - 2;
				y = b + 2;
			} else {
				x = a - 3;
				y = b + 3;
			}
			break;
		case (4):
			if (chesspad[a][b + 1] == 0) {
				x = a;
				y = b + 1;
			} else if (chesspad[a][b + 2] == 0) {
				x = a;
				y = b + 2;
			} else {
				x = a;
				y = b + 3;
			}
			break;
		case (5):
			if (chesspad[a + 1][b + 1] == 0) {
				x = a + 1;
				y = b + 1;
			} else if (chesspad[a + 2][b + 2] == 0) {
				x = a + 2;
				y = b + 2;
			} else {
				x = a + 3;
				y = b + 3;
			}
			break;
		case (6):
			if (chesspad[a + 1][b] == 0) {
				x = a + 1;
				y = b;
			} else if (chesspad[a + 2][b] == 0) {
				x = a + 2;
				y = b;
			} else {
				x = a + 3;
				y = b;
			}
			break;
		case (7):
			if (chesspad[a + 1][b - 1] == 0) {
				x = a + 1;
				y = b - 1;
			} else if (chesspad[a + 2][b - 2] == 0) {
				x = a + 2;
				y = b - 2;
			} else {
				x = a + 3;
				y = b - 3;
			}
			break;
		case (8):
			if (chesspad[a][b - 1] == 0) {
				x = a;
				y = b - 1;
			} else if (chesspad[a][b - 2] == 0) {
				x = a;
				y = b - 2;
			} else {
				x = a;
				y = b + 3;
			}
			break;
		}
	}
}

⌨️ 快捷键说明

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