publicclassGobang{//定义一个二维数组充当棋盘privateString[][]board;//定义棋盘大小privatestaticintboard_size=15;publicvoidinitBoard(){//初始化棋盘数组board=newString[board...
public class Gobang {
//定义一个二维数组充当棋盘
private String[][] board;
//定义棋盘大小
private static int board_size=15;
public void initBoard()
{
//初始化棋盘数组
board=new String[board_size][board_size];
//定义一个“+”
for (int i=0;i
{
for (int j=0;j
{
board[i][j]="+";
}
}
}
//在控制输出棋盘的方法
public void printBoard()
{
//打印每个数组元素
for (int i =0 ;i< board_size ;i++ )
{
for (int j=0;j
{
//打印
System.out.print(board[i][j]);
} //每次打印后输出一个换行符
System.out.print("\n");
}
}
public static void main(String[] args)throws Exception
{
Gobang gb=new Gobang();
gb.initBoard();
gb.printBoard();
//获取键盘输入的方法
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
String input=null;
while ((input=br.readline())!=null)
{
String[] poss=input.split(",");
int x=Integer.parseInt(poss[0]);
int y=Integer.parseInt(poss[1]);
gb.board[x-1][y-1]="●";
gb.printBoard();
System.out.println("请输入您下棋的坐标,应以x,y的格式:");
}
}
}
展开