版權(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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 學校安全重點部位實驗室檢查記錄表
- 高一化學教案:專題第二單元第三課時燃料燃燒釋放的熱量
- 2024高中物理章末質(zhì)量評估一含解析粵教版選修1-1
- 2024高中語文開學第一課學生觀后感范文800字少年強中國強素材
- 2024高中語文精讀課文二第4課1貝多芬:扼住命運的咽喉一課堂練習含解析新人教版選修中外傳記蚜
- 2024高考化學一輪復習第十二章物質(zhì)結(jié)構(gòu)與性質(zhì)第一講原子結(jié)構(gòu)與性質(zhì)規(guī)范演練含解析新人教版
- 2024高考歷史一輪復習方案專題十五西方人文精神的起源和發(fā)展專題整合備考提能教學案+練習人民版
- 2025新人教版英語七年級下單詞表(小學部分)
- (2篇)2024初中英語教師工作總結(jié)初中英語教師述職報告
- 倉庫管理制度通知
- 危險化學品的應(yīng)急處理和救援措施
- DB23-T 2334-2019 裝配式混凝土矩形渠道應(yīng)用技術(shù)規(guī)范
- 2023信息系統(tǒng)運維服務(wù)方案
- 試卷分析格式表
- 本霍根的五堂課中文版
- 軟件無線電原理與應(yīng)用第3版 課件 【ch02】軟件無線電理論基礎(chǔ)
- 國網(wǎng)山東電力生產(chǎn)技術(shù)改造原則
- 鐵路運輸安全現(xiàn)場管理
- 自粘聚合物改性瀝青防水卷材施工工藝與規(guī)程
- 線上學習平臺管理辦法
- 2023年某保險公司春節(jié)經(jīng)營教材
評論
0/150
提交評論