int CheckDownBorder(chess_data Chess) {
int x,y;
for (y=0;y<=3;y++) for (x=0;x<=3;x++) {
if (Chess.data[x][y]) {
if (Chess.xy.Y+y+1>=CHESS_Y+CHESS_HIGHT) {
return 1; } } }
return 0; }
//检测下方向是否有棋子存在
int CheckDownChess(chess_data Chess) {
int x,y;
for (y=0;y<=3;y++) for (x=0;x<=3;x++) {
if (Chess.data[x][y]) { if
(ChessBoard[(Chess.xy.X-CHESS_X)/2+x][Chess.xy.Y-CHESS_Y+y+1]) //12*18
{
return 1; } } }
31
}
return 0;
//假设向左移一格,是否会产生碰撞,如果有,则返回1 否则返回0 int CheckLeftChess(chess_data Chess) {
int x,y;
for (y=0;y<=3;y++) for (x=0;x<=3;x++) {
if (Chess.data[x][y]) { if
(ChessBoard[(Chess.xy.X-CHESS_X)/2+x-1][Chess.xy.Y-CHESS_Y+y]) //12*18
{
return 1; } } }
return 0; }
//假设向右移一格,是否会产生碰撞,如果有,则返回1 否则返回0 int CheckRightChess(chess_data Chess) {
int x,y;
for (y=0;y<=3;y++) for (x=0;x<=3;x++) {
if (Chess.data[x][y]) { if
(ChessBoard[(Chess.xy.X-CHESS_X)/2+x+1][Chess.xy.Y-CHESS_Y+y
32
]) //12*18
{
return 1; } } }
return 0; }
//旋转冲突检测
int CheckSpinBorder(chess_data chess) { int x,y,ty;
chess_data NextChess;
//取得旋转后的棋子数据 NextChess=chess;//xy,rx,ry //取得旋转后棋子数据data
//NextChess.data=DownChessData[chess.rx][chess.ry].data; if (chess.ry==3) {
ty=0; }else {
ty=chess.ry+1; }
memcpy(NextChess.data,DownChessData[chess.rx][ty].data,4*4*sizeof(char));
//检测边界冲突
for (x=0;x<=3;x++) for (y=0;y<=3;y++) {
if (NextChess.data[x][y]) {
if (NextChess.xy.X+x<=CHESS_X+2)
33
{
return 1; } //
if (NextChess.xy.X+x>=CHESS_X+CHESS_WIDTH-4)//{
return 1; } //
if (NextChess.xy.Y+y+1>=CHESS_Y+CHESS_HIGHT) {
return 1; }
//检测与棋盘数据的冲突
左边界│占2字符宽度+右边界│占的2个字符宽度所以得减4
if
(ChessBoard[(NextChess.xy.X-CHESS_X)/2+x][NextChess.xy.Y-CHESS_Y+y]) //12*18 {
return 1; } } }
return 0; }
//检测ChessBoard 里边是否有一行是全1 是返回这一行的下标,否则返回 -1
int CheckRowAllOne() {
int x,y; int num=0;
for ( y=17;y>=0;y--) {
34
num=0; //归零初始化
for (x=0;x<=11;x++) //行是否全1
{
if (ChessBoard[x][y]) {
num++; } }
if (num>=11) {
return y; } }
return -1; }
//ClearRow
int ClearRow(int rowY) { int x,y;
for (x=1;x<=11;x++) //行是否全1
{
ChessBoard[x][rowY]=0;
gotoxy(CHESS_X+x*2,CHESS_Y+rowY); prt(\ \}
//下移所有的行 for (y=rowY;y>=1;y--) {
for (x=1;x<11;x++) {
35