russia.c
来自「minigui PDA系统 可实现手机功能」· C语言 代码 · 共 2,258 行 · 第 1/5 页
C
2,258 行
//first draw the static bricks,then draw the moving square. pMovingSquare = pPlayingWindow->pPreCreatedSquare; if(pMovingSquare){ poStart1.x = poStart.x+(6+ pMovingSquare->poAll[0].x)*iSideLength; poStart1.y = poStart.y+(0+ pMovingSquare->poAll[0].y)*iSideLength; DrawLittleBrick(hDC,hWnd,poStart1,iSideLength,pMovingSquare->iType); poStart1.x = poStart.x+(6+ pMovingSquare->poAll[1].x)*iSideLength; poStart1.y = poStart.y+(0+ pMovingSquare->poAll[1].y)*iSideLength; DrawLittleBrick(hDC,hWnd,poStart1,iSideLength,pMovingSquare->iType); poStart1.x = poStart.x+(6+ pMovingSquare->poAll[2].x)*iSideLength; poStart1.y = poStart.y+(0+ pMovingSquare->poAll[2].y)*iSideLength; DrawLittleBrick(hDC,hWnd,poStart1,iSideLength,pMovingSquare->iType); poStart1.x = poStart.x+(6+ pMovingSquare->poAll[3].x)*iSideLength; poStart1.y = poStart.y+(0+ pMovingSquare->poAll[3].y)*iSideLength; DrawLittleBrick(hDC,hWnd,poStart1,iSideLength,pMovingSquare->iType); } poStart.y += 4*iSideLength; for(i=RUSSIA_SQUARE_HEIGHT-1;i>=0;i--) { bMeetBrick = FALSE; for(j=0;j<RUSSIA_SQUARE_WIDTH;j++) if(pPlayingWindow->iStateMatrix[i][j]) { poStart1.x = poStart.x+j*iSideLength; poStart1.y = poStart.y+i*iSideLength; DrawLittleBrick(hDC,hWnd,poStart1,iSideLength,\ pPlayingWindow->iStateMatrix[i][j]); bMeetBrick = TRUE; } } pMovingSquare = pPlayingWindow->pMovingSquare; if(pMovingSquare){ poStart1.x = poStart.x+(pMovingSquare->poOrigin.x+ pMovingSquare->poAll[0].x)*iSideLength; poStart1.y = poStart.y+(pMovingSquare->poOrigin.y+ pMovingSquare->poAll[0].y)*iSideLength; DrawLittleBrick(hDC,hWnd,poStart1,iSideLength,pMovingSquare->iType); poStart1.x = poStart.x+(pMovingSquare->poOrigin.x+ pMovingSquare->poAll[1].x)*iSideLength; poStart1.y = poStart.y+(pMovingSquare->poOrigin.y+ pMovingSquare->poAll[1].y)*iSideLength; DrawLittleBrick(hDC,hWnd,poStart1,iSideLength,pMovingSquare->iType); poStart1.x = poStart.x+(pMovingSquare->poOrigin.x+ pMovingSquare->poAll[2].x)*iSideLength; poStart1.y = poStart.y+(pMovingSquare->poOrigin.y+ pMovingSquare->poAll[2].y)*iSideLength; DrawLittleBrick(hDC,hWnd,poStart1,iSideLength,pMovingSquare->iType); poStart1.x = poStart.x+(pMovingSquare->poOrigin.x+ pMovingSquare->poAll[3].x)*iSideLength; poStart1.y = poStart.y+(pMovingSquare->poOrigin.y+ pMovingSquare->poAll[3].y)*iSideLength; DrawLittleBrick(hDC,hWnd,poStart1,iSideLength,pMovingSquare->iType); }}void DrawLittleBrick(HDC hDC, HWND hWnd, POINT poStart,int iSideLength,int iType){ gal_pixel iColor; iColor = COLOR_green; switch(iType) { case SQUARE_LONG: iColor = COLOR_green; break; case SQUARE_SQUARE: iColor = COLOR_lightgray; break; case SQUARE_HILL: iColor = COLOR_red; break; case SQUARE_LEFT_DUCK: iColor = COLOR_yellow; break; case SQUARE_RIGHT_DUCK: iColor = COLOR_blue; break; case SQUARE_LEFT_CHAIR: iColor = COLOR_magenta; break; case SQUARE_RIGHT_CHAIR: iColor = COLOR_cyan; break; } Draw3DUpThickFrame (hDC,poStart.x,poStart.y,poStart.x+iSideLength, poStart.y+iSideLength,iColor);}//处理键盘左方向BOOL OnLeftKeyDown(HWND hWnd,PlayingWindow *pPlayingWindow,int iWhich){ RECT rect1; assert(hWnd); if(!pPlayingWindow) return FALSE; if(!pPlayingWindow->bBegin) return FALSE; if(pPlayingWindow->bPause) return FALSE; if(pPlayingWindow->bDead) return FALSE; if(MoveSquare(pPlayingWindow,ACTION_LEFT)){ rect1.left=pPlayingWindow->pMovingSquare->poOrigin.x; rect1.top =pPlayingWindow->pMovingSquare->poOrigin.y; rect1.right = rect1.left + pPlayingWindow->pMovingSquare->poRightBottom.x+2; rect1.bottom = rect1.top + pPlayingWindow->pMovingSquare->poRightBottom.y+1; ConvertRectCord(hWnd,iWhich,&rect1); InvalidateRect(hWnd,&rect1,TRUE); } else return FALSE; return TRUE;}BOOL OnRightKeyDown(HWND hWnd,PlayingWindow *pPlayingWindow,int iWhich){ RECT rect1; assert(hWnd); if(!pPlayingWindow) return FALSE; if(!pPlayingWindow->bBegin) return 0; if(pPlayingWindow->bPause) return 0; if(pPlayingWindow->bDead) return 0; if(MoveSquare(pPlayingWindow,ACTION_RIGHT)){ rect1.left=pPlayingWindow->pMovingSquare->poOrigin.x-1; rect1.top =pPlayingWindow->pMovingSquare->poOrigin.y; rect1.right = rect1.left + pPlayingWindow->pMovingSquare->poRightBottom.x+2; rect1.bottom = rect1.top + pPlayingWindow->pMovingSquare->poRightBottom.y+1; ConvertRectCord(hWnd,iWhich,&rect1); InvalidateRect(hWnd,&rect1,TRUE); } else return FALSE; return TRUE;}BOOL OnRotateKeyDown(HWND hWnd,PlayingWindow *pPlayingWindow,int iWhich){ RECT rect1; assert(hWnd); if(!pPlayingWindow) return FALSE; if(!pPlayingWindow->bBegin) return 0; if(pPlayingWindow->bPause) return 0; if(pPlayingWindow->bDead) return 0; if(MoveSquare(pPlayingWindow,ACTION_ROTATE)){ rect1.left=pPlayingWindow->pMovingSquare->poOrigin.x-1; rect1.top =pPlayingWindow->pMovingSquare->poOrigin.y-1; rect1.right = rect1.left + 5; rect1.bottom = rect1.top + 5; //rect1.left = 0; //rect1.top = 0; //rect1.right = 0; //rect1.bottom = 0; ConvertRectCord(hWnd,iWhich,&rect1); InvalidateRect(hWnd,&rect1,TRUE); } else return FALSE; return TRUE;}BOOL OnDownKeyDown(HWND hWnd,PlayingWindow *pPlayingWindow,int iWhich){ RECT rect1; int iScoreBefore; int iScoreAfter; int iLines; assert(hWnd); if(!pPlayingWindow) return FALSE; if(!pPlayingWindow->bBegin) return 0; if(pPlayingWindow->bPause) return 0; if(pPlayingWindow->bDead) return 0; MoveSquare(pPlayingWindow,ACTION_DOWN); 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 TRUE;}BOOL OnStartKeyDown(HWND hWnd,PlayingWindow *pPlayingWindow,int iWhich){ int i,j; assert(hWnd); if(!pPlayingWindow) return FALSE; if(pPlayingWindow->bPause) return FALSE; if(theApp.bTease) return 0; //reset the struct : pMoingSquare.... if(pPlayingWindow->pMovingSquare){ free(pPlayingWindow->pMovingSquare); pPlayingWindow->pMovingSquare = NULL; free(pPlayingWindow->pPreCreatedSquare); pPlayingWindow->pPreCreatedSquare = NULL; } for(i=0;i<RUSSIA_SQUARE_HEIGHT;i++) for(j=0;j<RUSSIA_SQUARE_WIDTH;j++) pPlayingWindow->iStateMatrix[i][j] = 0; pPlayingWindow->iScore = 0; pPlayingWindow->bBegin = TRUE; pPlayingWindow->bDead = FALSE; return TRUE;}BOOL OnPauseKeyDown(HWND hWnd,PlayingWindow *pPlayingWindow,int iWhich){ RECT rect1; assert(hWnd); if(!pPlayingWindow) return FALSE;; if(!pPlayingWindow->bBegin) return FALSE; if(pPlayingWindow->bDead) return FALSE; if(theApp.bTease) return 0; if(pPlayingWindow->bPause) pPlayingWindow->bPause = FALSE; else pPlayingWindow->bPause = TRUE; rect1.left=0; rect1.right=0; rect1.top=0; rect1.bottom=0; ConvertRectCord(hWnd,iWhich,&rect1); InvalidateRect(hWnd,&rect1,!pPlayingWindow->bPause); return TRUE;}void OnTimer(HWND hWnd,PlayingWindow *pPlayingWindow,int iWhich){ RECT rect1; int iScoreBefore; int iScoreAfter; int iLines; MovingSquare * pMovingSquare ; assert(hWnd); assert(pPlayingWindow); if(!pPlayingWindow->bBegin) return; if(pPlayingWindow->bPause) return; if(pPlayingWindow->bDead) return; //if no moving square,create one. if(!pPlayingWindow->pMovingSquare){ if(!pPlayingWindow->pPreCreatedSquare){ pPlayingWindow->pPreCreatedSquare = (MovingSquare*)calloc(1,sizeof(MovingSquare)); pMovingSquare = pPlayingWindow->pPreCreatedSquare; srandom(time(NULL)+2+iWhich); pMovingSquare->iType = (rand() +2+iWhich)% 7 + 1; pMovingSquare->iDir = (rand() +2+iWhich)% 4 + 1; pMovingSquare->poOrigin.y = 0; pMovingSquare->poOrigin.x = (rand()+2+iWhich) % (RUSSIA_SQUARE_WIDTH-3); MoveSquare(pPlayingWindow,ACTION_INIT); } pPlayingWindow->pMovingSquare = pPlayingWindow->pPreCreatedSquare; pPlayingWindow->pPreCreatedSquare = (MovingSquare*)calloc(1,sizeof(MovingSquare)); pMovingSquare = pPlayingWindow->pPreCreatedSquare; srandom(time(NULL)+iWhich); pMovingSquare->iType = (rand()+iWhich) % 7 + 1; pMovingSquare->iDir = (rand()+iWhich) % 4 + 1; pMovingSquare->poOrigin.y = 0; pMovingSquare->poOrigin.x = (rand()+iWhich) % (RUSSIA_SQUARE_WIDTH-3); MoveSquare(pPlayingWindow,ACTION_INIT); 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; 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;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?