欢迎您阅读本文,今天小编为你分享的电脑教程是:【教你用c写个能发炮弹的ascii坦克车】,下面是详细的讲解!
教你用c写个能发炮弹的ascii坦克车
昨天yangxi推荐unbunt下的一个ascii动画, 有兴趣的可以apt-get install sl看下效果。
今天中午利用休息的时间写了类似的程序, 绝对比那个震撼, 有兴趣的朋友可以拿gcc编译下看看效果。
BTW: 程序员们赶快行动起来吧, Program Just For Fun!
#include
#include
#include
#define LENTH 7
#define WIDTH 155
#define SLEEP_TIME 30000
#define ENTER_NUM 20
char fun_ascii[LENTH][WIDTH]={
" | ",
" _\\--__|_ ",
" II=======OOOOO[/ *02 ___| ",
" ____\\______|/-----.",
" /____________________|",
" \\@@@@@@@@@@@@@@@@@@@/ ",
" ~~~~~~~~~~~~~~~~~~~ "
};
int g_shoot_pos;
int g_shoot_pos_static;
void display_ascii(void);
void print_enter(void);
void move_ascii(void)
{
int i, j;
for (i=0; i < LENTH; i++) {
for (j=0; j < WIDTH; j++) {
if (fun_ascii[i][j] !=' ') {
fun_ascii[i][j - 1]=fun_ascii[i][j];
fun_ascii[i][j]=' ';
}
}
}
}
void shoot_init(void)
{
int i, j;
for (j=0; j < WIDTH; j++) {
if (fun_ascii[2][j] !=' ')
break;
}
--j;
g_shoot_pos_static=g_shoot_pos=j;
}
void shoot_begin(void)
{
fun_ascii[2][g_shoot_pos]='O';
system("clear");
print_enter();
display_ascii();
fun_ascii[2][g_shoot_pos]=' ';
}
void shoot_ascii(void)
{
int i;
i=WIDTH / 2 - 1;
while (i > 0 && g_shoot_pos > 0) {
shoot_begin();
g_shoot_pos--;
usleep(SLEEP_TIME);
i--;
}
}
void do_shoot_ascii(void)
{
int i=3;
shoot_init();
while (i > 0) {
shoot_ascii();
g_shoot_pos=g_shoot_pos_static;
i--;
}
}
void display_ascii(void)
{
int i, j;
for (i=0; i < LENTH; i++) {
for (j=0; j < WIDTH; j++)
printf("%c", fun_ascii[i][j]);
printf("\n");
}
}
void print_enter(void)
{
int i;
for (i=0; i < ENTER_NUM; i++)
printf("\n");
}
int main(void)
{
int i=WIDTH;
while (i > 0) {
if (i==(WIDTH / 2)) {
do_shoot_ascii();
i--;
continue;
}
system("clear");
print_enter();
move_ascii();
display_ascii();
i--;
usleep(SLEEP_TIME);
}
return 0;
}
关于教你用c写个能发炮弹的ascii坦克车的用户互动如下:
相关问题:关于 五子棋和坦克大战的 编程思想
答:判断最后一次下的坐标,及8个方向的棋子,如果满足赢的条件,就胜啦 坦克坐标判断移动,发消息给服务端,客户端用消息判断按下还是按祝 www.csyjx.com(郁金香精品装饰建材城) >>详细
相关问题:小时候玩的街机和电视游戏机有个游戏“两个小人,从...
答:革命英雄 也叫古巴英雄 >>详细
相关问题:请给我写个,用C语言做的,10进制转换ASCII的程序...
答:1、ASCII码 指的是用固定的十六进制代码表示在通用设备上现实的字符,例如:0x30 就代表字符 0。十进制就是常见的数字,例如:10,178,2919199等等;C语言中,ASCII码一般用于LCD模块显示字符,或串口打印字符的转换等等。常用的数值是十进制和... >>详细
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
