JAVA课程设计黑白棋源代码 第7页


       //System.out.println("吃掉己方2颗棋子中间的对方棋子");
       Chess[i - n - 1][j].setText(mychess);//吃掉己方2颗棋子中间的对方棋子
       n++;
      }
      ChessCheck3 = true;
      break;
     }
     else { ChessCheck3 = false; }//如果不是己方棋子,继续寻找
    }
   }
   //检查下方
   System.out.println("检查下方");
   if (Chess[i + 1][j].getText() != yourchess) {
    //System.out.println("下方边第一个是我的棋子");
    ChessCheck4 = false; }
   else
   {//向右移动找出是否有自己的棋子,如果有则吃掉对方的子,否则返回false
    //System.out.println("向下移动找出是否有自己的棋子,如果有则吃掉对方的子,否则返回false");
    for (int m = 1; m < Max - i - 1; m++)
    {
     if (Chess[i + 1 + m][j].getText() == mychess)//如果是己方棋子
     {
      //System.out.println("如果是己方棋子");
      int n = 1;
      while (n <= m)
      {
       //System.out.println("吃掉己方2颗棋子中间的对方棋子");
       Chess[i + n][j].setText(mychess);//吃掉己方2颗棋子中间的对方棋子
       n++;
      }
      ChessCheck4 = true;
      break;
     }
     else { ChessCheck4 = false; }//如果不是己方棋子,继续寻找
    }
   }
   //上面已经完成对水平和垂直方向的检查过程,下面开始是些对角方向的检查
   //检查右上角
   System.out.println("检查右上角");
   if (Chess[i - 1][j + 1].getText() != yourchess) {
    //System.out.println("右上角第一个是我的棋子");
    ChessCheck5 = false; }
   else
   {//向右上移动找出是否有自己的棋子,如果有则吃掉对方的子,否则返回false
    //System.out.println("向右上移动找出是否有自己的棋子,如果有则吃掉对方的子,否则返回false");
    int x = Max - j; int y = i; int m = 1; int tj;
    if (x > y) { tj = y - 2; } else { tj = x - 2; }
    while (m <= tj)
    {
     //System.out.println("寻找棋子" + m + tj);
     if (Chess[i - m - 1][j + 1 + m].getText() == mychess)//如果是己方棋子
     {
      //System.out.println("如果是己方棋子" + Chess[i - m - 1][j + 1 + m].getText());
      int n = 1;
      while (n <= m)
      {
       //System.out.println("吃掉己方2颗棋子中间的对方棋子");
       Chess[i - n][j + n].setText(mychess);//吃掉己方2颗棋子中间的对方棋子
       n++;
      }
      ChessCheck5 = true;
      break;
     }
     else { ChessCheck5 = false; }//如果不是己方棋子,继续寻找
     m++;
    }
   }
   //右下角
   System.out.println("检查右下角");
   if (Chess[i + 1][j + 1].getText() != yourchess) {
    //System.out.println("右下角第一个是我的棋子");
    ChessCheck6 = false; }
   else
   {//向右下移动找出是否有自己的棋子,如果有则吃掉对方的子,否则返回false
    //System.out.println("向右下移动找出是否有自己的棋子,如果有则吃掉对方的子,否则返回false");
    int m = 1; int tj;
    if (i > j) { tj = Max - i - 2; } else { tj = Max - j - 2; }
    while (m <= tj)
    {
     //System.out.println("寻找棋子" + m + tj);
     if (Chess[i + m + 1][j + 1 + m].getText() == mychess)//如果是己方棋子
     {
      //System.out.println("如果是己方棋子" + Chess[i + m + 1][j + 1 + m].getText());
      int n = 1;
      while (n <= m)
      {
       //System.out.println("吃掉己方2颗棋子中间的对方棋子");
       Chess[i + n][j + n].setText(mychess);//吃掉己方2颗棋子中间的对方棋子
       n++;
      }
      ChessCheck6 = true;
      break;
     }
     else { ChessCheck6 = false; }//如果不是己方棋子,继续寻找
     m++;
    }

上一页  [1] [2] [3] [4] [5] [6] [7] [8] 下一页

Copyright © 2007-2012 www.chuibin.com 六维论文网 版权所有