俄罗斯方块C语言源代码Word下载.docx

上传人:b****1 文档编号:5862997 上传时间:2023-05-05 格式:DOCX 页数:22 大小:18.96KB
下载 相关 举报
俄罗斯方块C语言源代码Word下载.docx_第1页
第1页 / 共22页
俄罗斯方块C语言源代码Word下载.docx_第2页
第2页 / 共22页
俄罗斯方块C语言源代码Word下载.docx_第3页
第3页 / 共22页
俄罗斯方块C语言源代码Word下载.docx_第4页
第4页 / 共22页
俄罗斯方块C语言源代码Word下载.docx_第5页
第5页 / 共22页
俄罗斯方块C语言源代码Word下载.docx_第6页
第6页 / 共22页
俄罗斯方块C语言源代码Word下载.docx_第7页
第7页 / 共22页
俄罗斯方块C语言源代码Word下载.docx_第8页
第8页 / 共22页
俄罗斯方块C语言源代码Word下载.docx_第9页
第9页 / 共22页
俄罗斯方块C语言源代码Word下载.docx_第10页
第10页 / 共22页
俄罗斯方块C语言源代码Word下载.docx_第11页
第11页 / 共22页
俄罗斯方块C语言源代码Word下载.docx_第12页
第12页 / 共22页
俄罗斯方块C语言源代码Word下载.docx_第13页
第13页 / 共22页
俄罗斯方块C语言源代码Word下载.docx_第14页
第14页 / 共22页
俄罗斯方块C语言源代码Word下载.docx_第15页
第15页 / 共22页
俄罗斯方块C语言源代码Word下载.docx_第16页
第16页 / 共22页
俄罗斯方块C语言源代码Word下载.docx_第17页
第17页 / 共22页
俄罗斯方块C语言源代码Word下载.docx_第18页
第18页 / 共22页
俄罗斯方块C语言源代码Word下载.docx_第19页
第19页 / 共22页
俄罗斯方块C语言源代码Word下载.docx_第20页
第20页 / 共22页
亲,该文档总共22页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

俄罗斯方块C语言源代码Word下载.docx

《俄罗斯方块C语言源代码Word下载.docx》由会员分享,可在线阅读,更多相关《俄罗斯方块C语言源代码Word下载.docx(22页珍藏版)》请在冰点文库上搜索。

俄罗斯方块C语言源代码Word下载.docx

K_P=0x1970

};

/*thedatastructureoftheblock*/

typedefstructtagBlock

charc[4][4];

/*cellfillinfoarray,0-empty,1-filled*/

intx;

/*blockpositioncx[0,BoardWidht-1]*/

inty;

/*blockpositioncy[-4,BoardHeight-1]*/

charcolor;

/*blockcolor*/

charsize;

/*blockmaxsizeinwidthorheight*/

charname;

/*blockname(theblock'

sshape)*/

}Block;

/*game'

sglobalinfo*/

intFrameTime=1300;

intCellSize=18;

intBoardLeft=30;

intBoardTop=30;

/*nextblockgrid*/

intNBBoardLeft=300;

intNBBoardTop=30;

intNBCellSize=10;

/*scoreboardposition*/

intScoreBoardLeft=300;

intScoreBoardTop=100;

intScoreBoardWidth=200;

intScoreBoardHeight=35;

intScoreColor=LIGHTCYAN;

/*infortextpostion*/

intInfoLeft=300;

intInfoTop=200;

intInfoColor=YELLOW;

intBorderColor=DARKGRAY;

intBkGndColor=BLACK;

intGameRunning=true;

intTopLine=BoardHeight-1;

/*topemptyline*/

intTotalScore=100;

charinfo_score[20];

charinfo_help[255];

charinfo_common[255];

/*ourboard,Board[x][y][0]-isFilled,Board[x][y][1]-fillColor*/

unsignedcharBoard[BoardWidth][BoardHeight][2];

charBufferCells[4][4];

/*usedtojudgeifcanrotateblock*/

BlockcurBlock;

/*currentmovingblock*/

BlocknextBlock;

/*nextBlocktoappear*/

/*functionlist*/

intGetKeyCode();

intCanMove(intdx,intdy);

intCanRotate();

intRotateBlock(Block*block);

intMoveBlock(Block*block,intdx,intdy);

voidDrawBlock(Block*block,int,int,int);

voidEraseBlock(Block*block,int,int,int);

voidDisplayScore();

voidDisplayInfo(char*text);

voidGenerateBlock(Block*block);

voidNextBlock();

voidInitGame();

intPauseGame();

voidQuitGame();

/*GetKeyCode*/

int_INNER_HELPERGetKeyCode()

intkey=0;

if(bioskey

(1))

{

key=bioskey(0);

}

returnkey;

}

/*displaytext!

*/

void_INNER_HELPERDisplayInfo(char*text)

setcolor(BkGndColor);

outtextxy(InfoLeft,InfoTop,info_common);

strcpy(info_common,text);

setcolor(InfoColor);

/*createanewblockbykeynumber,

*theblockanchortothetop-leftcornerof4*4cells

*/

void_INNER_HELPERGenerateBlock(Block*block)

intkey=(random(13)*random(17)+random(1000)+random(3000))%7;

block->

size=3;

/*becausemostblocks'

size=3*/

memset(block->

c,0,16);

switch(key)

case0:

name='

T'

;

color=RED;

c[1][0]=1;

c[1][1]=1,block->

c[2][1]=1;

c[1][2]=1;

break;

case1:

L'

color=YELLOW;

c[1][1]=1;

c[1][2]=1,block->

c[2][2]=1;

case2:

J'

color=LIGHTGRAY;

c[0][2]=1;

case3:

z'

color=CYAN;

c[0][0]=1,block->

case4:

5'

color=LIGHTBLUE;

c[1][0]=1,block->

c[2][0]=1;

c[0][1]=1,block->

case5:

o'

color=BLUE;

size=2;

case6:

I'

color=GREEN;

size=4;

c[1][3]=1;

/*getnextblock!

voidNextBlock()

/*copythenextBlocktocurBlock*/

curBlock.size=nextBlock.size;

curBlock.color=nextBlock.color;

curBlock.x=(BoardWidth-4)/2;

curBlock.y=-curBlock.size;

memcpy(curBlock.c,nextBlock.c,16);

/*generatenextBlockandshowit*/

EraseBlock(&

nextBlock,NBBoardLeft,NBBoardTop,NBCellSize);

GenerateBlock(&

nextBlock);

nextBlock.x=1,nextBlock.y=0;

DrawBlock(&

/*rotatetheblock,updatetheblockstructdata*/

int_INNER_HELPERRotateCells(charc[4][4],charblockSize)

chartemp,i,j;

switch(blockSize)

temp=c[0][0];

c[0][0]=c[2][0],c[2][0]=c[2][2],c[2][2]=c[0][2],c[0][2]=temp;

temp=c[0][1];

c[0][1]=c[1][0],c[1][0]=c[2][1],c[2][1]=c[1][2],c[1][2]=temp;

/*only'

blockarivedhere!

c[1][0]=1-c[1][0],c[1][2]=1-c[1][2],c[1][3]=1-c[1][3];

c[0][1]=1-c[0][1],c[2][1]=1-c[2][1],c[3][1]=1-c[3][1];

/*judgeiftheblockcanmovetowardthedirection*/

intCanMove(intdx,intdy)

inti,j,tempX,tempY;

for(i=0;

i<

curBlock.size;

i++)

for(j=0;

j<

j++)

if(curBlock.c[i][j])

/*cannotmoveleftwardorrightward*/

tempX=curBlock.x+i+dx;

if(tempX<

0||tempX>

(BoardWidth-1))returnfalse;

/*makesurexisvalid!

/*cannotmovedownward*/

tempY=curBlock.y+j+dy;

if(tempY>

(BoardHeight-1))returnfalse;

/*yisonlycheckedlowerbound,maybenegative!

!

/*thecellalreadyfilled,wemustcheckY'

supperboundbeforecheckcell!

=0&

&

Board[tempX][tempY][0])returnfalse;

returntrue;

/*judgeiftheblockcanrotate*/

intCanRotate()

/*updatebuffer*/

memcpy(BufferCells,curBlock.c,16);

RotateCells(BufferCells,curBlock.size);

if(BufferCells[i][j])

tempX=curBlock.x+i;

tempY=curBlock.y+j;

(BoardWidth-1))

returnfalse;

(BoardHeight-1))

Board[tempX][tempY][0])

/*drawtheblock*/

void_INNER_HELPERDrawBlock(Block*block,intbdLeft,intbdTop,intcellSize)

inti,j;

setfillstyle(SOLID_FILL,block->

color);

block->

size;

if(block->

c[i][j]&

(block->

y+j)>

=0)

floodfill(

bdLeft+cellSize*(i+block->

x)+cellSize/2,

bdTop+cellSize*(j+block->

y)+cellSize/2,

BorderColor);

/*Rotatetheblock,ifsuccess,returntrue*/

intRotateBlock(Block*block)

intb_success;

size==2)

if((b_success=CanRotate()))

EraseBlock(block,BoardLeft,BoardTop,CellSize);

memcpy(curBlock.c,BufferCells,16);

DrawBlock(block,BoardLeft,BoardTop,CellSize);

returnb_success;

/*eraseablock,onlyfillthefilledcellwithbackgroundcolor*/

void_INNER_HELPEREraseBlock(Block*block,intbdLeft,intbdTop,intcellSize)

setfillstyle(SOLID_FILL,BkGndColor);

y+j>

=0))

/*movebythedirectionifcan,donothingifcannot

*returnvalue:

true-success,false-cannotmovetowardthisdirection

intMoveBlock(Block*block,intdx,intdy)

intb_canmove=CanMove(dx,dy);

if(b_canmove)

curBlock.x+=dx;

curBlock.y+=dy;

returnb_canmove;

/*droptheblocktothebottom!

intDropBlock(Block*block)

while(CanMove(0,1))

curBlock.y++;

return0;

/*returnvalueisassigntotheblock'

salive*/

/*initthegraphicsmode,drawtheboardgrid*/

voidInitGame()

inti,j,gdriver=DETECT,gmode;

structtimesysTime;

/*drawboardcells*/

memset(Board,0,BoardWidth*BoardHeight*2);

memset(nextBlock.c,0,16);

strcpy(info_help,"

P:

PauseGame.--byhoodlum1980"

);

initgraph(&

gdriver,&

gmode,"

"

setcolor(BorderColor);

=BoardWidth;

line(BoardLeft+i*CellSize,BoardTop,BoardLeft+i*CellSize,BoardTop+BoardHeight*CellSize);

=BoardHeight;

line(BoardLeft,BoardTop+i*CellSize,BoardLeft+BoardWidth*CellSize,BoardTop+i*CellSize);

/*drawboardouterborderrect*/

rectangle(BoardLeft-CellSize/4,BoardTop-CellSize/4,

BoardLeft+BoardWidth*CellSize+CellSize/4,

BoardTop+BoardHeight*CellSize+CellSize/4);

/*drawnextblockgrids*/

=4;

line(NBBoardLeft+i*NBCellSize,NBBoardTop,NBBoardLeft+i*NBCellSize,NBBoardTop+4*NBCellSize);

line(NBBoardLeft,NBBoardTop+i*NBCellSize,NBBoardLeft+4*NBCellSize,NBBoardTop+i*NBCellSize);

/*drawscorerect*/

rectangle(ScoreBoardLeft,ScoreBoardTop,ScoreBoardLeft+ScoreBoardWidth,ScoreBoardTop+ScoreBoardHeight);

DisplayScore();

/*setnewseed!

gettime(&

sysTime);

srand(sysTime.ti_hour*3600+sysTime.ti_min*60+sysTime.ti_sec);

NextBlock();

/*createfirstblock*/

setcolor(DARKGRAY);

outtextxy(InfoLeft,InfoTop+20,"

Up-rotateSpace-drop"

outtextxy(InfoLeft,InfoTop+35,"

Left-leftRight-right"

outtextxy(InfoLeft,InfoTop+50,"

Esc-exit"

DisplayInfo(info_help);

/*settheisFilledandfillcolordatatotheboard*/

void_INNER_HELPERFillBoardData()

if(curBlock.c[i][j]&

(curBlock.y+j)>

Board[curBlock.x+i][curBlock.y+j][0]=1;

Board[curBlock.x+i][curBlock.y+j][1]=curBlock.color;

/*drawonelineoftheboard*/

void_INNER_HELPERPaintBoard(

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 初中教育 > 理化生

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2