本文主要是介绍游戏:Flappy Bird[飞行的鸟](C++)1.2,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
前言:
最近快学习压力有点大,所以很少有时间来写游戏,游戏可能有BUG,还请多多包含!!
这次更新主要是针对一下几点:
1.加了O2优化,让游戏更流畅;
2.更改了计分规则,修复了分数累加的BUG;
3.设置难度选项(手残党狂喜)。
奉上代码:
#include<iostream>
#include<stdio.h>
#include<ctime>
#include<windows.h>
#include<conio.h>
#include<cstdlib>
#include<fstream>
#include<iomanip>
#pragma GCC optimize(2)
using namespace std;
int l=-1,r=30;
int x=3,y=5;
int fenshu=0;
int nandu;
int map[89][96]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,1,0,1,0,1,1,1,1,0,0,1,0,1,0,1,1,1,1,0,0,1,0,1,0,1,1,1,1,0,0,1,0,1,8,1,1,1,1,0,0,1,0,1,0,1,1,1,1,0,0,1,0,1,0,1,1,1,1,0,0,1,0,1,0,1,1,1,1,0,0,1,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,8,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,1,1,1,1,1,1,1,1,1,1,8,
};
void home();
void win() {cout<<"你赢了!!!\n";system("pause");system("cls");cout<<"你的分数:\n"<<fenshu;system("pause");system("cls");fenshu=0;home();
}
void Nandu() {int n;for(int i=1; i<=25; i++)cout<<" ";cout<<"选择难度\n";for(int i=1; i<=25; i++)cout<<" ";cout<<"1.简单游戏\n";for(int i=1; i<=25; i++)cout<<" ";cout<<"2.困难游戏\n";for(int i=1; i<=25; i++)cout<<" ";cout<<"3.地狱游戏(你确定?)"<<"\n";for(int i=1; i<=25; i++)cout<<" ";cout<<"请输入:";cin>>n;nandu=50*(4-n);system("cls");
}
void jiaocheng() {cout<<"玩法:长按空格键控制小鸟向上飞(别让小鸟撞到树枝)\n";system("pause");system("cls");home();
}
void over() {cout<<"你死了\n";system("pause");system("cls");cout<<"你的分数:\n"<<fenshu;system("pause");system("cls");fenshu=0;home();
}
void draw(int a) {if(a==0) {printf(" ");}if(a==5) {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY);printf("鸟");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY);}if(a==1) {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN|FOREGROUND_INTENSITY);printf("树");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY);}if(a==8) {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_INTENSITY);printf("赢");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY);}if(a==9) {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);printf("终");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY);}if(a==7) {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);printf("点");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY);}if(a==6) {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);printf("线");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY);}
}
void xianshi(int l,int r) {while(r<=96) {map[x][y]=5;if(r<=56)l++,r++;for(int i=0; i<=8; i++) {for(int j=l; j<=r; j++) {draw(map[i][j]);}if(i!=8)printf("\n");}Sleep(nandu);map[x][y]=0;y++;x++;if (GetKeyState(' ')<0) {x-=1;}if (GetKeyState(' ')<0) {x-=1;}system("cls");if(map[x][y]==1) {over();return ;}fenshu++;if(map[x][y]==8||map[x][y]==9||map[x][y]==7||map[x][y]==6) {win();return ;}}
}
void home() {int n;int l=-1,r=30;for(int i=1; i<=25; i++)cout<<" ";cout<<"1.开始游戏\n";for(int i=1; i<=25; i++)cout<<" ";cout<<"2.退出游戏\n";for(int i=1; i<=25; i++)cout<<" ";cout<<"3.游戏教程\n";for(int i=1; i<=25; i++)cout<<" ";cout<<"请输入:";cin>>n;system("cls");if(n==1) {Nandu();x=3,y=5;xianshi(-1,30);}if(n==2)return ;if(n==3)jiaocheng();
}
int main() {system("mode con cols=65 lines=10");home();
}
Oh,最后,千万别忘了——
这篇关于游戏:Flappy Bird[飞行的鸟](C++)1.2的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!