概述
#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;
}
最后
以上就是羞涩戒指为你收集整理的DEVC++跳鸟游戏的全部内容,希望文章能够帮你解决DEVC++跳鸟游戏所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复