本文整理汇总了C++中Chess::setErrorCode方法的典型用法代码示例。如果您正苦于以下问题:C++ Chess::setErrorCode方法的具体用法?C++ Chess::setErrorCode怎么用?C++ Chess::setErrorCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chess
的用法示例。
在下文中一共展示了Chess::setErrorCode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: areSquaresLegal
//------------------------------------------------------------------------------
bool RookPiece::areSquaresLegal(int src_row, int src_col,
int dest_row, int dest_col,
Piece* game_area[8][8], Chess& game_control)
{
if(src_row == dest_row)
{
// be sure that all squares are empty
int col_offset = (dest_col - src_col > 0) ? 1 : -1;
for(int check_col = src_col + col_offset; check_col != dest_col;
check_col += col_offset)
{
// check if the coordinates are valid
if((check_col < 0 || check_col > 7))
{
return false;
}
if(game_area[src_row][check_col] != NULL)
{
game_control.setErrorCode(ERROR_PIECE_ON_WAY);
return false;
}
}
return true;
}
else if(dest_col == src_col)
{
int row_offset = (dest_row - src_row > 0) ? 1 : -1;
for(int check_row = src_row + row_offset; check_row != dest_row;
check_row += row_offset)
{
// check if the coordinates are valid
if((check_row < 0 || check_row > 7))
{
return false;
}
if(game_area[check_row][src_col] != NULL)
{
game_control.setErrorCode(ERROR_PIECE_ON_WAY);
return false;
}
}
return true;
}
return false;
}
示例2: isMoveValid
//------------------------------------------------------------------------------
bool Piece::isMoveValid(int src_row, int src_col,
int dest_row, int dest_col,
Piece* game_area[8][8], Chess& game_control)
{
Piece* dest_area = game_area[dest_row][dest_col];
if((dest_area == NULL) || (piece_color_ != dest_area->getColor()))
{
bool ret = areSquaresLegal(src_row, src_col, dest_row, dest_col, game_area,
game_control);
if(ret == false && game_control.getErrorCode() != ERROR_PIECE_ON_WAY)
{
game_control.setErrorCode(ERROR_TARGET_NOT_REACHABLE);
}
game_control.setPieceCaptured(false);
if((ret == true) && (dest_area != NULL) &&
(piece_color_ != dest_area->getColor()))
{
game_control.setPieceCaptured(true);
}
return ret;
}
else
{
bool ret = areSquaresLegal(src_row, src_col, dest_row,
dest_col, game_area,
game_control);
if(ret == false && game_control.getErrorCode() != ERROR_PIECE_ON_WAY)
{
game_control.setErrorCode(ERROR_TARGET_NOT_REACHABLE);
}
else
{
game_control.setErrorCode(ERROR_OWN_PIECE_ON_TARGET);
}
}
// check if the player goes to a square, where his own piece is on
// but also another piece is on the way
if((dest_area != NULL) && (piece_color_ == dest_area->getColor()))
{
areSquaresLegal(src_row, src_col, dest_row, dest_col, game_area,
game_control);
}
return false;
}