Chess[Max - 1][4].setText("裁判");
//比分显示
Chess[Max - 1][6].setText("总比分");
Chess[Max - 1][7].setText("黑"+Mark1);
Chess[Max - 1][8].setText("白"+Mark2);
Chess[0][1].setBackground(Color.white);
Chess[0][Max - 1].setBackground(Color.white);
}
//设置功能按钮的事件侦听事件
class UserEvent implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Object obj = e.getSource();
//System.out.println("you have pressed a area");
if (obj == Chess[Max - 1][1]) { System.exit(1); }//退出按钮
if (obj == Chess[Max - 1][2]) { new Reset(); }//退出按钮
if (obj == Chess[Max - 1][3])//让步按钮
{
if (IamFirst == false)//如果白棋让步
{
IamFirst = true;
Chess[0][0].setBackground(Color.red);
Chess[0][Max-2].setBackground(Color.white);
}
else //如果黑棋让步
{
IamFirst = false;
Chess[0][0].setBackground(Color.white);
Chess[0][Max-2].setBackground(Color.red);
}
}
if(obj == Chess[Max - 1][4])//如果按裁判按钮,计算成绩
{
int M1 = 0, M2 = 0;
M1 = Integer.parseInt(Chess[0][1].getText());
M2 = Integer.parseInt(Chess[0][Max - 1].getText());
if (M1>M2){
System.out.println("黑棋胜");
msg = new String("裁判郑重宣布:\n胜利方为黑棋!\n恭喜恭喜!黑棋取得胜利!继续努力吧!\n白棋不要气馁,再接再厉!");
JOptionPane.showOptionDialog(null, msg, "成绩统计结果!", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
Mark1 = Mark1 + 1;//修改比分
Chess[Max - 1][7].setText("黑" + Mark1);
}
if (M1<M2){
System.out.println("白棋胜");
msg = new String("裁判郑重宣布:\n胜利方为白棋!\n恭喜恭喜!白棋取得胜利!继续努力吧!\n黑棋不要气馁,再接再厉!");
JOptionPane.showOptionDialog(null, msg, "成绩统计结果!", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
Mark2 = Mark2 + 1;
Chess[Max - 1][8].setText("白" + Mark1);
}
if (M1 == M2)
{
System.out.println("双方战平");
msg = new String("裁判郑重宣布:\n双方战平!\n大家水平相当!努力吧,争取下次打倒对手!");
JOptionPane.showOptionDialog(null, msg, "成绩统计结果!", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
}
new Reset();//调用重设棋盘方法
}
//循环侦听棋盘上按钮事件
for (int i = 1; i < Max - 1; i++)
{
//System.out.println("line:"+i);
for (int j = 1; j < Max - 1; j++)
{
//System.out.println("coulue:"+j);
if (obj == Chess[i][j])
{
//System.out.println("you have pressed Chess" + i + j);
if (Chess[i][j].getText() == "")//只侦听棋盘上的空白区域
{
//System.out.println("this area has no Chess");
//检查当前点击的按钮周围8个按钮是否为空,如果为空,则不进行处理,程序返回
if (Chess[i + 1][j].getText() == "●" || Chess[i - 1][j].getText() == "●" ||
Chess[i + 1][j + 1].getText() == "●" || Chess[i - 1][j - 1].getText() == "●" ||
Chess[i + 1][j - 1].getText() == "●" || Chess[i - 1][j + 1].getText() == "●" ||
Chess[i][j + 1].getText() == "●" || Chess[i][j - 1].getText() == "●" ||
Chess[i + 1][j].getText() == "○" || Chess[i - 1][j].getText() == "○" ||
Chess[i + 1][j + 1].getText() == "○" || Chess[i - 1][j - 1].getText() == "○" ||
Chess[i + 1][j - 1].getText() == "○" || Chess[i - 1][j + 1].getText() == "○" ||
Chess[i][j + 1].getText() == "○" || Chess[i][j - 1].getText() == "○")
{
//System.out.println("there is at least 1 Chess around it");
//判断是谁下的棋
if (IamFirst == true)
{
System.out.println("I am black");
rules(i, j, "●");
if (ChessCheck == true)
{
Chess[i][j].setText("●");
IamFirst = false;
Chess[0][0].setBackground(Color.white);
Chess[0][Max-2].setBackground(Color.red);
WhoWin();
}
}
上一页 [1] [2] [3] [4] [5] [6] [7] [8] 下一页
JAVA课程设计黑白棋源代码 第5页下载如图片无法显示或论文不完整,请联系qq752018766