C语言俄罗斯方块游戏源代码.docx_第1页
C语言俄罗斯方块游戏源代码.docx_第2页
C语言俄罗斯方块游戏源代码.docx_第3页
C语言俄罗斯方块游戏源代码.docx_第4页
C语言俄罗斯方块游戏源代码.docx_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

/*学无止境*/#include #include #include #define ESC 27#define UP 328#define DOWN 336#define LEFT 331#define RIGHT 333#define BLANK 32#define BOTTOM 2#define CANNOT 1#define CAN 0#define MAX 30#define F1 315#define ADD 43#define EQUAL 61#define DEC 45#define SOUNDs 115#define SOUNDS 83#define PAUSEP 80#define PAUSEp 112void Init();void Down();void GoOn();void ksdown();void Display(int color);void Give();int Touch(int x,int y,int dx,int dy);int GeyKey();void Select();void DetectFill();void GetScores();void Fail();void Help();void Quit();void DrawBox(int x,int y,int Color);void OutTextXY(int x,int y,char *String);void DispScore(int x,int y,char Ch);void DrawNext(int Color);int Heng=12,Shu=20; /*横竖*/int PositionMAXMAX;int middleMAXMAX;int ActH,ActS;int Act,Staus;int i,j,k;int Wid=10;int NoPass=CAN;float Delays=15000;int BeginH=250,BeginS=7;float Seconds=0;int Scores=0;int flag=1;int Sounds=CAN;int PreAct,NextAct;int a8444=1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,1,1,1,0,0,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,1,1,1,1,0,0,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,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1,0,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,0,1,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0,1,0,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,0,1,1,0,1,1,0,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,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,0,0,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,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,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,0,0,0,1,0,0,0,1,1,0,0,0,0,0,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0;int b44;main(int argc,char *argv)if (argc!=1)if (argv1!=)Heng=atoi(argv1);if (argv2!=)Shu=atoi(argv2);Init(); /*初始化界面*/PreAct=random(8); /*取得当前的方块*/for(;) /*以下是游戏流程*/NextAct=random(8); /*取得下一个方块*/DrawNext(1); /*画出下一个方块*/Act=PreAct;if (Heng%2=0) ActH=Heng/2;else ActH=(Heng-1)/2;ActS=0; /*方块开始从游戏空间的中间下落*/Staus=0; /*取开始的状态*/NoPass=CAN; /*物体可以下落*/Give(); /*取得当前的方块*/Display(Act+1); /*显示当前的方块,每种方块的颜色不同*/GoOn(); /*游戏的算法精髓所在*/PreAct=NextAct; /*方块下落完毕,取得下一个方块*/DrawNext(0);void Init()int GraphDriver=DETECT,GraphMode;registerbgidriver(EGAVGA_driver);initgraph(&GraphDriver,&GraphMode,);if (kbhit() Sounds=CANNOT;setcolor(1);OutTextXY(10,10,Tetris);OutTextXY(30,30,Version 2.0);OutTextXY(10,120,Help:);OutTextXY(20,140,+ :Faster);OutTextXY(20,160,- :Slower);OutTextXY(20,180,Esc :Quit);OutTextXY(20,200,F1 :Help); OutTextXY(10,310,Copyright(c) 1998.2.22); OutTextXY(10,320,By Mr. Unique); outtextxy(10,250,Score: 00000); rectangle(BeginH-3,BeginS-3,BeginH+Heng*(Wid+2)+2,BeginS+Shu*(Wid+2)+2); rectangle(BeginH-5,BeginS-5,BeginH+Heng*(Wid+2)+4,BeginS+Shu*(Wid+2)+4); rectangle(BeginH+(Heng+4)*(Wid+2)-2,BeginS+10,BeginH+(Heng+8)*(Wid+2)+2,BeginS+12+4*(Wid+2); for (i=0;iMAX;i+) for (j=0;jMAX;j+) Positionij=1; middleij=-1; for (i=0;iHeng;i+) for (j=0;jShu;j+) Positionij=0; for (i=0;iHeng;i+) for (j=0;j=Delays) Down(); Seconds=0; if (NoPass=BOTTOM) DetectFill(); middleActHActS=Act; if (ActS=0) Fail(); return; if (kbhit() Select(); void Down() /*方块下降*/ Display(0); if (Touch(ActH,ActS,0,1)=CAN) ActS+; else middleActHActS=Act; Display(Staus+1); int Touch(int x,int y,int dx,int dy) NoPass=CAN; for (i=0;i4;i+) for (j=0;j4;j+) Positionx+dx+iy+dy+j+=bij; for (i=0;iMAX;i+) for (j=0;j1) NoPass=CANNOT; for (i=0;i4;i+) for (j=0;j4;j+) Positionx+dx+iy+dy+j-=bij; middlex+dx+iy+dy+j=Act; if (NoPass=CANNOT & dx=0 & dy=1) for (i=0;i4;i+) for (j=0;j8; return(Low=0?Hig+256:Low); void Select() int OldStaus,acts=ActS; switch(GetKey() case ESC :Quit();break; case DOWN :Seconds+=14500;break; case LEFT :Display(0); if (ActH0 & Touch(ActH,ActS,-1,0)=CAN) ActH-; Display(Act+1);break; case RIGHT :Display(0); if (ActH300) Delays-=100;break; case DEC :if (Delays3000) Delays+=100;break; case PAUSEP : case PAUSEp :getch();break; case SOUNDS : case SOUNDs :if (Sounds=CAN) Sounds=CANNOT; else Sounds=CAN;break; case UP :if(Act=7) while(actsTopScore) setcolor(1); outtextxy(470,80,Hello !); outtextxy(470,100,In all the players,); outtextxy(470,120,You are the First !); outtextxy(470,140,And your score will); outtextxy(470,160,be the NEW RECORD !); fseek(fp,0L,0); fprintf(fp,%d,Scores); fclose(fp); setcolor(1); OutTextXY(470,220,Are You Sure (Yes/no)?); ch=getch(); if (ch=y|ch=Y) closegraph(); delay(20); exit(0); setcolor(0); outtextxy(470,220,Are You Sure (Yes/no)?); void OutTextXY(int x,int y,char *String) int i=0; char a2; moveto(x,y); a1=0; while (*(String+i)!=0) a0=*(String+i); outtext(a); if (Sounds=CAN & a0!= ) sound(3000); delay(50); nosound(); i+; void Help() unsigned Save; void *Buf; Save=imagesize(160,120,500,360); Buf=malloc(Save); getimage(160,120,500,360,Buf); setfillstyle(1,1); bar(160,120,500,280); setcolor(0); OutTextXY(170,130, About & Help); OutTextXY(170,150, # # # # # # # ); OutTextXY(170,160, # # # # # # # # # # ); OutTextXY(170,170, # # # # # ); OutTextXY(170,180, # # # # # # # # # ); OutTextXY(170,190, # # # # # # # # ); OutTextXY(170,200, # # # # # # # # # # # ); OutTextXY(170,210, # # # # # # # # # # ); OutTextXY(170,220, # # # # # # # # # ); OutTextXY(170,230, # # # # # # # ); OutTextXY(170,260, Good Luckly to You ! ); getch(); putimage(160,120,Buf,0); free(Buf); void GetScores() int Sec10000,Sec1000,Sec100,Sec10,Sec1; setfillstyle(0,1); bar(60,250,109,260); Sec1=Scores%10; Sec10=(Scores%100-Scores%10)/10; Sec100=(Scores%1000-Scores%100)/100; Sec1000=(Scores%10000-Scores%1000)/1000; Sec10000=(Scores%100000-Scores%10000)/10000; DispScore(60,250,0+Sec10000); DispScore(70,250,0+Sec1000); DispScore(80,250,0+Sec100); DispScore(90,250,0+Sec10); DispScore(100,250,0+Sec1); DispScore(110,250,0); DispScore(120,250,0); void DispScore(int x,int y,char Ch) char a2; a1=0; a0=Ch; outtextxy(x,y,a); void Give() for (i=0;i4;i+) for (j=0;j4;j+) bij=aActStausij; void Display(int color) for (i=0;i4;i+) for (j=0;j4;j+) if (bij=1) DrawBox(ActH+i,ActS+j,color); void DrawBox(int x,int y,int Color) x=BeginH+x*(Wid+2); y=BeginS+y*(Wid+2); setfillstyle(1,Color)

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论