小白都能学会的Flappy bird(C++)

小白都能学会的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;
		}
	}
}

实现效果:
在这里插入图片描述

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值