您的位置:首页 > 其它

字母落下炸开

2015-09-18 09:41 246 查看
#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;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: