Exemplo n.º 1
0
 public void CheckRight(ChessBoard cel) {
   int r = cel.getRow();
   int c = cel.getColumn();
   if (c + 1 < 8 && cell[r][c + 1].state != ' ' && cell[r][c + 1].state != turn) {
     for (int i = c + 2; i < 8; i++) {
       if (cell[r][i].state == turn) {
         can = true;
         for (int j = c; j < i; j++) {
           cell[r][j].state = cel.state = turn;
           cell[r][j].repaint();
         }
         return;
       } else {
         if (cell[r][i].state == ' ') break;
         else continue;
       }
     }
   }
 }
Exemplo n.º 2
0
 public void CheckLeft(ChessBoard cel) {
   int r = cel.getRow();
   int c = cel.getColumn();
   if (c - 1 >= 0 && cell[r][c - 1].state != ' ' && cell[r][c - 1].state != turn) {
     for (int i = c - 2; i >= 0; i--) {
       if (cell[r][i].state == turn) {
         can = true;
         for (int j = i + 1; j <= c; j++) {
           cell[r][j].state = cel.state = turn;
           cell[r][j].repaint();
         }
         return;
       } else {
         if (cell[r][i].state == ' ') break;
         else continue;
       }
     }
   }
 }
Exemplo n.º 3
0
 public void CheckDown(ChessBoard cel) {
   int r = cel.getRow();
   int c = cel.getColumn();
   if (r + 1 < 8 && cell[r + 1][c].state != ' ' && cell[r + 1][c].state != turn) {
     for (int i = r + 2; i < 8; i++) {
       if (cell[i][c].state == turn) {
         can = true;
         for (int j = r; j < i; j++) {
           cell[j][c].state = cel.state = turn;
           cell[j][c].repaint();
         }
         return;
       } else {
         if (cell[i][c].state == ' ') break;
         else continue;
       }
     }
   }
 }
Exemplo n.º 4
0
 public void CheckUp(ChessBoard cel) {
   int r = cel.getRow();
   int c = cel.getColumn();
   if (r - 1 >= 0 && cell[r - 1][c].state != ' ' && cell[r - 1][c].state != turn) {
     for (int i = r - 2; i >= 0; i--) {
       if (cell[i][c].state == turn) {
         can = true;
         for (int j = r; j > i; j--) {
           cell[j][c].state = cel.state = turn;
           cell[j][c].repaint();
         }
         return;
       } else {
         if (cell[i][c].state == ' ') break;
         else continue;
       }
     }
   }
 }
Exemplo n.º 5
0
 public void CheckRightDown(ChessBoard cel) {
   int r = cel.getRow();
   int c = cel.getColumn();
   if (r + 1 < 8
       && c + 1 < 8
       && cell[r + 1][c + 1].state != ' '
       && cell[r + 1][c + 1].state != turn) {
     for (int i = 2; (i + r) < 8 && (i + c) < 8; i++) {
       if (r + i < 8 && c + i < 8 && cell[i + r][c + i].state == turn) {
         can = true;
         for (int j = 0; j < i; j++) {
           cell[r + j][c + j].state = cel.state = turn;
           cell[r + j][c + j].repaint();
         }
         return;
       } else {
         if (cell[r + i][c + i].state == ' ') break;
         else continue;
       }
     }
   }
 }
Exemplo n.º 6
0
 public void CheckRightUp(ChessBoard cel) {
   int r = cel.getRow();
   int c = cel.getColumn();
   if (r - 1 >= 0
       && c + 1 < 8
       && cell[r - 1][c + 1].state != ' '
       && cell[r - 1][c + 1].state != turn) {
     for (int i = 2; (r - 2) >= 0 && (c + i) < 8; i++) {
       if (r - i >= 0 && c + i < 8 && cell[r - i][c + i].state == turn) {
         can = true;
         for (int j = 0; j < i; j++) {
           cell[r - j][c + j].state = cel.state = turn;
           cell[r - j][c + j].repaint();
         }
         return;
       } else {
         if (r - i >= 0 && c + i < 8 && cell[r - i][c + i].state == ' ') break;
         else continue;
       }
     }
   }
 }
Exemplo n.º 7
0
 public void CheckLeftDown(ChessBoard cel) {
   int r = cel.getRow();
   int c = cel.getColumn();
   if (r + 1 < 8
       && c - 1 >= 0
       && cell[r + 1][c - 1].state != ' '
       && cell[r + 1][c - 1].state != turn) {
     for (int i = 2; (r + i) < 8 && (c - i) >= 0; i++) {
       if (r + i < 8 && c - i >= 0 && cell[r + i][c - i].state == turn) {
         can = true;
         for (int j = 0; j < i; j++) {
           cell[r + j][c - j].state = cel.state = turn;
           cell[r + j][c - j].repaint();
         }
         return;
       } else {
         if (cell[r + i][c - i].state == ' ') break;
         else continue;
       }
     }
   }
 }