网络五子棋java代码 java五子棋源代码及uml类图(13)


}
if (board[x][y].equals("●") || board[x][y].equals("○")) {
isRight = false;
}
return isRight;
}
//判断谁赢了
public void whoWin(Games wz) {
// 从数组挨个查找找到某个类型的棋子就从该棋子位置向右,向下,斜向右下 各查找5连续的位置看是否为5个相同的
int xlabel;// 记录第一次找到某个棋子的x坐标
int ylabel;// 记录第一次找到某个棋子的y坐标
// ●○╋
// 判断人是否赢了
for (int i = 0; iSIZE; i++) {
for (int j = 0; jSIZE; j++) {
if (board[i][j].equals("○")) {
xlabel = i;
ylabel = j;
// 横向找 x坐标不变 y坐标以此加1连成字符串
String heng = "";
if (i + 5SIZEj + 5SIZE) {
for (int k = j; kj + 5; k++) {
heng += board[i][k];
}
if (heng.equals("○○○○○")) {
System.out.println(roles+"赢了!您输了!");
System.exit(0);
}
// 向下判断y不变 x逐增5 连成字符串
String xia = "";
for (int l = j; li + 5; l++) {
xia += board[l][j];
// System.out.println(xia);
}
if (xia.equals("○○○○○")) {
System.out.println(roles+"赢了!您输了!");
System.exit(0);
}
// 斜向右下判断
String youxia = "";
for (int a = 1; a = 5; a++) {
youxia += board[xlabel++][ylabel++];
}
if (youxia.equals("○○○○○")) {
System.out.println(roles+"赢了!您输了!");
System.exit(0);
}
}
}
}
}
// 判断电脑是否赢了
for (int i = 0; iSIZE; i++) {
for (int j = 0; jSIZE; j++) {
if (board[i][j].equals("●")) {
xlabel = i;
ylabel = j;
// 横向找 x坐标不变 y坐标以此加1连成字符串
String heng = "";
if (j + 5SIZEi + 5SIZE) {
for (int k = j; kj + 5; k++) {
heng += board[i][k];
}
if (heng.equals("●●●●●")) {
System.out.println(roles+"赢输了!您输了!");
System.exit(0);
}
// 向下判断y不变 x逐增5 连成字符串
String xia = "";
for (int l = i; li + 5; l++) {
xia += board[l][ylabel];
// System.out.println(xia);
}
if (xia.equals("●●●●●")) {
System.out.println(roles+"赢了!您输了!");
System.exit(0);
}
// 斜向右下判断
String youxia = "";
for (int a = 1; a = 5; a++) {
youxia += board[xlabel++][ylabel++];
}
if (youxia.equals("●●●●●")) {
System.out.println(roles+"赢了!您输了!");
System.exit(0);
}
}
}
}
}
}
public static void main(String[] args) {
Games wz = new Games();
Scanner sc = new Scanner(System.in);
wz.initBoard();
wz.printBoard();
while (true) {
System.out.print("请"+roles+"输入X , Y坐标 , 必须在0-15范围内,xy以空格隔开,输入16 16结束程序");
int x = sc.nextInt();
int y = sc.nextInt();
if (x == SIZEy == SIZE) {
System.out.println("程序结束");
System.exit(0);
}
if (xSIZE || x0 || ySIZE | y0) {
System.out.println("输入错误,请从新输入");
continue;
}
//如果roles是A玩家 就让A玩家下棋 , 否则就让B玩家下棋 。
if (wz.board[x][y].equals("╋")roles.equals("A玩家")) {
wz.board[x][y] = "○";
wz.printBoard();
//判断输赢
wz.whoWin(wz);
}else if(wz.board[x][y].equals("╋")roles.equals("B玩家")){
wz.board[x][y] = "●";
wz.printBoard();
//判断输赢
wz.whoWin(wz);
} else {
System.out.println("此处已经有棋子,从新输入");
continue;
}
if(roles.equals("A玩家")){
roles = "B玩家";
}else if(roles.equals("B玩家")){

推荐阅读