您的位置:首页资讯教你一招 → 教你用c写个能发炮弹的ascii坦克车

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

时间:2009/11/6 11:32:00来源:本站整理作者:我要评论(0)

昨天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       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;
}

相关阅读 cf11周年礼包奖励领取地址 cf11周年礼包活动礼包领取地址2020cf11周年庆轮回活动地址 cf11周年庆轮回活动抽奖地址2019cf火线实验室活动地址2020 cf火线实验室活动抽奖地址2020cf枪王自助餐8月活动地址2019 cf8月枪王自助餐礼包领取地址cf夏日主播大作战活动地址 cf夏日主播大作战礼包抽奖地址2019cf烈火超级翻牌活动地址2019 cf烈火超级翻牌活动抽奖地址2019禁用“Chrome请停用以开发者模式运行的扩展程序”教程cf夏日泳装许愿活动地址2020 cf夏日泳装许愿活动抽奖地址

文章评论
发表评论

热门文章 电视盒子怎么看百度云迅雷9怎么关闭右侧 迅迅雷99.99下载不完怎么网易云音乐怎么上传歌

最新文章 2022支付宝万能福扫福微信迎新春状态怎么设 微信小老虎头像怎么设置 微信ID后面设置小老抖音压岁钱卡怎么获得2022 抖音压岁钱获取方微博隐私保护怎么设置 微博隐私保护功能完善今日头条2022年集卡活动开启时间 今日头条2

人气排行 智学网怎么登录 智学网怎么查分数 智学网统教你怎么写电子邮箱格式?以163和QQ邮箱为例腾讯大王卡用了后悔怎么办 腾讯大王卡值得办缺少或丢失xinput1_3.dll解决方法,xinput1应用程序无法正常启动0xc000007b解决方法快播关闭怎么办?快播不能用了怎么看片将pdf文件转换为word文件的最简单方法如何破解QQ空间密码和权限