1 Star 0 Fork 0

七点/muxi

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
flappy bird.cpp 1.67 KB
一键复制 编辑 原始数据 按行查看 历史
七点 提交于 2019-06-08 14:51 +08:00 . flappy bird
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<windows.h>
//全局变量
int high, width; //游戏画面大小
int bird_x, bird_y; //小鸟的坐标
int bar1_y, bar1_xDown, bar1_xTop; //障碍物
int score; //得分,经过障碍物的个数
void gotoxy(int x, int y) //将光标移动到(x,y)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(handle, pos);
}
void startup() //数据的初始化
{
high = 20;
width = 50;
bird_x = high / 2;
bird_y = 3;
bar1_y = width / 2;
bar1_xDown = high / 3;
bar1_xTop = high / 2;
score = 0;
}
void show() //显示画面
{
gotoxy(0, 0);
int i, j;
for (i = 0; i < high; i++)
{
for (j = 0; j < width; j++)
{
if ((i == bird_x) && (j == bird_y))
printf("@"); //输出小鸟
else if ((j == bar1_y) && (i < bar1_xDown) || (i > bar1_xTop))
printf("*"); //输出墙壁
else
printf(" "); //输出空格
}
printf("\n");
}
printf("得分: %d\n", score);
}
void updateWithoutInput() //与用户输入无关更新
{
bird_x++;
bar1_y--;
if (bird_y == bar1_y)
{
if ((bird_x >= bar1_xDown) && (bird_x <= bar1_xTop))
score++;
else
{
printf("游戏失败\n");
system("pause");
exit(0);
}
}
}
void updateWithInput() ///与用户输入有关的更新
{
char input;
if (kbhit()) //判断是否输入有关
{
input = getch(); //根据用户的不同输入来移动,不必输入回车
if (input == ' ')
bird_x = bird_x - 2;
}
}
int main()
{
startup(); //数据的初始化
while (1) //游戏循环执行
{
show(); //显示画面
updateWithoutInput(); ///与用户输入无关的更新
updateWithInput(); //与用户输入有关更新
}
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/muxixixi/muxi.git
[email protected]:muxixixi/muxi.git
muxixixi
muxi
muxi
master

搜索帮助