java写五子棋代码 基于java的五子棋游戏的设计代码( 二 )


System.out.println("请输入您下棋的坐标 , 应以x,y的格式输入:");
}
}
/**
* 是否重新开始下棋 。
*
* @param chessman
*"●"为用户,"○"为计算机 。
* @return 开始返回true , 反则返回false 。
*/
public boolean isReplay(String chessman) throws Exception {
chessboard.printBoard();
String message = chessman.equals(Chessman.BLACK.getChessman()) ? "恭喜您,您赢了,"
: "很遗憾,您输了,";
System.out.println(message + "再下一局?(y/n)");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
if (br.readLine().equals("y")) {
// 开始新一局
return true;
}
return false;
}
/**
* 计算机随机下棋
*/
public int[] computerDo() {
int posX = (int) (Math.random() * (Chessboard.BOARD_SIZE - 1));
int posY = (int) (Math.random() * (Chessboard.BOARD_SIZE - 1));
String[][] board = chessboard.getBoard();
while (board[posX][posY] != "十") {
posX = (int) (Math.random() * (Chessboard.BOARD_SIZE - 1));
posY = (int) (Math.random() * (Chessboard.BOARD_SIZE - 1));
}
int[] result = { posX, posY };
return result;
}
/**
* 判断输赢
*
* @param posX
*棋子的X坐标 。
* @param posY
*棋子的Y坐标
* @param ico
*棋子类型
* @return 如果有五颗相邻棋子连成一条直接,返回真,否则相反 。
*/
public boolean isWon(int posX, int posY, String ico) {
// 直线起点的X坐标
int startX = 0;
// 直线起点Y坐标
int startY = 0;
// 直线结束X坐标
int endX = Chessboard.BOARD_SIZE - 1;
// 直线结束Y坐标
int endY = endX;
// 同条直线上相邻棋子累积数
int sameCount = 0;
int temp = 0;
// 计算起点的最小X坐标与Y坐标
temp = posX - WIN_COUNT + 1;
startX = temp0 ? 0 : temp;
temp = posY - WIN_COUNT + 1;
startY = temp0 ? 0 : temp;
// 计算终点的最大X坐标与Y坐标
temp = posX + WIN_COUNT - 1;
endX = tempChessboard.BOARD_SIZE - 1 ? Chessboard.BOARD_SIZE - 1
: temp;
temp = posY + WIN_COUNT - 1;
endY = tempChessboard.BOARD_SIZE - 1 ? Chessboard.BOARD_SIZE - 1
: temp;
// 从左到右方向计算相同相邻棋子的数目
String[][] board = chessboard.getBoard();
for (int i = startY; iendY; i++) {
if (board[posX][i] == icoboard[posX][i + 1] == ico) {
sameCount++;
} else if (sameCount != WIN_COUNT - 1) {
sameCount = 0;
}
}
if (sameCount == 0) {
// 从上到下计算相同相邻棋子的数目
for (int i = startX; iendX; i++) {
if (board[i][posY] == icoboard[i + 1][posY] == ico) {
sameCount++;
} else if (sameCount != WIN_COUNT - 1) {
sameCount = 0;
}
}
}
if (sameCount == 0) {
// 从左上到右下计算相同相邻棋子的数目
int j = startY;
for (int i = startX; iendX; i++) {
if (jendY) {
if (board[i][j] == icoboard[i + 1][j + 1] == ico) {
sameCount++;
} else if (sameCount != WIN_COUNT - 1) {
sameCount = 0;
}
j++;
}
}
}
return sameCount == WIN_COUNT - 1 ? true : false;
}
public static void main(String[] args) throws Exception {
GobangGame gb = new GobangGame(new Chessboard());
gb.start();
}
}
求一个简单的JAVA五子棋代码?。?网上复制的别来了!以下是现写的 实现了两人对战自己复制后运行把 没什么难度 类名 Games
import java.util.Scanner;
public class Games {
private String board[][];
private static int SIZE = 17;
private static String roles = "A玩家";

推荐阅读