五子棋
首先是运行效果
cmd
Eclipse
Ⅰ在cmd中运行时,代表棋子的符号 "○","●" 占位过大所以替换为 "Q","X" 来表示。
即:static String who[] ={"Q","X"}; //黑白棋子
Ⅱ另外在eclipse中运行效果最好,但在显示棋盘时会与cmd中的不同可以做如下调整:
(eclipse中自行调整字体)
//打印棋盘 private static void show() { for (int i = 0; i < chess.length; i++) System.out.print(" "+(char)+('A'+i)+" "); System.out.println(); for (int i = 0; i < chess.length; i++) { System.out.print((char)+('A'+i)); for (int j = 0; j < chess.length; j++) { System.out.print(chess[i][j]); if(j<14) System.out.print("—"); } System.out.println(); for (int x = 0; x < chess.length; x++) { if(i<14) { System.out.print(" ┤ "); } } System.out.println(); } }
import java.util.Scanner;
public class Text1{
//二维数组,棋盘
static String[][] chess = new String[15][15];//成员,全局唯一;static保存在方法区,在类对象加载前jvm
static int times;//棋盘上棋子总数
static String who[] ={"Q","X"}; //黑白棋子
static String temp[] = {"0","0"