📄 five.java
字号:
/*
Five.java 2008 09 24
CopyRight umsoft.net
author liusy
*/
/**
这个程序是通过制表符拼成五子棋的棋盘
┏ ┳ ┓
┣ ╋ ┫
┗ ┻ ┛
只支持单机人与人对弈
通过输入行列数决定棋子位置
如:2,4
就代表 2行 4列 下一个棋子
*/
public class Five
{
private int row ;
private int col;
private boolean bBlack = false;
// 定义棋盘类
ChessBoard chessBoard;
//
FiveInput fiveInput = new FiveInput();
public static void main(String[] args)
{
// 判断用输参数输入的是否正确
if (args.length < 2)
{
System.out.println(" 请输入棋盘大小");
System.out.println(" 格式: java Five 行数 列数");
System.out.println(" java Five 10 10 ");
// 退出程序
System.exit(0);
}
Five five = new Five();
// 取得棋盘大小
five.setRow( Integer.valueOf(args[0]));
five.setCol( Integer.valueOf(args[1]));
five.start();
}
// getter /setter
public void setRow(int v )
{
this.row = v;
}
public void setCol(int v )
{
this.col = v;
}
public void start()
{
// 进入下棋过程
chessBoard = new ChessBoard();
// 初始化棋盘
chessBoard.init(row , col );
// 输出欢迎信息
System.out.println("-----------------------------------");
System.out.println("| 欢迎使用XX五子棋游戏 |");
System.out.println("-----------------------------------");
while (true)
{
System.out.println("-----------------------------------");
System.out.println("| quit 退出 |");
System.out.println("-----------------------------------");
for (int i = 0 ; i < 10; i ++ )
{
System.out.println("");
}
//显示棋盘
chessBoard.showBoard();
//判断黑方还是白方下棋
if (bBlack)
{
System.out.println("---------------------------------");
System.out.println("| 黑方下棋 |");
System.out.println("---------------------------------");
}else{
System.out.println("---------------------------------");
System.out.println("| 白方下棋 |");
System.out.println("---------------------------------");
}
//等待用户输入下棋位置
fiveInput.input();
// 判断这个位置是不是已经有棋子
if (chessBoard.board[fiveInput.getCurRow()][fiveInput.getCurCol()] == chessBoard.black || chessBoard.board[fiveInput.getCurRow()][fiveInput.getCurCol()] == chessBoard.white)
{
System.out.print("你傻啊,那已经有棋子了");
fiveInput.input();
}
//根据用户下棋位置维护棋盘
chessBoard.go(bBlack ,fiveInput.getCurRow() , fiveInput.getCurCol() );
bBlack = !bBlack;
if (checkWin() == false)
{
break;
}
}
}
/**
功能: 判断输赢
*/
public boolean checkWin()
{
if ()
{
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -