BirdError
//#include<curses.h>
#include<stdlib.h>
#include<signal.h>
#include<time.h>
#define CHAR_BIRD '0'//表示bird
#define CHAR_STONE '*'//表示背景的柱子
#define CHRR_BLANK ' '
/*
**链表表示柱子
*/
typedef struct node
{
int x,y;
struct node *next;
}node,*Node;//node表示结构体数据,Node表示结构体指针类型
Node head,tail;
int bird_x,bird_y;
int ticker;
/**
*函数声明
*/
void init();
void init_bird();
void init_draw();
void init_head();
void init_wall();
void drop(int sig);
int set_ticker(int n);
int set_ticker(int n_msec)
{
struct itimerval timeset;
long n_sec,n_usec;
n_sec = n_msec/;
n_usec = (n_msec%)*1000L;
timeset.it_interval.tv_sec = n_sec;
timeset.it_interval.tv_usec = n_usec;
timeset.it_value.tv_sec = n_sec;
timeset.it_value.tv_usec = n_usec;
return setitimer(ITIMER_REAL,×et,NULL);
}
void drop(int sig)
{
int j;
Node tmp,p;
move(bird_y,bird_x);
addch(CHAR_BLANK);
refresh();
bird_y++;
move(bird_y,bird_x);
addch(CHAR_BIRD);
refresh();
if((char)inch()==CHAR STONE)
{
set_ticker();
sleep();
endwin();
exit();
}
p=head->next;
)
head->next= p->next;
free(p);
tmp = malloc(sizeof(node));
tmp->x = ;
do
{
tail->next = tmp;
tmp->next = NULL;
tail = tmp;
ticker-=;
set_ticker(ticker);
}
for(p = head->next;p->next!=NULL;p->x--,p=p->next>
{
;j<p->y;j++)
move(j,p->x);
addch(CHAR_STONE);
refresh();
}
;j<=;j++)
{
move(j,p->x-);
addch(CHAR_STONE);
refresh();
}
}
}
tail->x--;
}
int main()
{
char ch;
init();
)
{
ch = getch();
if(ch==' '||ch=='w'||ch=='W')
{
move(bird_y,bird_x);
addch(CHAR_BLANK);
refresh();
bird_y--;
move(bird_y,bird_x);
addch(CHAR_BIRD);
refresh();
if((char)inch()==CHAR_STONE)
{
set_ticker();
sleep();
endwin();
exit();
}
}
else if(ch=='z'||ch=='z')
{
set_ticker();
do
{
ch= getch();
}
while(ch!='q'||ch=='Q')
{
sleep();
endwin();
exit();
}
}
;
}
void init()
{
initscr();
cbreak();
noecho();
cur_set();
srand(time());
signal(SIGLRM,drop);
init_bird();
init_head();
init_wall();
init_draw();
sleep();
ticker=;
set_ticker(ticker);
}
void init_bird()
{
bird_x = ;
bird_y = ;
move(bird_y,bird_x);
addch(CHAR_BIRD);
refresh();
sleep();
}
void init_head()
{
Node tmp,p;
p=head;
;i<=;i+=)
{
tmp = malloc(sizeof(node));
tmp->x=i;
do
{
tmp->y = rand()%;
}
);
p->next=tmp;
tmp->next =NULL;
p=tmp;
}
tail = p;
}
void init_draw()
{
Node p;
int i,j;
for(p= head->next;p->next!=NULL;p->next)
{
;i--)
{
;j<p->y;j++)
{
move(j,i);
addch(CHAR_STONE);
refresh();
}
;j<=;j++)
{
move(j,i);
addch(CHAR_STONE);
refresh();
}
}
sleep();
}
}
BirdError的更多相关文章
随机推荐
- 查看https是否支持ATS
nscurl --ats-diagnostics --verbose https://我的域名
- 这是用过的"最差"树形插件
这是用过的"最差"树形插件 !!! 或许大家听过一个bootstrap UI框架---ace皮肤.有兴趣的童鞋可以在线查看:https://www.iteblog.com/ac ...
- 如何用jenkins实现自动化构建新版本和二维码下载
最近公司开发了自己的app,研发过程中对于测试人员来说,经常会像开发的人员询问,有没有最新的包啊(apk打包后的新版本),以免你测试的时候,提交了一些缺陷,实际上人家已经解决了.当然你也可以说你们公司 ...
- 下载VM12 虚拟机和安装kali
为什么现在才写这个-- 因为我在学校啊,学校的电脑还没有kali.好了我们开始. http://www.vmware.com/products/player/playerpro-evaluation ...
- React常用的API说明
楼主刚开始学习react,感受到了他的博大精深,看到很多莫名的用法,不知云云,找了很多没有找到参考手册,只有在中文社区和react官方看了一些,收集了一些比较常用的API,有补充的可以楼下评论补充.后 ...
- 添加系统右键菜单项 管理员取得所有权(W)(带盾牌)
@color 0A @title 添加系统右键菜单项 管理员取得所有权(^&W)(带盾牌) by wjshan0808 @echo off echo * >nul reg add HKC ...
- [原创]java WEB学习笔记103:Spring学习---Spring Bean配置:基于注解的方式(基于注解配置bean,基于注解来装配bean的属性)
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- Android 多媒体视频播放一( 多媒体理解与经验分享)
前言 说到android的多媒体,一把辛酸一把泪,当初听说会多媒体的比较牛掰,公司也有需求,于是乎我也积极的加入研究android多媒体的行列,记得以前刚接触的时候,最开始还是比较头大的,主要是但是很 ...
- 利用Python实现从百度下载图片到本地磁盘
import urllib.request import os import re url=r'http://image.baidu.com/search/index?tn=baiduimage&am ...
- escape(), encodeURI()和encodeURIComponent()(转)
escape(), encodeURI()和encodeURIComponent()是在Javascript中用于编码字符串的三个常用的方法,而他们之间的异同却困扰了很多的Javascript初学 ...