字母落下炸开

来源:互联网 发布:万能标签打印软件 编辑:程序博客网 时间:2024/04/27 16:13
#include <stdio.h>
#include <stdlib.h>
#include <curses.h>

#define DEEP  24
#define BALL  'O'
#define SPACE ' '

void drop();
void brusk(int,int,int);
void Init();

typedef struct{
    char ch;
    int  new_x,new_y;
    int  old_x,old_y;
    int  acc;
    int  dis;
}Chars;

int main(){
    Init();
    drop(40,0);
    move(15,40);

    int i=3;
    while(i--){
        char buf[10];
        move(15,40);
        sprintf(buf,"quit. %d",i);
        addstr(buf);
        refresh();
        sleep(1);
    }
    endwin();
    return 0;
}

void Init(){
    srand(time(0));
    initscr();
    noecho();
    move(0,0);
    int i;
    for(i=0;i<79;i++)
        addch('_');
    move(DEEP-1,0);
    for(i=0;i<79;i++)
        addch('_');
    refresh();
    for(i=0;i<3;i++){
          char str[2];
        sprintf(str,"%d",3-i);
        move(15,40); addstr(str);
        refresh();
        sleep(1);
    }
    mvaddch(15,40,SPACE);
    refresh();
}

void drop(int x,int y){
    int i=0;
    mvaddch(y,x,BALL);
    refresh();
    sleep(1);
    for(i=0;i<DEEP;i++){
        mvaddch(i-1,x,SPACE);
        mvaddch(i,  x,BALL);
        refresh();
        int time = (DEEP-i)*(DEEP-i)*30;
        usleep(time);
    }
    mvaddch(i-1,x,SPACE);
    
    brusk(x,DEEP,rand()%5+5);
}


void brusk(int x,int y,int n){
    int i,j;
    Chars *Bs=(Chars*)calloc(sizeof(Chars),n);
    // 初始化
    for(i=0;i<n;i++){
        Bs[i].ch = 'a'+rand()%24;
        Bs[i].new_x=Bs[i].old_x=x;
        Bs[i].new_y=Bs[i].old_y=y;
        Bs[i].acc = rand()%10-5;
        Bs[i].dis = rand()%10+2;
    }
    while(1){
    int flag = 0;
    for(i=0;i<n;i++){
            Bs[i].new_x-=Bs[i].acc;
            Bs[i].new_y--;
             if(Bs[i].new_x<=0 || Bs[i].new_x>=80 || Bs[i].new_y<=0 || Bs[i].new_y>=24){
             flag++;
            continue;    
        }
        
            mvaddch(Bs[i].old_y,Bs[i].old_x,SPACE);
            mvaddch(Bs[i].new_y,Bs[i].new_x,Bs[i].ch);    
            refresh();
            usleep(10000);
            Bs[i].old_x=Bs[i].new_x;
            Bs[i].old_y=Bs[i].new_y;
        }
        if(flag >= n) break;
    }
}


0 0