java 五子棋 源代码 在我的基础上加个悔棋 判断胜负后把胜利的一方显示在屏幕上 或别的标明胜利一方的 谢我的设计是:
allChess[19][19] ;//19 * 19 的棋盘存放所有的棋子
0 -- 当前没有棋子
1 -- 黑子
2 -- 白子
比如: allChess[2][3]=2-- 第3行第4列为白子
如果想要悔棋的话,我的理解是这样的:
拿白子举例:
每下一个白子后 , 保存两个数组,连续下两次白子之后的数组,如果想悔棋,黑方确认之后 , 返回到上一次白子下后的数组 。
楼主这样试试
用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);
choice[1] = new JRadioButton("フ?", new ImageIcon(white));
for(int i=0; ichoice.length; i++)
{
choice_menu.add(choice[i]);
choice_group.add(choice[i]);
}
for(int i=0; icommand.length; i++)
{
command[i] =new JMenuItem(command_str[i]);
command[i].addActionListener(this);
control_menu.add(command[i]);
}
JButton select = new JButton("絋)");
JPanel select_menu = new JPanel();
select_menu.add(select);
推荐阅读
- 直播囤货话术,直播囤货话术大全
- 怎么下载chatgpt电脑版,cheat engine电脑版怎么下载
- 关注公众号怎么在桌面,关注公众号怎么在桌面上显示
- js事件区分,js中的事件类型
- 梯度函数python 梯度函数怎么求python
- mysql暂时修改数据库引擎,mysql暂时修改数据库引擎内容
- thinkphp模板split,thinkPHP模板文件抛出异常
- 捕鱼游戏开发公司,捕鱼游戏定制开发公司
- linux命令是光标 linux光标移动命令