小游戲源代碼82_第1頁
小游戲源代碼82_第2頁
小游戲源代碼82_第3頁
小游戲源代碼82_第4頁
小游戲源代碼82_第5頁
已閱讀5頁,還剩50頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

************************Desc俄羅斯方塊游戲yhoodlum*Date:22:30***********************/#include<>#include<>#include<>#include<>#include<>#include<>#definetrue1#definefalse0#defineBoardWidth12defineBoardHeight23defineINNERHELPERinnerhelpermethod*/esDefine{upwardarrow*/TCEthedatastructureoftheblock*/k{charc[4][4];*/inty;/*cellfillinfoarray,0-empty,/*blockpositioncyblockcolorblocknametheblock'sshape)*/gamesglobalinfo/nextblockgridscoreboardposition/pinfortextpostionhttopemptylineeon/*ourboard,Board[x][y][0]-isFilled,Board[x][y][1]-fillColor*/unsignedcharBoardBoardWidthBoardHeight];lockcurBlockocknextBlockcurrentmovingblocknextBlocktoappear*/functionlist*/intdyrawBlockBlockblockintintintdEraseBlockBlockblockintintintisplayScoredDisplayInfochartexterateBlockBlockblockBlocktGameameGetKeyCode/{{oskey}key}displaytext*/dINNERHELPERDisplayInfochartext{nfoLeftInfoTopinfocommonnfoLeftInfoTopinfocommon}reateanewblockbykeynumbertheblockanchortothetop-leftcornerof4*4cellsINNERHELPERGenerateBlockBlockblock{keyrandomrandom+random(1000)+random(3000))%7;block->size=3;/*becausemostblocks'size=3*/memset(block->c,0,16);{blocknameT';blockcolorREDblockc][0]=1;blockc1][1]=1,block->c[2][1]=1;blockc][2]=1;case1:blocknameL';lockcolorYELLOWblockc][0]=1;blockc][1]=1;blockc1][2]=1,block->c[2][2]=1;blocknameJ';ockcolorLIGHTGRAYblockc][0]=1;blockc][1]=1;blockc1][2]=1,block->c[0][2]=1;blocknamez';lockcolorCYANblockc0][0]=1,block->c[1][0]=1;blockc1][1]=1,block->c[2][1]=1;blockname5';ockcolorLIGHTBLUEblockc1][0]=1,block->c[2][0]=1;blockc0][1]=1,block->c[1][1]=1;blocknameo';lockcolorBLUEblocksize;blockc0][0]=1,block->c[1][0]=1;blockc0][1]=1,block->c[1][1]=1;blocknameI';blockcolorGREENblocksize;blockc][0]=1;blockc][1]=1;blockc][2]=1;blockc][3]=1;}}getnextblock*/ck{copythenextBlocktocurBlock*/BoardWidth2;memcpy6);generatenextBlockandshowit*/eBlocknextBlockNBBoardLeftNBBoardTopNBCellSizerateBlocknextBlockDrawBlocknextBlockNBBoardLeftNBBoardTopNBCellSize}rotatetheblockupdatetheblockstructdata*/ccharblockSize{{ccctempccctempcaseonlyIblockarivedhere!*/}}/*judgeiftheblockcanmovetowardthedirection*/{ntrue{{{cannotmoveleftwardorrightward*/dxif(tempX<0||tempX>(BoardWidth-1))returnfalsemakesurexisvalid!*/cannotmovedownward*/dyif(tempY>(BoardHeight-1))returnfalse;yisonlycheckedlowerbound,maybenegative!!!!*/upperboundbeforecheckcell!*/if(tempY>=0&&Board[tempX][tempY][0])alse}}}}judgeiftheblockcanrotate*/{updatebuffer/memcpy(BufferCells,,16);llsBufferCells{{{XBoardWidthnfalsenfalsenfalse}}}ntrue}drawtheblock*/void_INNER_HELPERDrawBlock(Block*block,intbdLeft,intdTopintcellSize{FILLblockcolorocksizei{blocksizej{j{bdLeftcellSizeiblock->x)+cellSize/2,bdTopcellSizej+block->y)+cellSize/2,rderColor}}}}Rotatetheblockifsuccessreturntrue*/{rntrue{seBlockblockBoardLeftBoardTopCellSizememcpyBufferCells16);DrawBlockblockBoardLeftBoardTopCellSize}rnbsuccess}/*eraseablock,onlyfillthefilledcellwithbackgroundvoid_INNER_HELPEREraseBlock(Block*block,intbdLeft,intdTopintcellSize{lorocksizei{blocksizej{j{bdLeftcellSizeiblock->x)+cellSize/2,bdTopcellSizej+block->y)+cellSize/2,rderColor}}}}movebythedirectionifcandonothingifcannotntdy{{seBlockblockBoardLeftBoardTopCellSizeDrawBlockblockBoardLeftBoardTopCellSize}nbcanmove}droptheblocktothebottom!*/{seBlockblockBoardLeftBoardTopCellSizewhile(CanMove(0,1)){}rawBlockblockBoardLeftBoardTopCellSize}initthegraphicsmodedrawtheboardgrid*/itGame{drawboardcells*/memsetBoard0,BoardWidth*BoardHeight*2);memset,16);fohelpPPauseGamebyhoodlumdthi{line(BoardLeft+i*CellSize,BoardTop,BoardLeftiCellSizeBoardTopBoardHeight*CellSize);}Heighti{line(BoardLeft,BoardTop+i*CellSize,BoardLeft+BoardWidth*CellSize,BoardTop+i*CellSize);}drawboardouterborderrect*/rectangleBoardLeftCellSize,BoardTop-CellSize/4,BoardLeftBoardWidthCellSizeCellSizeBoardTopBoardHeightCellSizeCellSize;drawnextblockgrids*/{line(NBBoardLeft+i*NBCellSize,NBBoardTop,NBBoardLeftiNBCellSizeNBBoardTop+4*NBCellSize);line(NBBoardLeft,NBBoardTop+i*NBCellSize,NBBoardLeft4*NBCellSize,NBBoardTop+i*NBCellSize);}drawscorerect*/leScoreBoardLeftScoreBoardTopScoreBoardLeftScoreardWidthScoreBoardTopScoreBoardHeightsplayScoresetnewseed*/dteBlocknextBlockNextBlock();/*createfirstblock*/outtextxy(InfoLeft,InfoTop+20,"Up-rotateouttextxyInfoLeftInfoTop5,"Left-leftrightouttextxyInfoLeftInfoTopEscexit;playInfoinfohelp}settheisFilledandfillcolordatatotheboard*/NERHELPERFillBoardData{{{{Boardi[+j][0]=1;Boardi[+j][1]=;}}}}drawonelineoftheboard*/NERHELPERPaintBoard{maxTopLinejBoardHeightj{dthi{rdijBoardij1]:BkGndColor;orrdLeftiCellSizeCellSizeBoardTopjCellSi}}}NERHELPERCheckBoard{wefindthetopemptyline!*/jtopyBoardHeight{foriiBoardWidthi{}topy--;{foriiBoardWidthiemoveit{movethecellsdatadownoneline*/forkj;k>topy;k--){idthi{Board[i][k][0]=Board[i][k-1][0];Board[i][k][1]=Board[i][k-1][1];}}makethetoplineempty*/idthi{Boarditopy][0]=0;Boarditopy][1]=0;}topy++;/*movethetoplinedownwardonecorescorescoreadding0,150*/}j--;mjtopylinesFrameTimemax0-100*(TotalScore/200),400);TopLinetopy*updatethetopline*/ifnolinesremoveonlyadd1:*/core}displaythescore/RHELPERDisplayScore{textxyScoreBoardLeftScoreBoardTopinfoscoreTotalScoretextxyScoreBoardLeftScoreBoardTopinfoscore}wecallthisfunctionwhenablockisinactive

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論