DEVC++跳鸟游戏

#include<iostream>
#include<cstdlib>
#include<conio.h>
#include<windows.h>
using namespace std;
int x=50;  //边界的x和y
int y=20;
int birdx=x/5;
int birdy=y/4;
int speed=0;//控制速度
int speed2=0;//控制障碍物的来临速度
int xx=x/2;//障碍物的x坐标
int yy= rand()%(y/2);

int count=0;//记录笨鸟的得分


void notin();
void in();
void gotoxy(int x,int y) {
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	COORD pos;
	pos.X=x;
	pos.Y =y;
	SetConsoleCursorPosition(handle,pos);
}
void HideCursor() {
	CONSOLE_CURSOR_INFO cursor_info= {1,0};
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
}
void show() { //开始的初始化(达到循环显示的目的)
	gotoxy(0,0) ;
	HideCursor()   ;
	for(int i=1; i<y; ++i) {
		for(int j=1; j<x; ++j) {
			if(j==birdx&&i==birdy) {
				cout<<"\b"<<"鸟"; //\b的作用是因为输出的汉字多占了一个大小的空间,\b删除之前一个位置的输出
			} else if(j==xx&&(i>=1&&i<=yy)||j==xx&&(i>=yy+5&&i<=y))
				cout<<"*" ;
			else if(i==1||i==y-1) {
				cout<<"*";
			} else if(j==1||j==x-1) {
				cout<<"*";
			} else
				cout<<" ";
		}
		cout<<endl;
	}

	cout<<"得分:"<<count/6<<endl;

}
void in() {
	if(kbhit()) {
		string ss;
		ss=getch();

		if(ss==" ") {
			if(birdy>3)birdy-=3;
		}


	}
}
void notin() { //改变小鸟的位置和障碍物的位置
	if (birdx==xx&& (birdy>=yy&&birdy<=yy+5))
		count+=1;

	if(speed!=3) {
		speed++;
	}
	if(birdy!=y&&speed==3) {
		birdy+=1;
		speed=0;
	}


	if(speed2!=5) {
		speed2++;
	} else if(speed2==5) {
		if(xx>0) {
			xx--;

		}


		if(xx==0) {
			xx=x/2;//障碍物的x坐标
			yy= rand()%(y/2);
			while(yy==0) {
				yy= rand()%(y/2);
			}

		}
		speed2=0;

	}



}
int main() {
	while(yy==0) {
		yy= rand()%(y/2);
	}
	while(1) {


		show();
		notin();
		in() ;
		if(birdx==xx&&(((birdy>1&&birdy<yy))||(birdy >yy+5&&birdy<y))) {
			cout<<"YOU CRASH INTO PIPELINE!"<<endl;
			return 0;;
		}
		if(birdy==20){
			cout<<"YOU FELL TO THE GROUND!";
			return 0;
		}
		if(birdy==1){
			cout<<"YOU HAVE NO AIR TO BREATHE!";
			return 0;
		}
	}
	return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值