java编程五子棋代码 新手java五子棋完整代码( 八 )


{
if(((a+step)*20==chessBlack_x[chessCompare])((b-step)*20==chessBlack_y[chessCompare]))
{
chessLink++;
if(chessLink==5)
{
return(true);
}
}
}
if(chessLink==(chessLinkTest+1))
chessLinkTest++;
else
break;
}
chessLink=1;
chessLinkTest=1;
for(step=1;step=4;step++)
{
for(chessCompare=0;chessCompare=chessBlackCount;chessCompare++)
{
if(((a+step)*20==chessBlack_x[chessCompare])((b+step)*20==chessBlack_y[chessCompare]))
{
chessLink++;
if(chessLink==5)
{
return(true);
}
}
}
if(chessLink==(chessLinkTest+1))
chessLinkTest++;
else
break;
}
for(step=1;step=4;step++)
{
for(chessCompare=0;chessCompare=chessBlackCount;chessCompare++)
{
if(((a-step)*20==chessBlack_x[chessCompare])((b-step)*20==chessBlack_y[chessCompare]))
{
chessLink++;
if(chessLink==5)
{
return(true);
}
}
求java五子棋代码要注释~现在1小时等待package org.crazyit.gobang;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* 五子棋游戏类
*
* @author yangenxiong yangenxiong2009@gmail.com
* @author Kelvin Mak kelvin.mak125@gmail.com
* @version1.0
* br/网站: a href=""疯狂Java联盟/a
* brCopyright (C), 2009-2010, yangenxiong
* brThis program is protected by copyright laws.
*/
public class GobangGame {
// 定义达到赢条件的棋子数目
private final int WIN_COUNT = 5;
// 定义用户输入的X坐标
private int posX = 0;
// 定义用户输入的X坐标
private int posY = 0;
// 定义棋盘
private Chessboard chessboard;
/**
* 空构造器
*/
public GobangGame() {
}
/**
* 构造器,初始化棋盘和棋子属性
*
* @param chessboard
*棋盘类
*/
public GobangGame(Chessboard chessboard) {
this.chessboard = chessboard;
}
/**
* 检查输入是否合法 。
*
* @param inputStr
*由控制台输入的字符串 。
* @return 字符串合法返回true,反则返回false 。
*/
public boolean isValid(String inputStr) {
// 将用户输入的字符串以逗号(,)作为分隔,分隔成两个字符串
String[] posStrArr = inputStr.split(",");
try {
posX = Integer.parseInt(posStrArr[0]) - 1;
posY = Integer.parseInt(posStrArr[1]) - 1;
} catch (NumberFormatException e) {
chessboard.printBoard();
System.out.println("请以(数字,数字)的格式输入:");
return false;
}
// 检查输入数值是否在范围之内
if (posX0 || posX = Chessboard.BOARD_SIZE || posY0
|| posY = Chessboard.BOARD_SIZE) {
chessboard.printBoard();
System.out.println("X与Y坐标只能大于等于1,与小于等于" + Chessboard.BOARD_SIZE
+ ",请重新输入:");
return false;
}
// 检查输入的位置是否已经有棋子
String[][] board = chessboard.getBoard();
if (board[posX][posY] != "十") {
chessboard.printBoard();
System.out.println("此位置已经有棋子 , 请重新输入:");
return false;
}
return true;
}
/**
* 开始下棋
*/
public void start() throws Exception {
// true为游戏结束
boolean isOver = false;
chessboard.initBoard();
chessboard.printBoard();
// 获取键盘的输入
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String inputStr = null;
// br.readLine:每当键盘输入一行内容按回车键,则输入的内容被br读取到
while ((inputStr = br.readLine()) != null) {

推荐阅读