Hello everyone.This is CSDN Chinese website.I made one C/C++ program.Its name is 《flappy bird》.Without further ado.On the code.You can take it.
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include<conio.h>
#define column_num 5 //同一界面存在柱子的数目
/*
《flappy bird》 by:Gardeniall
————————————————————
|控制信号: | 向上 |
——————————————————
| 键盘: | 空格 |
————————————————————
1.小鸟默认向右向下飞,按空格会使小鸟弹起向上
2.小鸟每通过一根柱子,分数加1
3.若小鸟碰到柱子或边框,游戏结束
*/
void HideCursor(){
//隐藏光标位置 ,这个函数复制代码就行
CONSOLE_CURSOR_INFO cursor_info={
1,0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
}
void gotoxy(int x,int y){
//把光标放在(0,0)位置 ,这个函数复制代码就行
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(handle,pos);
}
int IsEnd;//是否结束
int interface_x,interface_y;//界面行数、列数
int scores;//分数
int column_x[column_num+1]; //柱子缺口的起始值
int column_x_long;//柱子缺口的长度
int column_y[column_num+1];//柱子位置
int column_y_width;//柱子宽度
int slow_v,slow_v_num;//移动变慢的值(越大速度越慢),移动变慢的变量
int slow_vbird,slow_vbird_num;//小鸟移动变慢的值(越大速度越慢),移动变慢的变量
int bird_x,bird_y;//小鸟位置
int bird_jump; //小鸟跳跃变量 =0时不跳 =3、2、1时跳跃
void startup(){
//【数据初始化】
int i;
HideCursor();//不显示光标
IsEnd = 0;
interface_x = 22;
interface_y = column_num*15;//此数应该为柱子数column_num的倍数
scores=0;
column_x_long=interface_x/4;//柱子缺口长度是界面长、1/4
for(i=1;i<=column_num;i++){
//柱子缺口起始位置
column_x[i]=rand()%(interface_x/2)+(interface_x/8);//位置有界面/2的选择范围,且下移1/8,不会挨着边界
}
column_y_width=(interface_y*3/2)/column_num/5;//柱子宽度是3/2界面宽/柱子数/5;