/******************************
*
* 还是问题多多,下降到最底的时候不能实现左插和右插,
* 按下键不能准确迅速的下滑到底。有待改进!!
*
*******************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
#include <signal.h>
#include <sys/time.h>
#define W 20
#define H 30
unsigned int tt=0;
int av = 0, fla_n=1, fla_r = 1, fla_l = 1, much=0;
int n=0,m=0,g=0,t=0,coulor=0,score=0; //图形预览标号,设置成全局变量。
int ox = 9, oy = 0; //图形的基座标。
int a,b;
//char cra[H][W];
struct Bshar{
char std;
int Bclor;
};
struct Sshar{
int str[4][4];
int Sclor;
};
struct Bshar cra[H][W];
struct Sshar stu[28]={
{
{
{1,1,0,0}, // * 0
{1,0,0,0}, // *
{1,0,0,0}, // * *
{0,0,0,0}
},
0
},
{
{
{1,1,1,0}, // *
{0,0,1,0}, // * * *
{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
},
{
{
{1,0,0,0}, // * * *
{1,1,1,0}, // *
{0,0,0,0},
{0,0,0,0}
},
0
},
{
{
{1,1,1,0}, // * 1
{0,1,0,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
},
{
{
{0,1,0,0}, //
{1,1,1,0}, // * * *
{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}
},
0
},
{
{
{1,1,1,0}, // * 2
{1,0,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}
},
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,1,0,0}, // * 3
{1,1,0,0}, // * *
{1,0,0,0}, // *
{0,0,0,0}
},
0
},
{
{
{1,1,0,0}, //
{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}
},
0
},
{
{
{1,1,0,0}, //
{0,1,1,0}, // * *
{0,0,0,0}, // * *
{0,0,0,0}
},
0
},
{
{
{1,1,1,1}, // 4
{0,0,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}
},
0
},
{
{
{0,1,0,0}, // *
{0,1,0,0}, // *
{0,1,0,0}, // *
{0,1,0,0} // *
},
0
},
{
{
{1,0,0,0}, // * 5
{1,1,0,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}
},
0
},
{
{
{1,0,0,0}, // *
{1,1,0,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}
},
0
},
{
{
{1,1,0,0}, // 6
{1,1,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}
},
0
},
{
{
{1,1,0,0}, //
{1,1,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}
},
0
},
};
int intsys(void)
{
int i,j;
for(i=0;i<30;i++)
{
for(j=0;j<20;j++)
{
cra[i][j].std ='+';
cra[i][j].Bclor = 47;
}
}
printf("\033[1;1H");
printf("\033[2J");
return 0;
}
void func(int no)
{
// if(oy<29)
// oy++;
tt++;
if(tt==30)
{
if(oy<29)
oy++;
tt=0;
}
sharp();
_much();
clear_line();
show();
fflush(NULL);
}
int show(void)
{
int i,j;
printf("\033[1;1H");
for(i=0;i<30;i++)
{
for(j=0;j<20;j++)
{
switch (cra[i][j].std)
{
case '+':
// printf("\033[47m \033[0m");□ □ ┊
// printf("\033[4m\033[%dm□ \033[0m",cra[i][j].Bclor+2 );
printf("\033[%dm□ \033[0m",cra[i][j].Bclor+2 );
break;
case '^':
printf("\033[%dm※ \033[0m",cra[i][j].Bclor );
break;
case '#':
printf("\033[%dm※ \033[0m",cra[i][j].Bclor );
break;
}
}
printf("\n");
}
printf("\033[26;50H");
for(i=3;i>=0;i--)
{
for(j=0;j<4;j++)
{
switch ( stu[ 4 * m + g ].str[i][j] )
{
case 0:
{
// printf("\033[4m\033[47m__\033[0m");
printf("\033[47m□ \033[0m");
break;
}
case 1:
printf("\033[%dm※ \033[0m",m+40);
//stu[ 4 * m + g ].Sclor + 40);
break;
}
}
printf("\033[%d;%dH",30-i,50);
}
printf("\033[15;50H");
printf("score : %d",score);
printf("\033[50;50H");
return 0;
}
int _much(void) // 在右边框变形出框界的处理。
{
if(much!=0)
{
while(much!=0)
{
// printf("af:%d ox:%d\n",much,ox);
// getchar();
ox--;
much--;
}
// much=0;
sharp();
}
}
int clear_sharp(void)
{
int i,j;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(b-i>=0)
{
if(cra[b-i][a+j].std == '^' && cra[b-i][a+j].std != '#')
{
cra[ b - i ][ a + j ].std = '+';
cra[ b - i ][ a + j ].Bclor = 47;
}
}
}
}
}
int clear_line(void)
{
int i,j,r,s;
for(i=29;i>=0;i--)
{
// for(j=0;j<20;j++)
j=0;
while ( cra[i][j++].std=='#' )
{
if(j==20)
{
while( j-- )
{
cra[i][j].std='+';
cra[i][j].Bclor = 40+rand()%7;
}
usleep(10000);
for(r=i;r>0;r--)
{
for(s=0;s<20;s++)
{
cra[r][s].std=cra[r-1][s].std;
cra[r][s].Bclor=cra[r-1][s].Bclor;
}
}
score++;
break;
}
}
}
}
int next(void)
{
}
int sharp(void)
{
int x=0,y=0,_x=0,_y=0;
int i,j;
fla_r = 1;
fla_l = 1;
fla_n = 1;
if(av == 1)
{
ox = 9;
oy = 0;
t=m;
n=g;
m=rand()%7;
g=rand()%4;
coulor=(rand()+2)%10;
av = 0;
}
else
clear_sharp();
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
// if( stu[ i + t * 16 + 4 * n ][j] != 0 )
if(stu[ 4 * t + n ].str[i][j] != 0 )
{
_x = j;
_y = i;
x = ox + _x;
y = oy - _y;
if(( x + 1 ) > 19 ||(cra[y][ x + 1].std == '#' ))
{
fla_r = 0; //作为判断不能右移的标志。
}
if(( x - 1 ) < 0 ||cra[y][x - 1].std == '#' )
{
fla_l = 0; //作为判断不能左移的标志。
}
if(cra[y][x].std == '#' && cra[y][ox+2].std =='#')
{
if( (x-ox-1) > much)
much= x - ox - 1 ;
}
if(cra[y][x].std =='#' && cra[y][ox+3].std == '#' )
{
if((x-ox-2 > much ))
much = x-ox-1;
}
if(cra[y][ox-1].std =='#')
{
fla_n = 0;
}
if( x > 19 )
{
if( x - 19 > much )
much=x-19; //计算出因为变形而多出右边框的部分。
} //左边不用判断
/*
if( cra[y+1][x].std != '#')
if( cra[y+1][x].std != '#')
{
}
*/
if((oy == 29 || cra[y+1][x].std == '#')&& much ==0 )
{
av = 1; //下降到了终点标志。
}
if ( oy == 0 && cra[y+1][x].std == '#' )
{
printf("\033[34;0H");
printf("GAME OVER !!");
system("stty echo");
system("stty icanon");
没有合适的资源?快使用搜索试试~ 我知道了~
eluos.zip_eluos_linux_out
共1个文件
c:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 157 浏览量
2022-09-19
17:58:00
上传
评论
收藏 3KB ZIP 举报
温馨提示
linux下shell下的俄罗斯方块游戏的源代码,在终端下直接用gcc编译这个c源代码后执行生成的.out文件即可使用。实现了所有功能:7种图形的变形和左右移动以及快速下落,消隐功能,记录积分等,其中包括到边界变形的问题的算法,例如:图形靠近边界时可能出现的出界和异常显示的问题。同时利用信号量产生定时下落和变形操作不冲突的问题。当然也有不足之处,就是未实现图形下落到底时进行左插和右插到空挡位置的功能。希望能和大家交流交流做一定的改进。
资源详情
资源评论
资源推荐
收起资源包目录
eluos.zip (1个子文件)
eluos.c 10KB
共 1 条
- 1
寒泊
- 粉丝: 75
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0