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玩家")){
roles = "A玩家";
}
}
}
}
用JAVA实现五子棋悔棋代码保存成.java文件直接运行编译
这是我回答五子棋代码java随机的别人问题五子棋代码java随机的答案地址
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
class Gobang extends JFrame implements Runnable, ActionListener
{
final static int Player=1;
final static int AI =-1;
ClassLoader cl = this.getClass().getClassLoader();
Toolkit tk = Toolkit.getDefaultToolkit();
int length=14, game_state, winner, check, step;
int grid[][] = new int[length][length];
int locX, locY /* ?囱?竚 */, count /* 硈囱计 */, x, y /* 既??竚 */, displace_x=0, displace_y=0 /* ?簿秖 */, direction;
ArrayList steps = new ArrayList(); /* 疠魁囱˙ */
JPopupMenu control_menu = new JPopupMenu(); /* ?龄匡虫?? */
JMenuItem[] command = new JMenuItem[4];
String[] command_str={"?囱", "?郎", "弄郎", "?秨"};
int[][] dir = { {-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1} };
boolean[] dir2 = new boolean[8];
boolean turn;
String message;
final JDialog dialog = new JDialog(this, "叫匡?", true);
Font font=new Font("new_font", Font.BOLD, 20);
Grid grids[][] = new Grid[length][length];
Image white= tk.getImage(cl.getResource("res/white.png"));
Image black= tk.getImage(cl.getResource("res/black.png"));
Image title= tk.getImage(cl.getResource("res/title.png"));
Image temp;
JPanel boardPanel, bigpanel;
JRadioButton[] choice = new JRadioButton[2];
final static int Start =0;
final static int Select =1;
final static int Playing =2;
final static int End =3;
final static int nil=-1; /* 礚よ? */
final static int oblique_1 =0; /* ???オ? */
final static int oblique_2 =1; /* オ???? */
final static int horizontal =2; /* 绢? */
final static int vertical=3; /* ?? */
Gobang()
{
super("き?囱");
boardPanel = new JPanel();
boardPanel.setLayout(new GridLayout(length, length, 0, 0));
boardPanel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
for(int i=0; ilength; i++)
for(int j=0; jlength; j++)
{
grids[i][j] = new Grid(i, j);
boardPanel.add(grids[i][j]);
}
bigpanel = new JPanel();
bigpanel.add(boardPanel, BorderLayout.CENTER);
getContentPane().add(bigpanel, BorderLayout.SOUTH);
game_state=Start;
ThreadStart();
dialog.setSize(160, 100);
dialog.setResizable(false);
dialog.setLocationRelativeTo(null);
ButtonGroup choice_group = new ButtonGroup();
JPanel choice_menu = new JPanel();
choice[0] = new JRadioButton("堵?", new ImageIcon(black), true);
推荐阅读
- 保皇直播技巧,保皇游戏直播
- 云从科技新增ChatGPT概念,云从科技是什么公司
- 毕业设计模仿现有的网站吗,毕业设计论文去网上模仿
- 即时战略类游戏发展史小说,即时战略类的游戏
- linux命令逻辑符号 linux命令符号解释
- 电商如何发液体快递,液体怎么发国际快递
- 会展小程序开发功能,会展软件应用
- 无人直播图片动漫,无人直播效果怎么样
- php抓取首页数据 php获取当前页面url