字母落下炸开
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;
}
}
#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;
}
}
相关文章推荐
- iOS 面试总结
- 修改LinearLayout中子控件TextView点击颜色小结
- iOS采用手动发布app到appStore
- Wcf 第一个项目
- C语言中数组的几种输入
- Java基础知识强化24:Java中异常
- Web设计中打开新页面或页面跳转的方法
- 举例详解iOS开发过程中的沙盒机制与文件
- 安装nagios后,通过Apache访问nagios不能正常访问,总是下载index.php
- 拖放转换 批量转换 xls 2 txt
- C语言读入多组数并打印数值和
- Error:(27, 42) 错误: <匿名com.jeff.networktest.MainActivity$1>不是抽象的, 并且未覆盖Handler中的抽象方法publish(LogRecord
- 抄 c#邮件发送 关于邮箱的端口号及SMTP 服务器
- centOS7 修改hostname
- 建造者模式
- iOS项目发布流程
- StackEdit Windows本地服务器搭建
- Emgu安装配置及使用
- JS实现很实用的对联广告代码(可自适应高度)
- 对象中的前8字节就是isa指针