作业七:团队项目——Alpha版本冲刺阶段-10

部分代码:

 public void run(){
while (true){
//单击棋子第一下开始闪烁
if (chessManClick){
play[Man].setVisible(false); //时间控制
try{
tmain.sleep();
}
catch(Exception e){
} play[Man].setVisible(true);
} //闪烁当前提示信息 以免用户看不见
else {
text.setVisible(false);
//时间控制
try{
tmain.sleep();
}
catch(Exception e){
} text.setVisible(true);
} try{
tmain.sleep();
}
catch (Exception e){
}
}
} //单击棋子方法
public void mouseClicked(MouseEvent me){
System.out.println("Mouse"); //当前坐标
int Ex=,Ey=; //启动线程
if (tmain == null){
tmain = new Thread(this);
tmain.start();
} //单击棋盘(移动棋子)
if (me.getSource().equals(image)){
//该红棋走棋的时候
if (chessPlayClick == && play[Man].getName().charAt() == ''){
Ex = play[Man].getX();
Ey = play[Man].getY();
//移动卒、兵
if (Man > && Man < ){
rule.armsRule(Man,play[Man],me);
} //移动炮
else if (Man > && Man < ){
rule.cannonRule(play[Man],play,me);
} //移动车
else if (Man >= && Man < ){
rule.cannonRule(play[Man],play,me);
} //移动马
else if (Man > && Man < ){
rule.horseRule(play[Man],play,me);
} //移动相、象
else if (Man > && Man < ){
rule.elephantRule(Man,play[Man],play,me);
} //移动仕、士
else if (Man > && Man < ){
rule.chapRule(Man,play[Man],play,me);
} //移动将、帅
else if (Man == || Man == ){
rule.willRule(Man,play[Man],play,me);
} //是否走棋错误(是否在原地没有动)
if (Ex == play[Man].getX() && Ey == play[Man].getY()){
text.setText(" 红棋走棋");
chessPlayClick=;
} else {
text.setText(" 黑棋走棋");
chessPlayClick=;
} }//if //该黑棋走棋的时候
else if (chessPlayClick == && play[Man].getName().charAt() == ''){
Ex = play[Man].getX();
Ey = play[Man].getY(); //移动卒、兵
if (Man > && Man < ){
rule.armsRule(Man,play[Man],me);
} //移动炮
else if (Man > && Man < ){
rule.cannonRule(play[Man],play,me);
} //移动车
else if (Man >= && Man < ){
rule.cannonRule(play[Man],play,me);
} //移动马
else if (Man > && Man < ){
rule.horseRule(play[Man],play,me);
} //移动相、象
else if (Man > && Man < ){
rule.elephantRule(Man,play[Man],play,me);
} //移动仕、士
else if (Man > && Man < ){
rule.chapRule(Man,play[Man],play,me);
} //移动将、帅
else if (Man == || Man == ){
rule.willRule(Man,play[Man],play,me);
} //是否走棋错误(是否在原地没有动)
if (Ex == play[Man].getX() && Ey == play[Man].getY()){
text.setText(" 黑棋走棋");
chessPlayClick=;
} else {
text.setText(" 红棋走棋");
chessPlayClick=;
} }//else if //当前没有操作(停止闪烁)
chessManClick=false; }//if //单击棋子
else{
//第一次单击棋子(闪烁棋子)
if (!chessManClick){
for (int i=;i<;i++){
//被单击的棋子
if (me.getSource().equals(play[i])){
//告诉线程让该棋子闪烁
Man=i;
//开始闪烁
chessManClick=true;
break;
}
}//for
}//if //第二次单击棋子(吃棋子)
else if (chessManClick){
//当前没有操作(停止闪烁)
chessManClick=false; for (i=;i<;i++){
//找到被吃的棋子
if (me.getSource().equals(play[i])){
//该红棋吃棋的时候
if (chessPlayClick == && play[Man].getName().charAt() == ''){
Ex = play[Man].getX();
Ey = play[Man].getY(); //卒、兵吃规则
if (Man > && Man < ){
rule.armsRule(play[Man],play[i]);
} //炮吃规则
else if (Man > && Man < ){
rule.cannonRule(,play[Man],play[i],play,me);
} //车吃规则
else if (Man >= && Man < ){
rule.cannonRule(,play[Man],play[i],play,me);
} //马吃规则
else if (Man > && Man < ){
rule.horseRule(play[Man],play[i],play,me);
} //相、象吃规则
else if (Man > && Man < ){
rule.elephantRule(play[Man],play[i],play);
} //士、仕吃棋规则
else if (Man > && Man < ){
rule.chapRule(Man,play[Man],play[i],play);
} //将、帅吃棋规则
else if (Man == || Man == ){
rule.willRule(Man,play[Man],play[i],play);
play[Man].setVisible(true);
} //是否走棋错误(是否在原地没有动)
if (Ex == play[Man].getX() && Ey == play[Man].getY()){
text.setText(" 红棋走棋");
chessPlayClick=;
break;
} else{
text.setText(" 黑棋走棋");
chessPlayClick=;
break;
} }//if //该黑棋吃棋的时候
else if (chessPlayClick == && play[Man].getName().charAt() == ''){
Ex = play[Man].getX();
Ey = play[Man].getY(); //卒吃规则
if (Man > && Man < ){
rule.armsRule(play[Man],play[i]);
} //炮吃规则
else if (Man > && Man < ){
rule.cannonRule(,play[Man],play[i],play,me);
} //车吃规则
else if (Man >= && Man < ){
rule.cannonRule(,play[Man],play[i],play,me);
} //马吃规则
else if (Man > && Man < ){
rule.horseRule(play[Man],play[i],play,me);
} //相、象吃规则
else if (Man > && Man < ){
rule.elephantRule(play[Man],play[i],play);
} //士、仕吃棋规则
else if (Man > && Man < ){
rule.chapRule(Man,play[Man],play[i],play);
} //将、帅吃棋规则
else if (Man == || Man == ){
rule.willRule(Man,play[Man],play[i],play);
play[Man].setVisible(true);
} //是否走棋错误(是否在原地没有动)
if (Ex == play[Man].getX() && Ey == play[Man].getY()){
text.setText(" 黑棋走棋");
chessPlayClick=;
break;
} else {
text.setText(" 红棋走棋");
chessPlayClick=;
break;
} }//else if }//if }//for //是否胜利
if (!play[].isVisible()){
JOptionPane.showConfirmDialog(
this,"黑棋胜利","玩家一胜利",
JOptionPane.DEFAULT_OPTION,JOptionPane.WARNING_MESSAGE);
//双方都不可以在走棋了
chessPlayClick=;
text.setText(" 黑棋胜利"); }//if else if (!play[].isVisible()){
JOptionPane.showConfirmDialog(
this,"红棋胜利","玩家二胜利",
JOptionPane.DEFAULT_OPTION,JOptionPane.WARNING_MESSAGE);
chessPlayClick=;
text.setText(" 红棋胜利");
}//else if }//else }//else }
上一篇:nginx学习之简化安装篇(一)


下一篇:个人小爱好:Operating System: three easy pieces第6章第5节——总结