📄 main.c
字号:
//syslog(LOG_INFO,"OnTimer:Created a new square!"); //syslog(LOG_INFO,"Type:%d,Dir:%d,poOrigin:%d,%d",pMovingSquare->iType,pMovingSquare->iDir,pMovingSquare->poOrigin.x,pMovingSquare->poOrigin.y); if(!MoveSquare(pPlayingWindow,ACTION_PUTIN)){ //No where to put the created square,die. pPlayingWindow->bDead = TRUE; UpdateHighScore(hWnd,pPlayingWindow); rect1.left=0; rect1.right=0; rect1.top=0; rect1.bottom=0; ConvertRectCord(hWnd,iWhich,&rect1); InvalidateRect(hWnd,&rect1,TRUE); return; } if(WillNotTouch(pPlayingWindow)){ //A successful initialize. //rect1.left=pMovingSquare->poOrigin.x; //rect1.right=rect1.left+pMovingSquare->poRightBottom.x; //rect1.top=pMovingSquare->poOrigin.y; //rect1.bottom=rect1.top+pMovingSquare->poRightBottom.y; rect1.left = 0; rect1.right = 0; rect1.top = 0; rect1.bottom = 0; ConvertRectCord(hWnd,iWhich,&rect1); InvalidateRect(hWnd,&rect1,TRUE); return; } //Touch the bottom!! put it in the square. PutSquare(pPlayingWindow); //Can remove at least one line,live..... if(RemoveFullLines(pPlayingWindow,iWhich)>0){ rect1.left=0; rect1.right=0; rect1.top=0; rect1.bottom=0; ConvertRectCord(hWnd,iWhich,&rect1); InvalidateRect(hWnd,&rect1,TRUE); return; } //can not,die.... pPlayingWindow->bDead = TRUE; UpdateHighScore(hWnd,pPlayingWindow); rect1.left=0; rect1.right=0; rect1.top=0; rect1.bottom=0; ConvertRectCord(hWnd,iWhich,&rect1); InvalidateRect(hWnd,&rect1,TRUE); return; } //if there exist one,move down one step. //possible case: //1.simple move down //2.move down and find touch one brick.kill the moving square. if(WillNotTouch(pPlayingWindow)){ //simple move down pMovingSquare = pPlayingWindow->pMovingSquare; pMovingSquare->poOrigin.y += 1; rect1.left=pMovingSquare->poOrigin.x; rect1.top=pMovingSquare->poOrigin.y-1; rect1.right=rect1.left+pMovingSquare->poRightBottom.x+1; rect1.bottom=rect1.top+pMovingSquare->poRightBottom.y+2; //rect1.left = 0; //rect1.top = 0; //rect1.right = 0; //rect1.bottom = 0; //syslog(LOG_INFO,"OnTimer:rect1:L:%d,R:%d,T:%d,B:%d",rect1.left, // rect1.right,rect1.top,rect1.bottom); ConvertRectCord(hWnd,iWhich,&rect1); InvalidateRect(hWnd,&rect1,TRUE); return; } //Touch the bottom!! put it in the square. PutSquare(pPlayingWindow); iScoreBefore = (pPlayingWindow->iScore)%DIFFICULTY_HOP; iLines = RemoveFullLines(pPlayingWindow,iWhich); if(iLines){ iScoreAfter = (pPlayingWindow->iScore)%DIFFICULTY_HOP; if(iScoreBefore > iScoreAfter){ pPlayingWindow->iLevel = (pPlayingWindow->iLevel + 1); if(pPlayingWindow->iLevel>9) pPlayingWindow->iLevel = 9; if(iWhich == 1)#ifdef _TIMER_UNIT_10MS SetTimerSpeed(hWnd,RUSSIA_SQUARE_TIMER1,1000/TimerFreq[pPlayingWindow->iLevel]);#else SetTimerSpeed(hWnd,RUSSIA_SQUARE_TIMER1,TimerFreq[pPlayingWindow->iLevel]);#endif else#ifdef _TIMER_UNIT_10MS SetTimerSpeed(hWnd,RUSSIA_SQUARE_TIMER2,1000/TimerFreq[pPlayingWindow->iLevel]);#else SetTimerSpeed(hWnd,RUSSIA_SQUARE_TIMER2,TimerFreq[pPlayingWindow->iLevel]);#endif } if(iLines>=2) InvalidateRect(hWnd,NULL,TRUE); } rect1.left=0; rect1.right=0; rect1.top=0; rect1.bottom=0; ConvertRectCord(hWnd,iWhich,&rect1); InvalidateRect(hWnd,&rect1,TRUE); return;}//first: Decide wheather can we move.//if can ,then//second: Move the square.BOOL MoveSquareLong(PlayingWindow * pPlayingWindow,int iAction){ MovingSquare *pMovingSquare; POINT *pPoint; if(iAction == ACTION_INIT) pMovingSquare = pPlayingWindow->pPreCreatedSquare; else pMovingSquare = pPlayingWindow->pMovingSquare; pPoint = &pMovingSquare->poOrigin; switch(pMovingSquare->iDir){ case DIR_UP: case DIR_DOWN: switch(iAction){ case ACTION_INIT: pMovingSquare = pPlayingWindow->pPreCreatedSquare; pMovingSquare->poRightBottom.y = 3; pMovingSquare->poRightBottom.x = 0; pMovingSquare->poAll[0].x=0; pMovingSquare->poAll[0].y=0; pMovingSquare->poAll[1].x=0; pMovingSquare->poAll[1].y=1; pMovingSquare->poAll[2].x=0; pMovingSquare->poAll[2].y=2; pMovingSquare->poAll[3].x=0; pMovingSquare->poAll[3].y=3; break; case ACTION_PUTIN: if(!TestPosition(pPlayingWindow,pPoint->y,pPoint->x)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+1,pPoint->x)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+2,pPoint->x)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+3,pPoint->x)) return FALSE; break; case ACTION_LEFT: if(!TestPosition(pPlayingWindow,pPoint->y,pPoint->x-1)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+1,pPoint->x-1)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+2,pPoint->x-1)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+3,pPoint->x-1)) return FALSE; pPoint->x -=1; break; case ACTION_RIGHT: if(!TestPosition(pPlayingWindow,pPoint->y,pPoint->x+1)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+1,pPoint->x+1)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+2,pPoint->x+1)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+3,pPoint->x+1)) return FALSE; pPoint->x +=1; break; case ACTION_ROTATE: if(!TestPosition(pPlayingWindow,pPoint->y,pPoint->x+1)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+1,pPoint->x-1)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+1,pPoint->x+1)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+1,pPoint->x+2)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+2,pPoint->x-1)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+3,pPoint->x-1)) return FALSE; pPoint->x -=1; pPoint->y +=1; pMovingSquare->iDir = DIR_LEFT; pMovingSquare->poRightBottom.y = 0; pMovingSquare->poRightBottom.x = 3; pMovingSquare->poAll[0].x=0; pMovingSquare->poAll[0].y=0; pMovingSquare->poAll[1].x=1; pMovingSquare->poAll[1].y=0; pMovingSquare->poAll[2].x=2; pMovingSquare->poAll[2].y=0; pMovingSquare->poAll[3].x=3; pMovingSquare->poAll[3].y=0; break; case ACTION_DOWN: while(TRUE){ if(!TestPosition(pPlayingWindow,pPoint->y+4,pPoint->x)) return FALSE; pPoint->y +=1; } break; } break; case DIR_LEFT: case DIR_RIGHT: switch(iAction){ case ACTION_INIT: pMovingSquare = pPlayingWindow->pPreCreatedSquare; pMovingSquare->poRightBottom.y = 0; pMovingSquare->poRightBottom.x = 3; pMovingSquare->poAll[0].x=0; pMovingSquare->poAll[0].y=0; pMovingSquare->poAll[1].x=1; pMovingSquare->poAll[1].y=0; pMovingSquare->poAll[2].x=2; pMovingSquare->poAll[2].y=0; pMovingSquare->poAll[3].x=3; pMovingSquare->poAll[3].y=0; break; case ACTION_PUTIN: if(!TestPosition(pPlayingWindow,pPoint->y,pPoint->x)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y,pPoint->x+1)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y,pPoint->x+2)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y,pPoint->x+3)) return FALSE; break; case ACTION_LEFT: if(!TestPosition(pPlayingWindow,pPoint->y,pPoint->x-1)) return FALSE; pPoint->x -=1; break; case ACTION_RIGHT: if(!TestPosition(pPlayingWindow,pPoint->y,pPoint->x+4)) return FALSE; pPoint->x +=1; break; case ACTION_ROTATE: if(!TestPosition(pPlayingWindow,pPoint->y-1,pPoint->x)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y-1,pPoint->x+1)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+1,pPoint->x+1)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+2,pPoint->x+1)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+1,pPoint->x+2)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+2,pPoint->x+2)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+1,pPoint->x+3)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+2,pPoint->x+3)) return FALSE; pPoint->x +=1; pPoint->y -=1; pMovingSquare->iDir = DIR_UP; pMovingSquare->poRightBottom.y = 3; pMovingSquare->poRightBottom.x = 0; pMovingSquare->poAll[0].x=0; pMovingSquare->poAll[0].y=0; pMovingSquare->poAll[1].x=0; pMovingSquare->poAll[1].y=1; pMovingSquare->poAll[2].x=0; pMovingSquare->poAll[2].y=2; pMovingSquare->poAll[3].x=0; pMovingSquare->poAll[3].y=3; break; case ACTION_DOWN: while(TRUE){ if(!TestPosition(pPlayingWindow,pPoint->y+1,pPoint->x)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+1,pPoint->x+1)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+1,pPoint->x+2)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+1,pPoint->x+3)) return FALSE; pPoint->y +=1; } break; } break; } return TRUE;} BOOL MoveSquareSquare(PlayingWindow * pPlayingWindow,int iAction){ MovingSquare *pMovingSquare; POINT *pPoint; if(iAction == ACTION_INIT) pMovingSquare = pPlayingWindow->pPreCreatedSquare; else pMovingSquare = pPlayingWindow->pMovingSquare; pPoint = &pMovingSquare->poOrigin; switch(iAction){ case ACTION_INIT: pMovingSquare->poRightBottom.y = 1; pMovingSquare->poRightBottom.x = 1; pMovingSquare->poAll[0].x=0; pMovingSquare->poAll[0].y=0; pMovingSquare->poAll[1].x=1; pMovingSquare->poAll[1].y=0; pMovingSquare->poAll[2].x=0; pMovingSquare->poAll[2].y=1; pMovingSquare->poAll[3].x=1; pMovingSquare->poAll[3].y=1; break; case ACTION_PUTIN: if(!TestPosition(pPlayingWindow,pPoint->y,pPoint->x)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+1,pPoint->x)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y,pPoint->x+1)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+1,pPoint->x+1)) return FALSE; break; case ACTION_LEFT: if(!TestPosition(pPlayingWindow,pPoint->y,pPoint->x-1)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+1,pPoint->x-1)) return FALSE; pPoint->x -=1; break; case ACTION_RIGHT: if(!TestPosition(pPlayingWindow,pPoint->y,pPoint->x+2)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+1,pPoint->x+2)) return FALSE; pPoint->x +=1; break; case ACTION_ROTATE: break; case ACTION_DOWN: while(TRUE){ if(!TestPosition(pPlayingWindow,pPoint->y+2,pPoint->x)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+2,pPoint->x+1)) return FALSE; pPoint->y +=1; } break; } return TRUE;}BOOL MoveSquareLeftDuck(PlayingWindow * pPlayingWindow,int iAction){ MovingSquare *pMovingSquare; POINT *pPoint; if(iAction == ACTION_INIT) pMovingSquare = pPlayingWindow->pPreCreatedSquare; else pMovingSquare = pPlayingWindow->pMovingSquare; pPoint = &pMovingSquare->poOrigin; switch(pMovingSquare->iDir){ case DIR_UP: case DIR_DOWN: switch(iAction){ case ACTION_INIT: pMovingSquare->poRightBottom.y = 2; pMovingSquare->poRightBottom.x = 1; pMovingSquare->poAll[0].x=1; pMovingSquare->poAll[0].y=0; pMovingSquare->poAll[1].x=0; pMovingSquare->poAll[1].y=1; pMovingSquare->poAll[2].x=1; pMovingSquare->poAll[2].y=1; pMovingSquare->poAll[3].x=0; pMovingSquare->poAll[3].y=2; break; case ACTION_PUTIN: if(!TestPosition(pPlayingWindow,pPoint->y,pPoint->x+1)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+1,pPoint->x)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+1,pPoint->x+1)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+2,pPoint->x)) return FALSE; break; case ACTION_LEFT: if(!TestPosition(pPlayingWindow,pPoint->y,pPoint->x)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+1,pPoint->x-1)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+2,pPoint->x-1)) return FALSE; pPoint->x -=1; break; case ACTION_RIGHT: if(!TestPosition(pPlayingWindow,pPoint->y,pPoint->x+2)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+1,pPoint->x+2)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y+2,pPoint->x+1)) return FALSE; pPoint->x +=1; break; case ACTION_ROTATE: if(!TestPosition(pPlayingWindow,pPoint->y,pPoint->x)) return FALSE; if(!TestPosition(pPlayingWindow,pPoint->y
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -