C++简易谷歌小恐龙游戏1.0 开发者:蛋糕东东TAT(这是博主网名) 这只是简陋版,没有优化,很多功能没有实现,玩法及其单调,手感也很拉。所以希望各位C++大佬骂轻点,同时也希望得到指点哦~玩的开心,Thanks♪(・ω・)ノ
代码如下,复制进C++玩即可
#include<iostream>
#include<conio.h>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<iomanip>
#include<cstring>
#include<windows.h>
#define la 880
#define la1 1760
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
int flag=0;
int gotoxy(int x,int y){//在指定行列输入字符
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
HANDLE hConsoleOut;
hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsoleOut,&csbiInfo);
csbiInfo.dwCursorPosition.X = x;
csbiInfo.dwCursorPosition.Y = y;
SetConsoleCursorPosition(hConsoleOut,csbiInfo.dwCursorPosition);
}
void check(char c){//检测某个按键是否按下,按下就改变一下变量
if(!KEY_DOWN(c))flag=0;
else flag=1;
}
int main(){
int score=0,time=100,time1=200,trapflag=0,trapi=0,jump=7,jumpflag=0,jumphigh=0,jumphighflag=1;
Sleep(1000);
gotoxy(0,0);
cout<<"3";
Beep(la,400);
Sleep(600);
gotoxy(0,0);
cout<<"2";
Beep(la,400);
Sleep(600);
gotoxy(0,0);
cout<<"1";
Beep(la,400);
Sleep(600);
gotoxy(0,0);
cout<<"开始游戏!";
Beep(la1,800);
gotoxy(0,0);
cout<<'\t'<<'\t';
gotoxy(0,10);
for(int l1=1;l1<=3;l1++){
for(int l2=1;l2<=100;l2++){
cout<<"*";
}
cout<<endl;
}
while(1){
gotoxy(0,0);
cout<<"分数:"<<score;
gotoxy(0,20);
cout<<"按\"X\"键跳跃";
score++;
if(score%time1==0){
if(time!=20){
time=time-20;
time1=time1*2;
}
Beep(la,200);
}
if(trapflag==1){
trapi=100;
}
if(trapi>=0){
trapflag=0;
for(int l1=7;l1<=9;l1++){
gotoxy(trapi+1,l1);
cout<<" ";
gotoxy(trapi,l1);
cout<<"$";
}
trapi--;
}else{
trapflag=1;
}
check('X');
if(flag==1&&jumpflag==0){
jumpflag=1;
}
if(jumpflag==1&&jumphigh==0){
jump--;
}
if(jumpflag==1&&jumphigh==1){
if(jumphighflag>3){
jump++;
}
jumphighflag++;
}
if(jump==7){
jumpflag=0;
jumphigh=0;
jumphighflag=1;
}
for(int l1=jump;l1<=jump+2;l1++){
gotoxy(19,l1);
cout<<"&";
if(jump<7){
gotoxy(19,jump+3);
cout<<" ";
}
gotoxy(19,jump-1);
cout<<" ";
}
if(jump==2){
jumphigh=1;
}
if(trapi==19&&jump+2>=5){
gotoxy(0,13);
cout<<"游戏结束,您的最终得分为:"<<score-1<<endl;
Sleep(5000);
return 0;
}
Sleep(time);
}
return 0;
}