You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.9 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package game;
//设置按钮监听方法monitor类
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
//实现对JPanel的监听接口处理
public class monitor implements config,ActionListener{
public UI gf;
static int q=0;
public monitor(UI gf) {
this.gf=gf;//获取左半部分的画板
}
//当界面发生操作时进行处理
public void actionPerformed(ActionEvent e) {
//获取当前被点击按钮的内容,判断是不是"开始新游戏"这个按钮
if(e.getActionCommand().equals("开始新游戏")) {
//如果是开始新游戏的按钮,再为左半部分设置监听方法
q++;
gf.textA.setText(" 开始新游戏!");
listener fl=new listener();
fl.setGraphics(gf);//获取画笔对象
gf.addMouseListener(fl);
}
//判断当前点击的按钮是不是悔棋
else if(e.getActionCommand().equals("悔棋")) {
if(gf.ChessPositonList.size()>1) {
//把棋子数组相应的位置置为0
position l=new position();
//获取最后一个棋子的对象信息
l=gf.ChessPositonList.remove(gf.ChessPositonList.size()-1);
//把相应的数组位置置为0
gf.isAvail[l.Listi][l.Listj]=0;
//把玩家还原为上一步的玩家
if(gf.turn==1) gf.turn++;
else gf.turn--;
gf.textA.setText(" ");
//直接调用gf的重绘方法重绘方法的画笔应该是在棋盘页面还没生成的时候就要获取
//调用repaint会自动调用paint方法而且不用给参数
gf.repaint();
//gf.paint(gf.getGraphics());
}
else {
gf.textA.setText(" 不能悔棋!");
//System.out.println("不能悔棋!");
}
}
else if(e.getActionCommand().equals("认输")) {
if(gf.turn==1) gf.textA.setText(" 白方赢!");//System.out.println("白方赢");
else gf.textA.setText(" 黑方赢!"); //System.out.println("黑方赢");
}
}
}