用C语言实现的俄罗斯方块的方法

来源:爱站网时间:2021-01-27编辑:网友分享
俄罗斯方块在我们小时候就已经存在了,这款游戏的经典之处,相信不言而喻了,随着互联网的发展我们在网络上制作了俄罗斯方块游戏,这款游戏通常都是使用C语言编写的,不妨在爱站技术频道上详细的了解用C语言实现的俄罗斯方块的方法吧!

俄罗斯方块在我们小时候就已经存在了,这款游戏的经典之处,相信不言而喻了,随着互联网的发展我们在网络上制作了俄罗斯方块游戏,这款游戏通常都是使用C语言编写的,不妨在爱站技术频道上详细的了解用C语言实现的俄罗斯方块的方法吧!

C语言实现俄罗斯方块小游戏的制作代码,具体内容如下

#include  
#include  
#include  
 
 
#define TTY_PATH "/dev/tty" 
#define STTY_ON "stty raw -echo -F" 
#define STTY_OFF "stty -raw echo -F" 
 
int map[21][14]; 
char direct; 
 
int node[7][4][16]={ 
  {{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}, 
   {0,1,0,0,0,1,0,0,0,1,0,0,0,1,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,1,0,0,1,1,1,0,0,0,0,0,0,0,0,0},//3边加一中点 
   {0,1,0,0,0,1,1,0,0,1,0,0,0,0,0,0}, 
   {0,0,0,0,1,1,1,0,0,1,0,0,0,0,0,0}, 
   {0,1,0,0,1,1,0,0,0,1,0,0,0,0,0,0}}, 
  {{0,1,1,0,0,1,0,0,0,1,0,0,0,0,0,0},//右锄头型 
   {0,0,0,0,1,1,1,0,0,0,1,0,0,0,0,0}, 
   {0,1,0,0,0,1,0,0,1,1,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,0,1,0,0,0,1,0,0,0,0,0,0},//左锄头型 
   {0,0,1,0,1,1,1,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,0,1,1,1,0,1,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,1,1,0,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,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}} 
  }; 
 
typedef struct block 
{ 
 int x; 
 int y; 
 int blockType; 
 int blockDirect;  
}Block; 
Block bl; 
 
void init_map()//初始化边框 
{ 
 int i,j; 
 for(i=0; i5 ; i--) 
  for(j = 1; j5; i--) 
 { 
  fals = 1; 
  for(j=1; j=0; i--) 
  for(j=0; j=0; i--) 
  for(j=0; j=0; i--) 
  for(j=0; j 0) 
 {  
   ch = getchar(); 
 }  
 return ch; 
} 
int main()//q 退出游戏,a,d 左右移动,空格变形 
{ 
 srand(time(NULL)); 
 init_map(); 
 new_block(); 
 input(); 
 char ch; 
 int num = 0; 
 while(1) 
 { 
  usleep(500000); 
  system(STTY_ON TTY_PATH); 
  ch = in_direct(); 
  system(STTY_OFF TTY_PATH); 
  system("clear");  
  if(ch == 'a' && num 

以上是爱站技术频道小编为大家介绍的用C语言实现的俄罗斯方块的方法,程序员需要掌握一定的开发技巧,然后利用不同的开发语言进行编程工作。

上一篇:C++开发中结构内存的计算问题

下一篇:C语言开发中调用Swift函数的详解

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载