俄羅斯方塊純c版(共86頁)_第1頁
俄羅斯方塊純c版(共86頁)_第2頁
俄羅斯方塊純c版(共86頁)_第3頁
俄羅斯方塊純c版(共86頁)_第4頁
俄羅斯方塊純c版(共86頁)_第5頁
已閱讀5頁,還剩82頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、#include #include #include #include #include #ifdef _cplusplus#define _CPPARGS .#else#define _CPPARGS#endif#define MINBOXSIZE 15 /* 最小方塊的尺寸(ch cun) */#define BGCOLOR 7 /* 背景(bijng)著色 */#define GX 200#define GY 10#define SJNUM 10000 /* 每當(dāng)玩家打到一萬分(wnfn)等級(jí)加一級(jí)*/* 按鍵碼*/#define VK_LEFT 0 x4b00#define VK_RI

2、GHT 0 x4d00#define VK_DOWN 0 x5000#define VK_UP 0 x4800#define VK_HOME 0 x4700#define VK_END 0 x4f00#define VK_SPACE 0 x3920#define VK_ESC 0 x011b#define VK_ENTER 0 x1c0d/* 定義俄羅斯方塊的方向(我定義他為4種)*/#define F_DONG 0#define F_NAN 1#define F_XI 2#define F_BEI 3#define NEXTCOL 20 /* 要出的下一個(gè)方塊的縱坐標(biāo)*/#define NE

3、XTROW 12 /* 要出的下一個(gè)方塊的橫從標(biāo)*/#define MAXROW 14 /* 游戲屏幕大小*/#define MAXCOL 20#define SCCOL 100 /*游戲(yux)屏幕大顯示器上的相對(duì)位置*/#define SCROW 60int gril2216; /* 游戲屏幕(pngm)坐標(biāo)*/int col=1,row=7; /* 當(dāng)前(dngqin)方塊的橫縱坐標(biāo)*/int boxfx=0,boxgs=0; /* 當(dāng)前寺塊的形壯和方向*/int nextboxfx=0,nextboxgs=0,maxcol=22;/*下一個(gè)方塊的形壯和方向*/int minboxco

4、lor=6,nextminboxcolor=6;int num=0; /*游戲分*/int dj=0,gamedj10=18,16,14,12,10,8,6,4,2,1;/* 游戲等級(jí)*/* 以下我用了一個(gè)3維數(shù)組來紀(jì)錄方塊的最初形狀和方向*/int boxstr7416=1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,0,0,1,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,0,0,1,0,0,0,0,0,0,0,0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,1,0

5、,0,0,1,1,0,0,0,1,0,0,0,0,0,0,0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,1,0,0,0,0,0,0,0,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0

6、,1,1,0,0,0,0,0,0,1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0.0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0.0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0.0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0.0,0

7、,0,0,0,0,0,0,1,1,1,0,0,1,0,0,0,0,0,0,1,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0,0,1,0,0,1,1,1,0,0,0,0,0.0,0,0,0,0,1,0,0,1,1,0,0,0,1,0,0,0,0,0,0;/* 隨機(jī)得到當(dāng)前方塊和下一個(gè)(y )方塊的形狀和方向*/void boxrad()minboxcolor=nextminboxcolor;boxgs=nextboxgs;boxfx=nextboxfx;nextminboxcolor=random(14)+1;if(nextminboxcolor=4|nextminboxcolor

8、=7|nextminboxcolor=8)nextminboxcolor=9;nextboxfx=F_DONG;nextboxgs=random(7);/*初始化圖形(txng)模試*/void init(int gdrive,int gmode)int errorcode;initgraph(&gdrive,&gmode,D:tc);errorcode=graphresult();if(errorcode!=grOk)printf(error of: %s,grapherrormsg(errorcode);exit(1);/* 在圖形(txng)模式下的清屏 */void cls()setf

9、illstyle(SOLID_FILL,0);setcolor(0);bar(0,0,640,480);/*在圖形模式(msh)下的高級(jí)清屏*/void clscr(int a,int b,int c,int d,int color)setfillstyle(SOLID_FILL,color);setcolor(color);bar(a,b,c,d);/*最小方塊的繪制(huzh)*/void minbox(int asc,int bsc,int color,int bdcolor)int a=0,b=0;a=SCCOL+asc;b=SCROW+bsc;clscr(a+1,b+1,a-1+MI

10、NBOXSIZE,b-1+MINBOXSIZE,color);if(color!=BGCOLOR)setcolor(bdcolor);line(a+1,b+1,a-1+MINBOXSIZE,b+1);line(a+1,b+1,a+1,b-1+MINBOXSIZE);line(a-1+MINBOXSIZE,b+1,a-1+MINBOXSIZE,b-1+MINBOXSIZE);line(a+1,b-1+MINBOXSIZE,a-1+MINBOXSIZE,b-1+MINBOXSIZE);/*游戲中出現(xiàn)(chxin)的文字*/void txt(int a,int b,char *txt,int fon

11、t,int color)setcolor(color);settextstyle(0,0,font);outtextxy(a,b,txt);/*windows 繪制*/void win(int a,int b,int c,int d,int bgcolor,int bordercolor)clscr(a,b,c,d,bgcolor);setcolor(bordercolor);line(a,b,c,b);line(a,b,a,d);line(a,d,c,d);line(c,b,c,d);/* 當(dāng)前方塊(fn kui)的繪制*/void funbox(int a,int b,int color,

12、int bdcolor)int i,j;int boxz44;for(i=0;i16;i+)boxzi/4i%4=boxstrboxgsboxfxi;for(i=0;i4;i+)for(j=0;j4;j+)if(boxzij=1)minbox(j+row+a)*MINBOXSIZE,(i+col+b)*MINBOXSIZE,color,bdcolor);/*下一個(gè)方塊(fn kui)的繪制*/void nextfunbox(int a,int b,int color,int bdcolor)int i,j;int boxz44;for(i=0;i16;i+)boxzi/4i%4=boxstrn

13、extboxgsnextboxfxi;for(i=0;i4;i+)for(j=0;j1;i-)for(j=1;j15;j+)minbox(j*MINBOXSIZE,i*MINBOXSIZE,BGCOLOR,BGCOLOR);grilij=grili-1j;if(grilij=1)minbox(j*MINBOXSIZE,i*MINBOXSIZE,minboxcolor,0);/*消掉所有(suyu)都有最小方塊的行*/void delete()int i,j,zero,delgx=0;char *nm=00000;for(i=1;i21;i+)zero=0;for(j=1;j15;j+)if(g

14、rilij=0)zero=1;if(zero=0)delcol(i);delgx+;num=num+delgx*delgx*10;dj=num/10000;sprintf(nm,%d,num);clscr(456,173,500,200,4);txt(456,173,Number:,1,15);txt(456,193,nm,1,15);/*時(shí)間(shjin)中斷結(jié)束*/void KillTimer()disable();setvect(TIMER,oldhandler);enable();/* 測試當(dāng)前方塊是否(sh fu)可以向下落*/int downok()int i,j,k=1,a44;

15、for(i=0;i16;i+)ai/4i%4=boxstrboxgsboxfxi;for(i=0;i4;i+)for(j=0;j4;j+)if(aij & grilcol+i+1row+j)k=0;return(k);/* 測試當(dāng)前方塊是否可以(ky)向左行*/int leftok()int i,j,k=1,a44;for(i=0;i16;i+)ai/4i%4=boxstrboxgsboxfxi;for(i=0;i4;i+)for(j=0;j4;j+)if(aij & grilcol+irow+j-1)k=0;return(k);/* 測試當(dāng)前方塊是否(sh fu)可以向右行*/int rig

16、htok()int i,j,k=1,a44;for(i=0;i16;i+)ai/4i%4=boxstrboxgsboxfxi;for(i=0;i4;i+)for(j=0;j4;j+)if(aij & grilcol+irow+j+1)k=0;return(k);/* 測試當(dāng)前方塊是否可以變形*/int upok()int i,j,k=1,a44;for(i=0;i4;i+)for(i=0;i=0;i-)for(j=3;j=0;j-)if(aij & grilcol+irow+j)k=0;return(k);/*當(dāng)前方塊落下之后(zhhu),給屏幕坐標(biāo)作標(biāo)記*/void setgril()int

17、 i,j,a44;funbox(0,0,minboxcolor,0);for(i=0;i16;i+)ai/4i%4=boxstrboxgsboxfxi;for(i=0;i4;i+)for(j=0;j0;i-)for(j=1;j3)boxfx=0;funbox(0,0,minboxcolor,0);break;case VK_LEFT: /*左方向鍵,縱坐標(biāo)減一*/if(leftok()row-;funbox(0,0,minboxcolor,0);break;case VK_RIGHT: /*右方向鍵,縱坐標(biāo)加一*/if(rightok()row+;funbox(0,0,minboxcolor,

18、0);break;case VK_SPACE: /*空格鍵,直接落到最后(zuhu)可以落到的們置*/while(downok()col+;funbox(0,0,minboxcolor,0);setgril();nextfunbox(NEXTCOL,NEXTROW,4,4);boxrad();nextfunbox(NEXTCOL,NEXTROW,nextminboxcolor,0);delete();break;default:txt(423,53,worng key!,1,4);txt(428,80,Plese Enter Anly Key AG!,1,4);getch();clscr(42

19、0,50,622,97,BGCOLOR);/*時(shí)間中斷(zhngdun)開始*/void timezd(void)int key;SetTimer(newhandler);boxrad();nextfunbox(NEXTCOL,NEXTROW,nextminboxcolor,0);for(;)if(bioskey(1)key=bioskey(0);funbox(0,0,BGCOLOR,BGCOLOR);if(key=VK_ESC)break;call_key(key);if(TimerCountergamedjdj)TimerCounter=0;if(downok()funbox(0,0,BG

20、COLOR,BGCOLOR);col+;funbox(0,0,minboxcolor,0);else if(col=1)gameover();getch();break;setgril();delete();funbox(0,0,minboxcolor,0);col=1;row=7;funbox(0,0,BGCOLOR,BGCOLOR);nextfunbox(NEXTCOL,NEXTROW,4,4);boxrad();nextfunbox(NEXTCOL,NEXTROW,nextminboxcolor,0);/*主程序開始(kish)*/void main(void)int i,j;char

21、*nm=00000;init(VGA,VGAHI);cls();/*屏幕(pngm)坐標(biāo)初始化*/for(i=0;i=MAXCOL+1;i+)for(j=0;j=MAXROW+1;j+)grilij=0;for(i=0;i=MAXCOL+1;i+) grili0=1;grili15=1;for(j=1;j查看同主題問題: 俄羅斯方塊 語言 語言 源代碼等待您來回答0回答MiniGUI 程序中為什么我的鼠標(biāo)無法正常工作0回答smdk2410 是什么,與S3C2410什么關(guān)系1回答那個(gè)開題報(bào)告也能發(fā)我一份么!謝謝!你有上市公司財(cái)務(wù)風(fēng)險(xiǎn)研究的開題.0回答50關(guān)于(guny)百雀羚凡士林保濕潤膚霜與大

22、寶SOD蜜的市場份額比例的具體情況,大.2回答(hud)“MiniGUI圖形庫”這個(gè)(zh ge)詞是怎么讀的0回答20誰有 s3c2410板子的wince6.0 的BSP包。0回答10求運(yùn)算放大器應(yīng)用的開題報(bào)告,及運(yùn)算放大器的現(xiàn)狀,學(xué)習(xí)的重點(diǎn)和難點(diǎn)。1回答20sod公司的電影有迅雷地址的,有的朋友發(fā)723453145 好了給分更多等待您來回答的問題其他回答 共8條只有100分回答者: chenyilong58 | 一級(jí) | 2008-9-13 09:04#include #include #include #include #include #include #include /*定義左上角

23、點(diǎn)在屏幕上的位置*/#define MAPXOFT 9#define MAPYOFT 5/*定義下一個(gè)方塊顯示(xinsh)的位置*/#define MAPXOFT1 13#define MAPYOFT1 -2#define LEFT 0 x4b00#define RIGHT 0 x4d00#define DOWN 0 x5000 /*此鍵為加速(ji s)鍵*/#define UP 0 x4800 /*此鍵為變形(bin xng)鍵*/#define ESC 0 x011b /*此鍵為退出鍵*/#define ENTER 0 x1c0d#define TIMER 0 x1c /* 時(shí)鐘中斷的

24、中斷號(hào) */* 中斷處理函數(shù)在C和C+中的表示略有不同。如果定義了_cplusplus則表示在C+環(huán)境下,否則是在C環(huán)境下。 */#ifdef _cplusplus#define _CPPARGS .#else#define _CPPARGS#endifint TimerCounter=0; /* 計(jì)時(shí)變量(binling),每秒鐘增加18。 */* 指向原來時(shí)鐘中斷(zhngdun)處理過程入口的中斷處理函數(shù)指針(句柄) */void interrupt ( *oldhandler)(_CPPARGS);/* 新的時(shí)鐘(shzhng)中斷處理函數(shù) */void interrupt newha

25、ndler(_CPPARGS) /* increase the global counter */ TimerCounter+; /* call the old routine */ oldhandler();/* 設(shè)置新的時(shí)鐘中斷處理過程 */void SetTimer(void interrupt (*IntProc)(_CPPARGS) oldhandler=getvect(TIMER); disable(); /* 設(shè)置新的時(shí)鐘中斷處理過程時(shí),禁止所有中斷 */ setvect(TIMER,IntProc); enable(); /* 開啟中斷 */* 恢復(fù)(huf)原有的時(shí)鐘中斷處理

26、過程 */void KillTimer() disable(); setvect(TIMER,oldhandler); enable();struct shape int xy8,next;struct shape shapes19=/*x1,y1,x2,y2,x3,y3,x4,y4 指四個(gè)小方塊的相對(duì)坐標(biāo)(zubio),next指此方塊變形后應(yīng)變?yōu)槟膫€(gè)小方塊 x1,y1,x2,y2,x3,y3,x4,y4,next*/ 0,-2, 0,-1, 0, 0, 1, 0, 1, -1, 0, 0, 0, 1,-1, 1, 0, 2, 0,-2, 1,-2, 1,-1, 1, 0, 3, -1,-1

27、,-1, 0, 0,-1, 1,-1, 0, 0,-2, 0,-1, 0, 0, 1,-2, 5, -1,-1, 0,-1, 1,-1, 1, 0, 6, 0, 0, 1,-2, 1,-1, 1, 0, 7, -1,-1,-1, 0, 0, 0, 1, 0, 4, -1, 0, 0,-1, 0, 0, 1, 0, 9, 0,-2, 0,-1, 0, 0, 1,-1,10, -1,-1, 0,-1, 1,-1, 0, 0,11, 0,-1, 1,-2, 1,-1, 1, 0, 8, -1, 0, 0,-1, 0, 0, 1,-1,13, 0,-2, 0,-1, 1,-1, 1, 0,12, -1

28、,-1, 0,-1, 0, 0, 1, 0,15, 0,-1, 0, 0, 1,-2, 1,-1,14, 0,-3, 0,-2, 0,-1, 0, 0,17, -1, 0, 0, 0, 1, 0, 2, 0,16, 0,-1, 0, 0, 1,-1, 1, 0,18;int board1020=0;/*定義(dngy)游戲板初始化為0*/char sp=0,le=0,sc=00000;int speed,speed0,level,score;int sign,flag;int style,style1; /*style為當(dāng)前方塊的種類(zhngli),style1為即將輸出的方塊的種類*/vo

29、id draw_block(int x,int y,int style,int way);void draw_little_block(int x,int y);void init();void initialize();void speed_change(void);void score_change(int);void kill_line(int y);void fill_board(int x,int y, int style);int change(int *i,int *j,int key);void renovate(void);void ajustment(void);void

30、level_change(void);main() int i,j,key,x0=5,y0=1; randomize(); while(!flag) /*flag為0表示(biosh)重新開始游戲*/ level=score=speed=0; strcpy(le,0); strcpy(sp,0); strcpy(sc,00000); for(i=0;i10;i+) for(j=0;j0) level_change(); /*根據(jù)高度隨機(jī)確定方塊是否存在*/ style=random(19); /*隨機(jī)確定方塊種類*/ while(1) i=x0,j=y0; style1=random(19);

31、 /*隨機(jī)確定即將(jjing)出現(xiàn)的方塊種類*/ setcolor(WHITE); sign=1; draw_block(MAPXOFT1,MAPYOFT1,style1,1); /*畫出即將(jjing)出現(xiàn)的方塊*/ for(j=y0;j18/(speed+1) /* 恢復(fù)(huf)計(jì)時(shí)變量 */ TimerCounter=0; break; else if(TimerCounter18/(9+1)/*按下加速(ji s)鍵時(shí)的處理*/ /* 恢復(fù)計(jì)時(shí)變量 */ TimerCounter=0; speed0=0; break; if(bioskey(1) key=bioskey(0);

32、if(change(&i,&j,key)/*根據(jù)按鍵(n jin)值做調(diào)整*/ flag=1; goto end; draw_block(i,j,style,0); renovate(); /*刷新(shu xn)屏幕*/ if(j=y0) break; j-; draw_block(i,j,style,1); fill_board(i,j,style); sign=1; draw_block(MAPXOFT1,MAPYOFT1,style1,0); style=style1; kill_line(j); /*消去的函數(shù)(hnsh),消去若干行并改變分?jǐn)?shù)和速度*/ while(bioskey(

33、1) /*清除(qngch)內(nèi)存中的按鍵*/ key=bioskey(0); setcolor(CYAN); settextstyle(0,0,2); TimerCounter=0; while(1) if(TimerCounter54) TimerCounter=0; break; while(bioskey(1) /*清除(qngch)內(nèi)存中的按鍵*/ key=bioskey(0); outtextxy(400,340,Game over!); outtextxy(360,360,Enter to replay.); outtextxy(360,380,Esc to quit.); whi

34、le(bioskey(1)=0); key=bioskey(0); end:; closegraph(); KillTimer(); if(key=ESC|flag) break; void initialize()/*初始化進(jìn)入(jnr)圖形模式*/ int gdriver = VGA, gmode=VGAHI, errorcode; /* initialize graphics mode */ initgraph(&gdriver, &gmode, c:Turboc2); /* read result of initialization */ errorcode = graphresult

35、(); if (errorcode != grOk) /* an error occurred */ printf(Graphics error: %sn, grapherrormsg(errorcode); printf(Press any key to halt:); getch(); exit(1); /* return with error code */ void init(void)/*初始化游戲(yux)板記分器等*/ int x1; x1=5+MAPXOFT; setcolor(GREEN); circle(x1+0.5)*16,(MAPYOFT-2)*16,3*16); se

36、tcolor(WHITE); line(x1-0.6)*16,(MAPYOFT-3.2)*16,x1*16,(MAPYOFT-3.2)*16); line(x1+1.4)*16,(MAPYOFT-3.2)*16,(x1+2.0)*16,(MAPYOFT-3.2)*16); line(x1+0.5)*16,(MAPYOFT-2)*16,(x1+0.5)*16,(MAPYOFT-1.7)*16); circle(x1+0.5)*16,(MAPYOFT-0.9)*16,0.3*16); setcolor(CYAN); line(MAPXOFT+3)*16,(MAPYOFT+21)*16,MAPXOF

37、T*16,(MAPYOFT+23.5)*16); line(MAPXOFT+5.5)*16,(MAPYOFT+21)*16,MAPXOFT*16,(MAPYOFT+26)*16); line(MAPXOFT+9)*16,(MAPYOFT+21)*16,(MAPXOFT+12)*16,(MAPYOFT+23.5)*16); line(MAPXOFT+6.5)*16,(MAPYOFT+21)*16,(MAPXOFT+12)*16,(MAPYOFT+26)*16); setcolor(MAGENTA); ellipse(MAPXOFT+1)*16,(MAPYOFT+11)*16,90,270,7*1

38、6,7*16); ellipse(MAPXOFT+11)*16,(MAPYOFT+11)*16,-90,90,7*16,7*16); circle(MAPXOFT+24)*16,(MAPYOFT+6)*16,6*16); setcolor(WHITE); rectangle(x1-0.5)*16,(MAPYOFT-2.9)*16,(x1-0.1)*16,(MAPYOFT-2.5)*16); rectangle(x1+1.5)*16,(MAPYOFT-2.9)*16,(x1+1.9)*16,(MAPYOFT-2.5)*16); setcolor(YELLOW); rectangle(10*16,

39、6*16,20*16,26*16); settextstyle(0,0,2); outtextxy(5*16,13.5*16,level); outtextxy(20.4*16,13.5*16,speed); outtextxy(MAPXOFT+22)*16,(MAPYOFT+3)*16,score); settextstyle(0,0,4); outtextxy(6.5*16,15*16,0); outtextxy(21.9*16,15*16,0); settextstyle(0,0,3); outtextxy(MAPXOFT+21)*16,(MAPYOFT+6)*16,sc);void a

40、justment(void) /*開始游戲前調(diào)整(tiozhng)速度和高度*/ int key,boo=1,left=1; setcolor(YELLOW); settextstyle(0,0,2); outtextxy(500,340,PRESS); outtextxy(500,360,ENTER); outtextxy(500,380, TO ); outtextxy(500,400,START); while(1) if(TimerCounter8) TimerCounter=0; boo*=-1; if(boo=-1) setcolor(BLACK); else setcolor(Y

41、ELLOW); if(left=1) line(6*16,17*16,8.5*16,17*16); setcolor(BLACK); line(21.4*16,17*16,23.9*16,17*16); else line(21.4*16,17*16,23.9*16,17*16); setcolor(BLACK); line(6*16,17*16,8.5*16,17*16); if(bioskey(1) key=bioskey(0); if(key=UP|key=DOWN) setcolor(BLACK); settextstyle(0,0,4); outtextxy(6.5*16,15*16

42、,le); outtextxy(21.9*16,15*16,sp); if(key=ENTER) break; else if(key=UP) if(left=1) level-; if(level=-1) level=9; else speed-; if(speed=-1) speed=9; else if(key=DOWN) if(left=1) level+; if(level=10) level=0; else speed+; if(speed=10) speed=0; else if(key=LEFT|RIGHT) left*=-1; setcolor(YELLOW); sp0=sp

43、eed+0; le0=level+0; settextstyle(0,0,4); outtextxy(6.5*16,15*16,le); outtextxy(21.9*16,15*16,sp); setcolor(YELLOW); sp0=speed+0; le0=level+0; settextstyle(0,0,4); outtextxy(6.5*16,15*16,le); outtextxy(21.9*16,15*16,sp); setcolor(BLACK); line(21.4*16,17*16,23.9*16,17*16); line(6*16,17*16,8.5*16,17*16

44、); settextstyle(0,0,2); outtextxy(500,340,PRESS); outtextxy(500,360,ENTER); outtextxy(500,380, TO ); outtextxy(500,400,START);void level_change(void) /*根據(jù)高度隨機(jī)確定(qudng)方塊是否存在*/ int i,j; setcolor(WHITE); for(i=1;i=10;i+) for(j=1;j=level;j+) if(random(2) boardi-120-j=1; draw_little_block(i+MAPXOFT,21-j

45、+MAPYOFT); void draw_block(int x,int y,int style,int way)/*此x,y為虛擬坐標(biāo),為19中形式(xngsh)中的一種:018中的一個(gè)x,y為10*20的方格(fn )的坐標(biāo),下標(biāo)從1開始way為1表填充(tinchng),為0表清除*/ int x1=x+MAPXOFT,y1=y+MAPYOFT; int i; if(way=1) setcolor(WHITE); else setcolor(BLACK); for(i=0;i=10&x=6&y26)|sign) rectangle(x*16,y*16,x*16+16,y*16+16);

46、circle(x*16+8,y*16+8,4); int check_block(int x,int y,int style)/*此處檢查在(x,y)處放置一方(y fn)塊是否可以,若是,則返回1,否則返回0*/ int x1=x+MAPXOFT,y1=y+MAPYOFT; int x2,y2,i; for(i=0;i=10&x220&y226&(y2=(sp0-0)*100&(sp0-0)=1;i-) sci-1+=(sci-0)/10; sci-=(sci-0)/10*10; setcolor(YELLOW); settextstyle(0,0,3); outtextxy(MAPXOFT

47、+21)*16,(MAPYOFT+6)*16,sc); /*輸出(shch)新分?jǐn)?shù)*/void kill_line(int y)/*消去的函數(shù),消去若干行并改變(gibin)分?jǐn)?shù)和速度*/ int count=0,i,t=1,j,k; for(;y=1&t=4;y-,t+) for(i=1;i=10;i+) if(!boardi-1y-1) break; if(i=11) count+; for(k=1;k=1;j-) for(k=1;k0) setcolor(CYAN); settextstyle(0,0,3); outtextxy(500,370,Good!); TimerCounter=

48、0; while(1) if(TimerCounter3) TimerCounter=0; break; setcolor(BLACK); settextstyle(0,0,3); outtextxy(500,370,Good!); score_change(count); speed_change(); void fill_board(int x,int y, int style) /*當(dāng)一方塊停止時(shí),將中相應(yīng)(xingyng)的值改為1*/ int x1,y1,i; for(i=0;i=6;i+=2) x1=x+shapesstyle.xyi; y1=y+shapesstyle.xyi+1

49、; boardx1-1y1-1=1; int change(int *i,int *j,int key)/*控制方塊移動(dòng)、變形(bin xng)的函數(shù)*/ int key1; if(key=UP&check_block(*i,*j,shapesstyle.next) draw_block(*i,*j,style,0); style=shapesstyle.next; draw_block(*i,*j,style,1); else if(key=LEFT&check_block(*i-1,*j,style) draw_block(*i,*j,style,0); (*i)-; draw_block

50、(*i,*j,style,1); else if(key=RIGHT&check_block(*i+1,*j,style) draw_block(*i,*j,style,0); (*i)+; draw_block(*i,*j,style,1); else if(key=DOWN&check_block(*i,*j+1,style) draw_block(*i,*j,style,0); (*j)+; draw_block(*i,*j,style,1); speed0=9; else if(key=ENTER) while(1) if(bioskey(1) key1=bioskey(0); if(

51、key1=ENTER) break; else if(key=ESC) return 1; else if(key=21040) sign=1; draw_block(MAPXOFT1,MAPYOFT1,style1,0); style1=16; sign=1; draw_block(MAPXOFT1,MAPYOFT1,style1,1); return 0;void renovate(void) /*刷新(shu xn)屏幕*/ int i,j; setcolor(WHITE); for(i=1;i=10;i+) for(j=1;j=20;j+) if(boardi-1j-1=1) draw

52、_little_block(i+MAPXOFT,j+MAPYOFT); setcolor(YELLOW); rectangle(10*16,6*16,20*16,26*16);回答者: wangtk1982 | 十一級(jí) | 2008-9-13 09:15TC下面(xi mian)的/* Desc: 俄羅斯方塊(fn kui)游戲* By: hoodlum1980* Email: * Date: 2008.03.12 22:30*/#include #include #include #include #include #include #define true 1#define false 0

53、#define BoardWidth 12#define BoardHeight 23#define _INNER_HELPER /*inner helper method */*Scan Codes Define*/enum KEYCODESK_ESC =0 x011b,K_UP =0 x4800, /* upward arrow */K_LEFT =0 x4b00,K_DOWN =0 x5000,K_RIGHT =0 x4d00,K_SPACE =0 x3920,K_P =0 x1970;/* the data structure of the block */typedef struct

54、 tagBlockchar c44; /* cell fill info array, 0-empty, 1-filled */int x; /* block position cx 0,BoardWidht -1 */int y; /* block position cy -4,BoardHeight-1 */char color; /* block color */char size; /* block max size in width or height */char name; /* block name (the blocks shape) */ Block;/* games gl

55、obal info */int FrameTime= 1300;int CellSize= 18;int BoardLeft= 30;int BoardTop= 30;/* next block grid */int NBBoardLeft= 300;int NBBoardTop= 30;int NBCellSize= 10;/* score board position */int ScoreBoardLeft= 300;int ScoreBoardTop=100;int ScoreBoardWidth=200;int ScoreBoardHeight=35;int ScoreColor=L

56、IGHTCYAN;/* infor text postion */int InfoLeft=300;int InfoTop=200;int InfoColor=YELLOW;int BorderColor=DARKGRAY;int BkGndColor=BLACK;int GameRunning=true;int TopLine=BoardHeight-1; /* top empty line */int TotalScore=100;char info_score20;char info_help255;char info_common255;/* our board, Boardxy0-i

57、sFilled, Boardxy1-fillColor */unsigned char BoardBoardWidthBoardHeight2;char BufferCells44; /* used to judge if can rotate block */Block curBlock; /* current moving block */Block nextBlock; /* next Block to appear */* function list */int GetKeyCode();int CanMove(int dx,int dy);int CanRotate();int Ro

58、tateBlock(Block *block);int MoveBlock(Block *block,int dx,int dy);void DrawBlock(Block *block,int,int,int);void EraseBlock(Block *block,int,int,int);void DisplayScore();void DisplayInfo(char* text);void GenerateBlock(Block *block);void NextBlock();void InitGame();int PauseGame();void QuitGame();/*Ge

59、t Key Code */int _INNER_HELPER GetKeyCode()int key=0;if(bioskey(1)key=bioskey(0);return key;/* display text! */void _INNER_HELPER DisplayInfo(char *text)setcolor(BkGndColor);outtextxy(InfoLeft,InfoTop,info_common);strcpy(info_common,text);setcolor(InfoColor);outtextxy(InfoLeft,InfoTop,info_common);/

60、* create a new block by key number,* the block anchor to the top-left corner of 4*4 cells*/void _INNER_HELPER GenerateBlock(Block *block)int key=(random(13)*random(17)+random(1000)+random(3000)%7;block-size=3;/* because most blocks size=3 */memset(block-c,0,16);switch(key)case 0:block-name=T;block-c

溫馨提示

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

最新文檔

評(píng)論

0/150

提交評(píng)論