Exemple #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;
       }
     }
   }
 }
Exemple #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;
       }
     }
   }
 }
Exemple #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;
       }
     }
   }
 }
Exemple #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;
       }
     }
   }
 }
Exemple #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;
       }
     }
   }
 }
Exemple #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;
       }
     }
   }
 }
Exemple #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;
       }
     }
   }
 }
Exemple #8
0
  public int Clicked(ChessBoard cel) {
    int judge = 0;
    int r = cel.getRow();
    int c = cel.getColumn();
    System.out.println("落子前:" + cell[3][5].taken);

    if (gameStart) {
      if (cel.taken == false) {
        Check(cel);
      }
      System.out.println(cell[3][5].taken);
      System.out.println(can);
      if (can && cel.taken == false) {
        /*for (int i = 0; i < 8; i++)
        for (int j = 0; j < 8; j++)
        if (cell[i][j].changed == true)
        {
        	cell[i][j].ChangeBack();
        }*/
        RememberState();
        ShowChessNumber();
        list.add(cel);
        JudgeWhoIsWinner();
        turn = TakeTurn();
        cel.taken = true;
        System.out.println("落子后:" + cell[3][5].taken);
        can = false;
        judge = 1;
        for (int i = 0; i < 8; i++)
          for (int j = 0; j < 8; j++)
            if (cell[i][j].changed) {
              cell[i][j].ChangeBack();
            }

        boolean flag = CheckAll();
        if (!flag && white + black < 64) CheckAtTheEnd();
        /*else
        {
        	for (int i = 0; i < 8; i++)
        	for (int j = 0; j < 8; j++)
        	if (cell[i][j].taken == false)
        	{
        		CheckPlace(cell[i][j]);
        		if (canPut)
        		{
        			cell[i][j].ChangeBackground();
        			canPut = false;
        		}
        	}
        }*/
      } else {
        JOptionPane.showMessageDialog(null, "无法在该位置落子");
        judge = 0;
        System.out.println(cell[3][5].taken);
      }
      return judge;
    } else {
      JOptionPane.showMessageDialog(null, "游戏还未开始或已结束");
      return 0;
    }
  }
Exemple #9
0
  public void CheckPlace(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) {
          canPut = true;
          return;
        } else {
          if (cell[i][c].state == ' ') break;
          else continue;
        }
      }
    }

    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) {
          canPut = true;
          return;
        } else {
          if (cell[i][c].state == ' ') break;
          else continue;
        }
      }
    }

    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) {
          canPut = true;
          return;
        } else {
          if (cell[r][i].state == ' ') break;
          else continue;
        }
      }
    }

    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) {
          canPut = true;
          return;
        } else {
          if (cell[r][i].state == ' ') break;
          else continue;
        }
      }
    }

    if (c - 1 >= 0
        && r - 1 >= 0
        && cell[r - 1][c - 1].state != ' '
        && cell[r - 1][c - 1].state != turn) {
      for (int i = 2; (r - i) >= 0 && (c - i) >= 0; i++) {
        if (cell[r - i][c - i].state == turn) {
          canPut = true;
          return;
        } else {
          if (cell[r - i][c - i].state == ' ') break;
          else continue;
        }
      }
    }

    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) {
          canPut = true;
          return;
        } else {
          if (cell[r + i][c - i].state == ' ') break;
          else continue;
        }
      }
    }

    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) {
          canPut = true;
          return;
        } else {
          if (r - i >= 0 && c + i < 8 && cell[r - i][c + i].state == ' ') break;
          else continue;
        }
      }
    }

    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) {
          canPut = true;
          return;
        } else {
          if (cell[r + i][c + i].state == ' ') break;
          else continue;
        }
      }
    }
  }