小白都能学会的Flappy bird(C++)
话不多说,上代码!
#include<iostream>
#include <conio.h>
#include<cstdlib>
#include<Windows.h>
#include<ctime>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
//用来判断鼠标的
using namespace std;
int sr,zr,xr;
int qk=0;
int bb=40;
int bbb()
{
srand(time(0));
sr=rand()%14+2; //取2~15的数
zr=8;
xr=25-8-sr;
}
void xxx()//墙
{
qk=0;
system("cls");
for(int i=1;i<=sr;i++)
{
for(int l=1;l<=bb;l++)
cout<<" ";
cout<<"|"<<endl;
}
for(int j=1;j<=7;j++)
cout<<endl;
for(int k=1;k<=xr;k++)
{
for(int l=1;l<=bb;l++)
cout<<" ";
cout<<"|"<<endl;
}
bb=bb-1;
if(bb==8)
{
qk=1;
}
if(bb==0)
{
srand(time(0));
sr=rand()%14+2;//2~15
zr=8;
xr=25-8-sr;
bb=40;
}
}
int w(int a,int b)//鸟
{
int q = 0;
while (q != a)
{
cout << endl;
q++;
if (q == 25 || q == 0)
{
return 0;
}
}
cout << " " << "@"<<endl;
q = 0;
while (q != b)
{
cout << endl;
q++;
}
}
int main()
{
int i = 0, x = 12, y = 12, qw = 1;
bbb();
w(x, y);
xxx();
while (1)
{
system("cls"); x = x + 1; y = y - 1; qw = w(x, y);
xxx();
if(qk==1)
if(x>=sr+7||x<sr)
{
system("cls");
cout << "Game Over!";
return 0;
}
while(KEY_DOWN(VK_LBUTTON))//判断是否按下鼠标左键
{
system("cls"); x = x - 1; y = y + 1; qw = w(x, y);
xxx();
if(qk==1)
if(x>=sr+7||x<sr)
{
system("cls");
cout << "Game Over!";
return 0;
}
}
if (qw == 0)
{
system("cls");
cout << "Game Over!";
return 0;
}
}
}
实现效果: