VC++ 6.0 C语言实现俄罗斯方块教程

今天把我之前写的大作业分享一下吧,并教你们如何实现,希望你们看了前面的教程也能自己写一个。

1.要先下载一个 graphics.h 的头文件来绘图。

2.初始化窗口:initgraph(x, y);这是先创建一个窗口的函数,以左上角为(0,0),向右为x轴,向下为y轴,其中x表示长x个单位,y表示宽y个单位。

3.关闭图像窗口:closegraph();结束时用来关闭用的。

4.按任意键继续:getch();这个就和getchar();差不多,为了防止以运行完就关了,这样能停顿一下,他的头文件是:conio.h 。

5.画线:line(x1, y1, x2, y2);在你创建的那么窗口里以(x1,y1)和(x2,y2)为两个端点画线。

6.画矩形:rectangle(x1,y1,x2,y2);以(x1,y1)和(x2,y2)为对角画一个矩形。

7.画圆:circle(x,y,r);以(x,y)为圆点,r为半径画圆。

8.颜色:setcolor(x);用来设置颜色的,其中x是你要设置的颜色,可以填这16种:黑 BLACK、蓝 BLUE、绿 GREEN、青 CYAN、红 RED、紫 MAGENTA、棕 BROWN、浅灰 LIGHTGRAY、深灰 DARKGRAY、亮蓝 LIGHTBLUE、亮绿 LIGHTGREEN、亮青 LIGHTCYAN、亮红 LIGHTRED、亮紫 LIGHTMAGENTA、黄 YELLOW、白 WHITE;当然,你也可以根据光的三原色来调自己喜欢的颜色,方法是:setcolor(RGB(x,y,z));其中RGB分别代表红绿蓝,对应的x,y,z是你选的该颜色的多少,范围是[0,255]。



根据上面的这些就能画出很多图形了.比如:

[cpp]  view plain copy
  1. # include <graphics.h>  
  2. # include <conio.h>  
  3.   void main()  
  4.   {     
  5.       initgraph(640,480);  
  6.       setcolor(BROWN);  
  7.       line(200,200,300,130);  
  8.       line(400,200,300,130);  
  9.       rectangle(200,200,400,380);  
  10.       setcolor(RGB(100,150,200));  
  11.       circle(255,260,20);  
  12.       circle(345,260,20);  
  13.       rectangle(280,300,310,360);  
  14.       getch();  
  15.       closegraph();  
  16.   }  


还有这个,画一个圆,圆心是(320,240),半径r=200,根据角度的公式画一个圆:

[cpp]  view plain copy
  1. # include <graphics.h>  
  2. # include <conio.h>  
  3. # include <math.h>  
  4. # define PI 3.1415926  
  5.   void main()  
  6.   {  
  7.       initgraph(640, 480);  
  8.       int x,y,r=200,c;  
  9.       double a;  
  10.       for(a=0; a<PI*2; a+=0.0001)  
  11.       {  
  12.           x=(int)(r*cos(a)+320+0.5);  
  13.           y=(int)(r*sin(a)+240+0.5);  
  14.           c=(int)(a*255/(2*PI));  
  15.           setcolor(RGB(c,200-c/2,100+c/2));  
  16.           line(320,240,x,y);  
  17.       }  
  18.       getch();  
  19.       closegraph();  
  20.   }  


9.停顿:Sleep(x);停顿x/1000秒。

有了Sleep();函数,就能让线动起来了,原理就是:先画一条线,然后再画一条黑色的线覆盖原来的那条,然后再画一条线,这样不断的画线能行了。



[cpp]  view plain copy
  1. # include <graphics.h>  
  2. # include <conio.h>  
  3.   void main()  
  4.   {  
  5.       int i,y;  
  6.       initgraph(640,480);  
  7.       for(y=0;y<480-2;y++)  
  8.       {  
  9.           setcolor(RGB(y,125,y/2%256));  
  10.           line(0,y,639,y);  
  11.           line(0,y+2,639,y+2);  
  12.           Sleep(10);  
  13.           setcolor(BLACK);  
  14.           line(0,y,639,y);  
  15.       }  
  16.       getch();  
  17.       closegraph();  
  18.   }  

10.随机数发生器:srand();使用方法:srand(time(NULL));使用时要有头文件time.h。

11.随机函数:rand();随机生成一个数,头文件是:stdlib.h,比如:

[cpp]  view plain copy
  1. # include <stdio.h>  
  2. # include <time.h>  
  3. # include <graphics.h>  
  4.   void main()  
  5.   {  
  6.       int t=10;  
  7.       while(t--)  
  8.       {  
  9.           srand(time(NULL));  
  10.           printf("%d\n",rand());  
  11.           Sleep(1000);  
  12.       }  
  13. }  


12.判断键盘是否有输入:kbhit();如果有的话返回1,否则返回0.

13.方向键:方健健的ASCII值我们不知道,普通的getchar();也不能输入,但是getch();通过运行程序可以发现方向比较特殊,分别是:上 224+72、下 224+80、左 224+75、右 224+77,就是说他们是由两个字符组成的,所以判断上下左右时就先判断if(kbhit()),然后判断if(getch()==224),如果是的话在判断if(getch()==72),是的话就是上,下左右同理。



[cpp]  view plain copy
  1. # include <stdio.h>  
  2. # include <graphics.h>  
  3. # include <conio.h>  
  4.   void main()  
  5.   {  
  6.       int key;  
  7.       while(1)  
  8.       {  
  9.           if(kbhit())  
  10.           {  
  11.               key=getch();  
  12.               if(key==224)  
  13.                   key=getch();  
  14.               printf("%d",key);  
  15.           }  
  16.           else  
  17.               printf("*");  
  18.           Sleep(500);  
  19.       }  
  20.   }  


14.输出:outtextxy(x,y,s);在坐标为(x,y)的地方输出字符串s。

15.数字转字符串:sprintf(s,"%d",a);将数字a,转化为字符串s,头文件是stdio.h。

16.设置字体:setfont(x,y,"字体");其中x表示你你要输出的字的大小,y会改变形状一般都是设为0,"字体"为你想要输出的字体,比如:setfont(40,0,"楷体");

[cpp]  view plain copy
  1. # include <graphics.h>  
  2. # include <conio.h>  
  3. # include <stdio.h>  
  4.   void main()  
  5.   {  
  6.       char s[10];  
  7.       initgraph(640,480);  
  8.       setfont(42,0,"隶体");  
  9.       outtextxy(200,200,"俄罗斯方块");  
  10.       sprintf(s,"%d",2015);  
  11.       outtextxy(250,250,s);  
  12.       getch();  
  13.       closegraph();  
  14.   }  


上面这些都学会了的话,差不多就能够自己完成编写一个俄罗斯方块了,下面分享一下我写的代码。



[cpp]  view plain copy
  1. # include <stdio.h>  
  2. # include <time.h>  
  3. # include <conio.h>  
  4. # include <graphics.h>  
  5.   int a,visit[30][15],Color[30][15],minX=30,minY=30,maxX=310,maxY=610,speed=500,score=0,rank=0;  
  6.   int color[]={GREEN,CYAN,MAGENTA,BROWN,LIGHTGRAY,LIGHTBLUE,LIGHTGREEN,LIGHTRED,YELLOW};  
  7.   int block[36][5][5]=  
  8.   {  
  9.       {0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0},  
  10.       {0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0},  
  11.       {0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0},  
  12.       {0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0},  
  13.       {0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,1,0,0,0,0,0,0},  
  14.       {0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1,0,0,0,0,0,0,0,0},  
  15.       {0,0,0,0,0,0,1,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0},  
  16.       {0,0,0,0,0,0,0,0,1,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0},  
  17.       {0,0,0,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0},  
  18.       {0,0,0,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0},  
  19.       {0,0,0,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0},  
  20.       {0,0,0,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0},  
  21.       {0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},  
  22.       {0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0},  
  23.       {0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0},  
  24.       {0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0},  
  25.       {0,0,1,1,0,0,0,1,0,0,0,0,1,1,0,0,0,1,0,0,0,0,1,1,0},  
  26.       {0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,1,0,1,0,0,0,0,0},  
  27.       {0,1,1,0,0,0,0,1,0,0,0,1,1,0,0,0,0,1,0,0,0,1,1,0,0},  
  28.       {0,0,0,0,0,1,0,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0},  
  29.       {0,0,0,0,0,0,1,0,1,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0},  
  30.       {0,0,0,0,0,0,0,1,1,0,0,0,1,0,0,0,0,1,1,0,0,0,0,0,0},  
  31.       {0,0,0,0,0,0,1,1,1,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0},  
  32.       {0,1,1,0,0,0,0,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0},  
  33.       {0,0,0,0,0,0,1,1,0,0,0,0,1,0,0,0,0,1,1,0,0,0,0,0,0},  
  34.       {0,0,0,0,0,0,0,0,1,0,0,1,1,1,0,0,1,0,0,0,0,0,0,0,0},  
  35.       {0,0,0,0,0,0,1,1,0,0,0,0,1,0,0,0,0,1,1,0,0,0,0,0,0},  
  36.       {0,0,0,0,0,0,0,0,1,0,0,1,1,1,0,0,1,0,0,0,0,0,0,0,0},  
  37.       {0,0,0,0,0,0,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0},  
  38.       {0,0,0,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0},  
  39.       {0,0,0,0,0,0,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},  
  40.       {0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0},  
  41.       {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},  
  42.       {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},  
  43.       {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},  
  44.       {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0}  
  45.   };  
  46.   void Interface();//界面的设计  
  47.   void nextblock();//生成下一个方块  
  48.   void newblock();//将下一个放到主方框中  
  49.   void move(int x,int y,int A);//移动方块  
  50.   int couldmove(int x0,int y0,int A,char dir,int next);//判断能否移动  
  51.   int couldrotate(int x0,int y0,int A,int next);//判断能否旋转  
  52.   void mark(int x0,int y0,int A,int next);//标记方块固定后的位置  
  53.   void full();//判断有没有能够消行的  
  54.   void down(int x);//有消行的将上面的方块下移一行  
  55.   int gameover();//判断游戏是否结束  
  56.   int main()  
  57.   {  
  58.       int i,j;  
  59.       Interface();  
  60.       nextblock();  
  61.       Sleep(500);  
  62.       memset(visit,0,sizeof(visit));  
  63.       while(1)  
  64.       {  
  65.       newblock();  
  66.       full();  
  67.       if(gameover())  
  68.           break;  
  69.       }  
  70.       getch();  
  71.       closegraph();  
  72.       return 0;  
  73.   }  
  74.   void Interface()  
  75.   {  
  76.       int i,j;  
  77.       char str[10];  
  78.       initgraph(550, 660);  
  79.       HWND hwnd = GetHWnd();  
  80.       SetWindowText(hwnd, "NEW俄罗斯方块                 制作:丶阿明");  
  81.       Sleep(2000);  
  82.       setfont(40,0,"隶体");  
  83.       setcolor(RED);  
  84.       outtextxy(145,200,"NEW");  
  85.       setfont(40,0,"楷体");  
  86.       for(i=0;i<=255;i++)  
  87.           for(j=0;j<=255;j++)  
  88.           {  
  89.               setcolor(RGB((i+j+128)%255,i,j));  
  90.               outtextxy(205,200,"俄罗斯方块!");  
  91.           }  
  92.           Sleep(2000);  
  93.           setcolor(YELLOW);  
  94.           setfont(22,0,"隶体");  
  95.           outtextxy(310,300,"←_←");  
  96.           setfont(22,0,"楷体");  
  97.           outtextxy(180,300,"这逼装的可以");  
  98.           setcolor(LIGHTMAGENTA);  
  99.           Sleep(2500);  
  100.           outtextxy(175,300,"请按任意键开始游戏!");  
  101.           getch();  
  102.           cleardevice();  
  103.           setcolor(WHITE);  
  104.           rectangle(29,29,334,633);  
  105.           rectangle(28,28,335,634);  
  106.           rectangle(370,50,515,195);  
  107.           setfont(24,0, "楷体");  
  108.           setcolor(LIGHTGRAY);  
  109.           outtextxy(405,215,"下一个:");  
  110.           setcolor(RED);  
  111.           outtextxy(405,280,"分数:");  
  112.           sprintf(str,"%d",score);  
  113.           outtextxy(415,310,str);  
  114.           outtextxy(405,375,"等级:");  
  115.           sprintf(str,"%d",rank);  
  116.           outtextxy(425,405,str);  
  117.           setfont(22,0, "楷体");  
  118.           setcolor(LIGHTBLUE);  
  119.           outtextxy(390,475,"操作说明:");  
  120.           outtextxy(390,500,"↑: 旋转");  
  121.           outtextxy(390,525,"↓: 下降");  
  122.           outtextxy(390,550,"←: 左移");  
  123.           outtextxy(390,575,"→: 右移");  
  124.           outtextxy(390,600,"空格: 暂停");  
  125.   }  
  126.   void nextblock()  
  127.   {  
  128.       int i,j,x=391,y=71;  
  129.       setfont(23,0,"楷体");  
  130.       setcolor(BLACK);  
  131.       for(i=0;i<5;i++)  
  132.           for(j=0;j<5;j++)  
  133.               outtextxy(x+20*j,y+20*i,"■");  
  134.           srand(time(NULL));  
  135.           a=rand()%9;  
  136.           setcolor(color[a]);  
  137.           for(i=0;i<5;i++)  
  138.               for(j=0;j<5;j++)  
  139.                   if(block[4*a][i][j]==1)  
  140.                       outtextxy(x+20*j,y+20*i,"■");  
  141.   }  
  142.   void newblock()  
  143.   {  
  144.       int i,j,x=130,y=30,A=a;  
  145.       if(A==0||A==1||A==6)  
  146.           y-=60;  
  147.       else if(A==2||A==3||A==5||A==7||A==8)  
  148.           y-=40;  
  149.       else  
  150.           y-=80;  
  151.       setfont(23,0,"楷体");  
  152.       setcolor(color[A]);  
  153.       for(i=0;i<5;i++)  
  154.           for(j=0;j<5;j++)  
  155.               if(block[4*A][i][j]==1&&y+20*i>=30)  
  156.                   outtextxy(x+20*j,y+20*i,"■");  
  157.               Sleep(100);  
  158.               nextblock();  
  159.               move(x,y,A);  
  160.   }  
  161.   void move(int x,int y,int A)  
  162.   {  
  163.       int i,j,f,k=0,next=0,Speed=speed,key,nex;  
  164.       while(1)  
  165.       {  
  166.           f=couldmove(x,y+k,A,'x',next);  
  167.           if(f==0)  
  168.           {  
  169.               mark(x,y+k,A,next);  
  170.               break;  
  171.           }  
  172.           if(kbhit())  
  173.           {  
  174.               key=getch();  
  175.               if(key==32)  
  176.                   getch();  
  177.           }  
  178.           setcolor(BLACK);  
  179.           for(i=0;i<5;i++)  
  180.               for(j=0;j<5;j++)  
  181.                   if(block[4*A+next][i][j]==1&&y+20*i+k>=30)  
  182.                       outtextxy(x+20*j,y+20*i+k,"■");  
  183.                   if(kbhit())  
  184.                   {  
  185.                       key=getch();  
  186.                       if(key==72)  
  187.                       {  
  188.                           nex=(next+1)%4;  
  189.                           if(couldrotate(x,y+k,A,nex))  
  190.                               next=nex;  
  191.                       }  
  192.                       else if(key==80)  
  193.                           Speed=50;  
  194.                       else if(key==75&&couldmove(x,y+k+20,A,'z',next))  
  195.                           x-=20;  
  196.                       else if(key==77&&couldmove(x,y+k+20,A,'y',next))  
  197.                           x+=20;  
  198.                   }  
  199.                   setcolor(color[A]);  
  200.                   for(i=0;i<5;i++)  
  201.                       for(j=0;j<5;j++)  
  202.                           if(block[4*A+next][i][j]==1&&y+20*i+k+20>=30)  
  203.                               outtextxy(x+20*j,y+20*i+k+20,"■");  
  204.                           Sleep(Speed);  
  205.                           k+=20;  
  206.               }  
  207.   }  
  208.   int couldmove(int x0,int y0,int A,char dir,int next)  
  209.   {  
  210.       int i,j,x,y,f=1;  
  211.       x=(y0-minY)/20;  
  212.       y=(x0-minX)/20;  
  213.       if(dir=='x')  
  214.       {  
  215.           for(i=0;i<5;i++)  
  216.               for(j=0;j<5;j++)  
  217.               if(block[4*A+next][i][j]==1&&(x+i+1==30||(x+i+1>=0&&x+i+1<30&&y+j>=0&&y+j<15&&visit[x+i+1][y+j]==1)))  
  218.                   f=0;  
  219.       }  
  220.       else if(dir=='z')  
  221.       {  
  222.           for(i=0;i<5;i++)  
  223.               for(j=0;j<5;j++)  
  224.                   if(block[4*A+next][i][j]==1&&(y+j==0||(x+i>=0&&x+i<30&&y+j-1>=0&&y+j-1<15&&visit[x+i][y+j-1]==1)))  
  225.                       f=0;  
  226.       }  
  227.       else if(dir=='y')  
  228.       {  
  229.           for(i=0;i<5;i++)  
  230.               for(j=0;j<5;j++)  
  231.                   if(block[4*A+next][i][j]==1&&(y+j+1==15||(x+i>=0&&x+i<30&&y+j+1>=0&&y+j+1<15&&visit[x+i][y+j+1]==1)))  
  232.                       f=0;  
  233.       }  
  234.       return f;  
  235.   }  
  236.   int couldrotate(int x0,int y0,int A,int next)  
  237.   {  
  238.       int i,j,x,y,f=1;  
  239.       x=(y0-minY)/20;  
  240.       y=(x0-minX)/20;  
  241.       if(!couldmove(x0,y0,A,'x',next))  
  242.           f=0;  
  243.       for(i=0;i<5;i++)  
  244.           for(j=0;j<5;j++)  
  245.               if(block[4*A+next][i][j]==1&&(y+j==-1||y+j==15||(x+i>=0&&x+i<30&&y+j>=0&&y+j<15&&visit[x+i][y+j]==1)))  
  246.                   f=0;  
  247.               return f;  
  248.   }  
  249.   void mark(int x0,int y0,int A,int next)  
  250.   {  
  251.       int i,j,x,y;  
  252.       x=(y0-minY)/20;  
  253.       y=(x0-minX)/20;  
  254.       for(i=0;i<5;i++)  
  255.           for(j=0;j<5;j++)  
  256.               if(block[4*A+next][i][j]==1)  
  257.               {  
  258.                   visit[x+i][y+j]=1;  
  259.                   Color[x+i][y+j]=color[A];  
  260.               }  
  261.   }  
  262.   void full()  
  263.   {  
  264.       int i,j,k=0;  
  265.       char str[10];  
  266.       for(i=29;i>=0;i--)  
  267.       {  
  268.           for(j=0;j<15;j++)  
  269.               if(visit[i][j]==0)  
  270.                   break;  
  271.               if(j==15)  
  272.               {  
  273.                   k++;  
  274.                   down(i);  
  275.                   i++;  
  276.               }  
  277.       }  
  278.       setcolor(RED);  
  279.       score+=10*k;  
  280.       sprintf(str,"%d",score);  
  281.       outtextxy(415,310,str);  
  282.       rank=(score/50);  
  283.       sprintf(str,"%d",rank);  
  284.       outtextxy(425,405,str);  
  285.       speed=500-100*rank;  
  286.       if(speed==0)  
  287.           speed=100;  
  288.       if(score>=300)  
  289.           speed=75;  
  290.   }  
  291.   void down(int x)  
  292.   {  
  293.       int i,j;  
  294.       for(i=x;i>0;i--)  
  295.           for(j=0;j<15;j++)  
  296.               if(visit[i-1][j]==1)  
  297.               {  
  298.                   visit[i][j]=visit[i-1][j];  
  299.                   Color[i][j]=Color[i-1][j];  
  300.                   setcolor(Color[i-1][j]);  
  301.                   outtextxy(minX+20*j,minY+20*i,"■");  
  302.               }  
  303.               else  
  304.               {  
  305.                   visit[i][j]=visit[i-1][j];  
  306.                   setcolor(BLACK);  
  307.                   outtextxy(minX+20*j,minY+20*i,"■");  
  308.               }  
  309.               setcolor(BLACK);  
  310.               for(j=0;j<15;j++)  
  311.               {  
  312.                   visit[0][j]=0;  
  313.                   outtextxy(minX+20*j,minY,"■");  
  314.               }  
  315.   }  
  316.   int gameover()  
  317.   {  
  318.       int i,j;  
  319.       for(i=0;i<15;i++)  
  320.           if(visit[0][i]==1)  
  321.           {  
  322.               for(i=0;i<=7;i++)  
  323.               {  
  324.                   setcolor(RGB(35*i,255-35*i,255));  
  325.                   for(j=i;j<30-i;j++,Sleep(20))  
  326.                       outtextxy(30+20*i,30+20*j,"■");  
  327.                   for(j=i;j<15-i;j++,Sleep(20))  
  328.                       outtextxy(30+20*j,30+20*(29-i),"■");  
  329.                   for(j=30-1-i;j>=i;j--,Sleep(20))  
  330.                       outtextxy(30+20*(14-i),30+20*j,"■");  
  331.                   for(j=15-1-i;j>=i;j--,Sleep(20))  
  332.                       outtextxy(30+20*j,30+20*i,"■");  
  333.               }  
  334.               setcolor(WHITE);  
  335.               setfont(45,0,"隶体");  
  336.               outtextxy(75,300,"GAME OVER!");  
  337.               Sleep(5000);  
  338.               return 1;  
  339.           }  
  340.           return 0;  
  341.   }  




我设置的一行能放15个小格子,一共能放30行,二维数组visit[30][15],来判断某个位置是否有方块,比如visit[29][5]=1表示第30行第6个方块的位置有方块了,0表示没方块,Color[30][15]用来记录某个位置的方块的颜色。minX=30,minY=30表示左上角的方块也就是第1行第1列的方块对应在界面的坐标,maxX,maxY同理。speed表示方块的下落速度,一开始初始化为500,没0.5s往下落一行,score记录分数,每消一行加10分,rank表示等级,每50分等级+1,且速度减100,当速度减到100时,就不变了,只有当分数超过300速度才会减为75,且以后都不会再减少了。

我一个设计了9种方块,每种方块都有4种形态,每顺时针旋转90°就有一种形态,所以一共是36个方块。每个方块都用5*5的二维数组来表示,36种就是36个二维数组,所以用block[36][5][5]来表示,block[k][5][5],(k<36&&k%4==0)表示每种方块的初始形态,k+1,+2,+3,分别表示第k种方块选择90°、180°、270°之后的形态。比如block[1][5][5]保存的是第1种方块旋转90°的方块,其中block[1][i][j]=1表示这个方块第i+1行,j+1列有一个小方块,=0代表没有,所以我的block[36][5][5],有36行,一行25个数列,表示一种方块。一维数组color[]依次表示9种方块的颜色。

附上效果图:
















  • 14
    点赞
  • 55
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值