为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

俄罗斯方块

2013-07-19 7页 doc 68KB 28阅读

用户头像

is_418609

暂无简介

举报
俄罗斯方块俄罗斯方块程序 大家努力啊!我们是最棒的! 2007-6-15 #include "stdlib.h" #include "stdio.h" #include "dos.h" #include "bios.h" #include "graphics.h" #include "math.h" #include "time.h" #include "ctype.h" #define DELAY for(count=0;count <=in...
俄罗斯方块
俄罗斯方块程序 大家努力啊!我们是最棒的! 2007-6-15 #include "stdlib.h" #include "stdio.h" #include "dos.h" #include "bios.h" #include "graphics.h" #include "math.h" #include "time.h" #include "ctype.h" #define DELAY for(count=0;count <=interval;count++){delay(count);} #define FX x0=nowblock.shapex[i]+px #define FY y0=nowblock.shapey[i]+py #define INTERVAL 300 #define ESC 0x11b #define ENTER 0x1c0d #define UP 0x4800 #define DOWN 0x5000 #define LEFT 0x4b00 #define RIGHT 0x4d00 #define p 0x1970 #define P 0x1950 #define w 0x1177 #define W 0x1157 #define a 0x1e61 #define A 0x1e41 #define s 0x1f73 #define S 0x1f53 #define d 0x2064 #define D 0x2044 #define x 0x2d78 #define X 0x2d58 #define r 0x1372 #define R 0x1352 #define y 0x1579 #define Y 0x1559 #define n 0x316e #define N 0x314e struct block { int shapex[4],shapey[4]; int color,next; }; for(i=0;i<=11;i++) grid[i][20]=2; for(i=0;i<20;i++) for(j=1;j<11;j++) grid[j][i]=0; px=5,py=-1,dx=0,dy=0; score=0,level=1,mode=1; interval=INTERVAL,num=0; } welcome() { settextstyle(4,0,7); setcolor(4); outtextxy(172,154,"RUSSIAN"); DELAY; setcolor(4); outtextxy(171,152,"RUSSIAN"); sleep(1); setcolor(10); outtextxy(170,150,"RUSSIAN"); settextstyle(0,0,1); outtextxy(290,230,"loading..."); setcolor(14); setfillstyle(1,15); bar(199,240,441,250); setcolor(2); for(i=0;i<231;i+=10) { setfillstyle(1,1); bar(201+i,241,209+i,249); for(j=1;j<=27;j++) delay(j*77); } } timelimited(int s0,int t0) { setfillstyle(1,1); bar(220,190,420,280); setcolor(14); settextstyle(0,0,1); outtextxy(227,203,"please choose mode..."); getch(); setfillstyle(0,0); bar(0,465,640,480); } showlastscore() {FILE *fp; char lastname[20]; char lastscore[3]; if((fp=fopen("name","r"))!=NULL) { fgets(lastname,20,fp); fclose(fp); outtextxy(40,100,lastname); } if((fp=fopen("highscore","r"))!=NULL) { fgets(lastscore,3,fp); fclose(fp); outtextxy(40,120,lastscore); } setcolor(14); outtextxy(40,70,"Last time:"); } showface() { setcolor(14); setlinestyle(0,0,1); rectangle(157,37,363,443); setlinestyle(0,0,1); rectangle(160,40,360,440); rectangle(439,39,541,141); circle(490,230,50); rectangle(439,319,541,441); line(440,340,540,340); settextstyle(0,0,1); setcolor(14); outtextxy(460,330,"--HELP--"); setcolor(10); outtextxy(447,350,"ESC:EXIT"); outtextxy(447,360,"X:SPEED UP"); outtextxy(447,370,"A:LEFT"); outtextxy(447,380,"D:RIGHT"); x0=nextblock.shapex[i]+2; y0=nextblock.shapey[i]+2; i0=x0*20+440; j0=y0*20+40; bar(i0+1,j0+1,i0+19,j0+19); } } deline() { for(i=19;i>=0;i--) { for(j=1;j<=10;j++) { if(grid[j][i]!=2) {break;} else num++; } if(num==10) { j=0; while(j<2) { for(t0=1;t0<=10;t0++) grid[t0][i]=0; renovate(); hao(); DELAY; sound(500); DELAY; nosound(); for(t0=1;t0<=10;t0++) grid[t0][i]=2; renovate(); setfillstyle(0,0); bar(40,210,95,270); DELAY; j++; } for(s0=i;s0>0;s0--) for(t0=1;t0<=10;t0++) grid[t0][s0]=grid[t0][s0-1]; i++;renovate(); if(score==900) score=0; } } renovate() { for(t0=0;t0<20;t0++) for(s0=1;s0<11;s0++) { if(grid[s0][t0]==1) setfillstyle(1,nowblock.color); if(grid[s0][t0]==2) setfillstyle(1,2); if(grid[s0][t0]==0) setfillstyle(0,15); bar(s0*20+141,t0*20+41,s0*20+ 159,t0*20+59); } } hao() {setcolor(14); line(60,210,40,240); line(40,240,60,270); line(40,215,70,215); line(60,215,40,270); line(70,210,90,210); line(90,210,80,235); line(80,235,80,270); line(80,270,75,268); line(65,235,93,235); } showtime(time_t temp) { setfillstyle(0,0); bar(160,455,360,465); ptr=localtime(&temp); c=asctime(ptr); setcolor(2); if(temp==start) outtextxy(160,20,c); else outtextxy(160,455,c); } } if((fp=fopen("name","r"))!=NULL) { clrscr(); printf("\n\n\n\n\n\n\n"); printf(" "); ch=fgetc(fp); while(ch!=EOF) { putchar(ch); ch=fgetc(fp); } fclose(fp); } printf("\n\n Your score is %d.",score); printf("\n\n You are the best! well done!"); sleep(3); return; } main() { int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,""); welcome(); loop: cleardevice(); init(); randomize(); choosemode(); showface(); waiting(); time(&start); showtime(start); nextblock=createblock(); do { nowblock=nextblock; nextblock=createblock(); drawnext(); while(checkborder()) { } } case p: case P: case s: case S:{waiting();break;} case r: case R:{ setfillstyle(1,1); bar(0,465,640,480); outtextxy(5,469,"Are you sure to restart(Y\\N)..."); while(1) { key=bioskey(0); if(key==y||key==Y) { setfillstyle(0,0); bar(0,465,640,480); goto loop; } if(key==n||key==N) { setfillstyle(0,0); bar(0,465,640,480); break; } } } } } if(dx==0) dy=1; else dy=0; px+=dx,py+=dy; dx=0,dy=0; } for(i=0;i<=3;i++) { FX,FY; grid[x0][y0-1]=2; } renovate(); interval=INTERVAL-level*20; int i,j; int s0,t0; int x0,y0; int i0,j0; int px,py,dx,dy; int score,level; int key,count,num; int interval,mode; int grid[12][21]; time_t start,finish; struct tm *ptr; char *c; struct block nowblock,nextblock; struct block shape[19]={ {0,-1,1,2,0,0,0,0,3,1}, {0,0,0,0,0,-1,1,2,3,0}, {0,-1,0,1,0,0,-1,0,4,3}, {0,0,0,1,0,1,-1,0,4,4}, {0,-1,1,0,0,0,0,1,4,5}, {0,0,0,-1,0,1,-1,0,4,2}, {0,0,0,1,0,1,-1,1,5,7}, {0,-1,1,-1,0,0,0,1,5,8}, {0,0,0,-1,0,1,-1,-1,5,9}, {0,-1,1,1,0,0,0,-1,5,6}, {0,0,0,-1,0,1,-1,1,9,11}, {0,-1,1,-1,0,0,0,-1,9,12}, {0,0,0,1,0,1,-1,-1,9,13}, {0,-1,1,1,0,0,0,1,9,10}, {0,-1,0,1,0,0,1,1,11,15}, {0,0,1,1,0,1,0,-1,11,14}, {0,0,-1,1,0,1,1,0,12,17}, {0,0,1,1,0,-1,0,1,12,16}, {0,0,1,1,0,1,0,1,13,18} }; init() { for(i=0;i<=20;i++) { grid[0][i]=2; grid[11][i]=2; } setfillstyle(1,s0); bar(250,225,395,243); setcolor(0); outtextxy(257,230,"no time limited"); setfillstyle(1,t0); bar(250,255,395,273); setcolor(0); outtextxy(257,260,"time limited(60s)"); } choosemode() { timelimited(15,1); while(1) { key=0; while(bioskey(1)==0); key=bioskey(0); if(key==UP) { timelimited(15,1); mode=1; } if(key==DOWN) { timelimited(1,15); mode=2; } if(key==ENTER) { cleardevice(); break; } } } waiting() { setfillstyle(1,1); bar(0,465,640,480); outtextxy(5,469,"press any key to continue..."); outtextxy(447,390,"W:CHANGE"); outtextxy(447,400,"S&P:PAUSE"); outtextxy(447,410,"R:RESTART"); outtextxy(447,420,"Y:YES"); outtextxy(447,430,"N:NO"); outtextxy(460,220,"SCORE 0"); outtextxy(460,240,"LEVEL 1"); setcolor(14); outtextxy(40,365,"copyright by:"); setcolor(10); outtextxy(40,385,"Wang Wei"); outtextxy(40,395,"wei7ge@163.com"); outtextxy(40,405,"05.8.6"); showlastscore(); } struct block createblock() { struct block newblock=shape [random(19)]; return newblock; } checkborder() { for(i=0;i<=3;i++) { FX+dx,FY+dy; if(y0>=0) if(grid[x0][y0]==2) return 0; if(x0<1||x0>10) return 0; } return 1; } drawnext() { setfillstyle(0,0); bar(440,40,540,140); setfillstyle(1,nextblock.color); for(i=0;i<=3;i++) { else score+=10; level=floor(score/100)+1; } num=0; } } showscore() { char cscore[3],clevel[1]; sprintf(cscore,"%d",score); sprintf(clevel,"%d",level); setfillstyle(0,0); bar(500,220,520,250); outtextxy(507,220,cscore); outtextxy(507,240,clevel); } struct block changeblock() { struct block newblock=nowblock; nowblock=shape[nowblock.next]; if(!checkborder()) { nowblock=newblock; } return nowblock; } drawblock() { for(i=0;i<=3;i++) { FX,FY; if(y0>=0) grid[x0][y0]=1; } renovate(); DELAY; for(i=0;i<=3;i++) { FX,FY; if(y0>=0) grid[x0][y0]=0; gameover() { for(i=19;i>=0;i--) { for(j=1;j<11;j++) grid[j][i]=2; renovate(); delay(7777); } settextstyle(0,0,5); setcolor(4); outtextxy(102,152,"GAME OVER"); DELAY; setcolor(10); outtextxy(100,150,"GAME OVER"); DELAY; setcolor(4); outtextxy(98,148,"GAME OVER"); setcolor(14); settextstyle(0,0,2); outtextxy(212,242,"R--Again!"); outtextxy(222,282,"ESC--Exit!"); DELAY; setcolor(5); outtextxy(210,240,"R--Again!"); outtextxy(224,284,"ESC--Exit!"); } entername() { FILE *fp; char ch; if((fp=fopen("name","w"))!=NULL) { printf("\n\n\n\n\n\n Please enter your name..."); while((ch=fgetchar())!='\n') fputc(ch,fp); fclose(fp); } if((fp=fopen("highscore","w"))!=NULL) { fprintf(fp,"%d",score); fclose(fp); renovate(); drawblock(); while(1) { if(bioskey(1)!=0) key=bioskey(0); else break; switch(key) { case DOWN: case X: case x:{interval=0;break;} case UP: case W: case w:{nowblock=changeblock(); break;} case LEFT: case A: case a:{dx=-1;if(!checkborder()) dx=0;break;} case RIGHT: case D: case d:{dx=1;if(!checkborder()) dx=0;break;} case ESC:{ setfillstyle(1,1); bar(0,465,640,480); outtextxy(5,469,"Are you sure to exit(Y\\N)..."); while(1) { key=bioskey(0); if(key==y||key==Y) { closegraph(); entername(); exit(0); } if(key==n||key==N) { setfillstyle(0,0); bar(0,465,640,480); break; } deline(); showscore(); px=5,py=-1; time(&finish); showtime(finish); if(mode==2) if(difftime(finish,start)>=60) break; }while(checkborder()); gameover(); while(1) { key=bioskey(0); if(key==r||key==R) goto loop; if(key==ESC) { cleardevice(); closegraph(); entername(); exit(0); } } } PAGE 7
/
本文档为【俄罗斯方块】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索