首页 电脑 电脑学堂 查看内容

用c写个能发炮弹的ascii坦克车

2009-11-3 15:01 724 0

摘要: 昨天yangxi推荐unbunt下的一个ascii动画, 有兴趣的可以apt-get install sl看下效果。今天中午利用休息的时间写了类似的程序, 绝对比那个震撼, 有兴趣的朋友可以拿gcc编...
关键词: perl install CPAN 如果 有下载 ptkdb XXXX http 工具箱 PLmakemake

昨天yangxi推荐unbunt下的一个ascii动画, 有兴趣的可以apt-get install sl看下效果。今天中午利用休息的时间写了类似的程序, 绝对比那个震撼, 有兴趣的朋友可以拿gcc编译下看看效果。BTW: 程序员们赶快行动起来吧, Program Just For Fun!/** Program Just For Fun** by wzt       http://hi.baidu.com/wzt85*/#include <stdio.h>#include <stdlib.h>#include <string.h>#define LENTH           7#define WIDTH           155#define SLEEP_TIME      30000#define ENTER_NUM       20char 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;}
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部