C语言Turbo C下实现俄罗斯方块

  

本文实例为大家分享了C语言俄罗斯方块的具体代码,供大家参考,具体内容如下

        # include & lt; stdio.h>   # include & lt; dos.h>   # include & lt; conio.h>   # include & lt; graphics.h>   # include & lt; stdlib.h>      # ifdef __cplusplus   #定义__CPPARGS……   其他#   #定义__CPPARGS   # endif   #定义MINBOXSIZE 15/*单方块的大小*/#定义告诉我们7/*背景着色*/#定义GAMEX 200   #定义勇敢的10   #定义利瓦300/*每当玩家打到三百分等级加一级*//*按键码*/#定义x4b00 VK_LEFT 0   #定义x4d00 VK_RIGHT 0   #定义x5000 VK_DOWN 0   #定义x4800 VK_UP 0   #定义x4700 VK_HOME 0   #定义x4f00 VK_END 0   #定义x3920 VK_SPACE 0   #定义x011b VK_ESC 0   #定义x1c0d VK_ENTER 0/*定义俄罗斯方块的方向*/#定义f 0   #定义STARTCOL 20/*要出的下一个方块的纵坐标*/#定义STARTROW 12/*要出的下一个方块的横从标*/#定义WINSROW 14/*游戏屏幕大小*/#定义WINSCOL 20   #定义LWINSCOL 100/*游戏屏幕大显示器上的相对位置*/#定义LWINSROW 60         int gwins [22] [16];/*游戏屏幕坐标*/int坳=1,行=7;/*当前方块的横纵坐标*/int nbx=0,国家统计局=0;/*当前寺块的形壮和方向*/int nextnbx=0, nextnbs=0, maxcol=22;/*下一个方块的形壮和方向*/int minbscolor=6, nextminbscolor=6;   int num=0;/*游戏分*/int leav=0, gameleav[10]={10 18日,16日,14日,12日,8、6、4、2、1},/*游戏等级*//*以下我用了一个3维数组来纪录方块的最初形状和方向*/int boxstastu [7] [4] [16]={{   {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,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,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,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}}      };/*随机得到当前方块和下一个方块的形状和方向*/空白boxrad () {   minbscolor=nextminbscolor;   国家统计局=nextnbs;   nbx=nextnbx;   nextminbscolor=随机(14)+ 1;   如果(nextminbscolor==4 | | nextminbscolor 7==| | nextminbscolor==8)   nextminbscolor=9;   nextnbx=f;   nextnbs=随机(7);   }/*初始化图形模试*/空白init (int gdrive int gmode) {   int错误代码;   initgraph(及gdrive, gmode,“c: \ tc”);   errorcode=graphresult ();   如果(errorcode !=神交){   printf("的错误:% s”, grapherrormsg(错误代码));   退出(1);   }   }/*在图形模式下的清屏*/空白cls ()   {   setfillstyle (SOLID_FILL 0);   改变颜色(0);   栏(0,0640480);   }/*在图形模式下的高级清屏*/空白clscr (int, int b, c int, int, int颜色)   {   setfillstyle (SOLID_FILL、颜色);   改变颜色(颜色);   酒吧(a, b, c, d);   }/*最小方块的绘制*/无效;   (i=1; i<21;我+ +){   0=0;   (j=1; j<15; j + +)   如果(gwins[我][j]==0)   0=1;   如果(0==0){   delcol(我);   delgx + +;   }   }   num=num + delgx * delgx * 10;   leav=num/10000;      sprintf (nm,“% d”, num);   clscr (456173500200 4);   文本(456173年,“数字:1、15);   文本(456193 nm, 1、15);   }/*时间中断结束*/空白消磨时间()   {   禁用();   setvect(计时器,oldhandler);   使();   }/*测试当前方块是否可以向下落*/int downok ()   {   int i, j, k=1, [4] [4];   (i=0; i<16岁;我+ +)   (我/4)[% 4]=boxstastu(国家统计局)[nbx][我];   (i=0; i<4,我+ +)   (j=0; j<4; j + +)   如果([我][j],,gwins[坳+我+ 1][行+ j])   k=0;   返回(k);   }/*测试当前方块是否可以向左行*/int leftok ()   {   int i, j, k=1, [4] [4];   (i=0; i

C语言Turbo C下实现俄罗斯方块