本人一个初一学生,放假课余写了一个弱智小游戏,虽然有点bug但也将就能玩,内容如下
这是一个跑酷小游戏,是一个苦力怕跳障碍,类似谷歌断网恐龙,但是可以调整苦力怕的大小,按s变小,w变大,空格键跳跃(小苦力怕会闪现)
废话不说,上代码
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
void Color(int a);
void start();
int ti(float a);
void Setpos(float x,float y);
void move(int a);
using namespace std;
int cnt=35;
char klp[100][100]={" █████████",
" ██ █ ██",
" █████████",
" ███ ████",
" ██ █ ██",
" █████████",
" █████",
" █████",
" █████",
" █████",
" █████",
" ██████████",
" ██ ",
" ██ ",
" ██ ",
};
char klp1[100][100]={" █████████",
" ██ █ ██",
" █████████",
" ███ ████",
" ██ █ ██",
" █████████",
" █████",
" █████",
" █████",
" █████",
" █████",
" ██████████",
" ██",
" ██",
" ██",
};
char klp2[100][100]={" █████████",
" ██ █ ██",
" █████████",
" ███ ████",
" ██ █ ██",
" █████████",
" █████",
" █████",
" █████",
" █████",
" █████",
" ███████",
" ██ ██",
" ██ ██",
" ██ ██",
};
char x[50][50]={" █",
" ███",
" ██ ▌",
" █████",
" ▌ ███",
" █████",
" ███",
" ███"};
long long sum;
int ti(float a)
{
return ((int)(a*10+5))/10;
}
void Setpos(float x,float y)
{
COORD pos;
pos.X=ti(y*4)/2;
pos.Y=ti(x);
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void start()
{
Color(2);
char a;
system("mode con cols=100 lines=40");
W: while(1)
{
srand((unsigned)time(NULL));
int d=rand()%2;
if(d==1)
move(2);
Color(2);
Setpos(20,10);
for(int i=0;i<15;i++)
{
Setpos(i+20,10);
puts(klp[i]);
}
cout<<"____________________________________________________________________________________________________"<<endl<<endl;
cout<<"分数:"<<sum++;
system("cls");
Setpos(20,0);
for(int i=0;i<15;i++)
{
Setpos(i+20,10);
puts(klp1[i]);
}
cout<<"____________________________________________________________________________________________________"<<endl<<endl;
cout<<"分数:"<<sum++;
system("cls");
if(kbhit())
{
char g=_getch();
if(g==' ')
{
int t=7;
for(int i=20;i>=0;i-=t)
{
Setpos(i,0);
for(int j=0;j<15;j++)
{
Setpos(i+j,10) ;
puts(klp1[i]);
}
Setpos(35,0);
cout<<"____________________________________________________________________________________________________"<<endl<<endl;
cout<<"分数:"<<sum++;
system("cls");
t-=1;
}
for(int i=0;i<=20&&t>0;i+=t)
{
Setpos(i,0);
for(int j=0;j<15;j++)
{
Setpos(i+j,10) ;
puts(klp1[i]);
}
Setpos(35,0);
cout<<"____________________________________________________________________________________________________"<<endl<<endl;
cout<<"分数:"<<sum++;
system("cls");
t+=1;
}
}
if(g=='s')
goto S;
}
}
S: while(1)
{
srand((unsigned)time(NULL));
int d=rand()%2;
if(d==1)
move(1);
Color(2);
Setpos(30,0);
for(int i=0;i<5;i++)
{
Setpos(i+30,10);
puts(klp1[i]);
}
Setpos(35,0);
cout<<"____________________________________________________________________________________________________"<<endl<<endl;
cout<<"分数:"<<sum++;
Sleep(50);
Color(8);
system("cls");
Setpos(30,0);
for(int i=0;i<5;i++)
{
Setpos(i+30,10);
puts(klp1[i]);
}
Setpos(35,0);
cout<<"____________________________________________________________________________________________________"<<endl<<endl;
cout<<"分数:"<<sum++;
Sleep(50);
system("cls");
if(kbhit())
{
char g=_getch();
if(g==' ')
{
int t=8;
for(int i=30;i>=5;i-=t)
{
for(int j=0;i<5;j++)
{
Setpos(i+j,10);
puts(klp1[j]);
}
Setpos(35,0);
cout<<"____________________________________________________________________________________________________"<<endl<<endl;
cout<<"分数:"<<sum++;
system("cls");
t-=1;
}
for(int i=5;i<=30&&t>0;i+=t)
{
for(int j=0;i<5;j++)
{
Setpos(i+j,10);
puts(klp1[j]);
}
Setpos(35,0);
cout<<"____________________________________________________________________________________________________"<<endl<<endl;
cout<<"分数:"<<sum++;
system("cls");
t+=1;
}
}
if(g=='w')
goto W;
}
}
}
void move(int a)
{
for(int k=35;k>=1;k--)
{
Color(2);
if(a==2)
{
Setpos(20,0);
if(k%2==0)
for(int i=0;i<15;i++)
{
Setpos(i+20,10);
puts(klp1[i]);
}
if(k%2==1)
for(int i=0;i<15;i++)
{
Setpos(i+20,10);
puts(klp[i]);
}
if(!kbhit()&&k<=15&&k>=10)
{
system("cls");
char str[]={" GAME OVER"};
for(int i=0;i<strlen(str);i++)
{
cout<<str[i];
Sleep(50);
}
cout<<endl<<endl;
system("pause");
sum=0;
start();
}
if(kbhit())
{
char g=_getch();
if(g==' ')
{
int t=7;
for(int i=20;i>=0;i-=t)
{
Setpos(i,10);
Color(2);
for(int j=0;j<15;j++)
{
Setpos(i+j,10) ;
puts(klp1[i]);
}
if(k!=1)
{
for(int j=0;j<8;j++)
{
Setpos(j+28,k);
Color(12);
puts(x[j]);
}
k--;
}
Setpos(35,0);
Color(2);
cout<<"____________________________________________________________________________________________________"<<endl<<endl;
cout<<"分数:"<<sum++;
system("cls");
t-=1;
}
for(int i=0;i<=20&&t>0;i+=t)
{
Setpos(i,10);
Color(2);
for(int j=0;j<15;j++)
{
Setpos(i+j,10) ;
puts(klp1[i]);
}
if(k!=1)
{
for(int j=0;j<8;j++)
{
Setpos(j+28,k);
Color(12);
puts(x[j]);
}
k--;
}
Setpos(35,0);
Color(2);
cout<<"____________________________________________________________________________________________________"<<endl<<endl;
cout<<"分数:"<<sum++;
system("cls");
t+=1;
}
}
}
}
if(a==1)
{
if(k%2==0)
for(int i=0;i<5;i++)
{
Color(2);
Setpos(i+30,10);
puts(klp1[i]);
}
if(k%2==1)
for(int i=0;i<5;i++)
{
Color(8);
Setpos(i+30,10);
puts(klp[i]);
}
for(int i=0;i<5;i++)
{
Setpos(i+30,10);
puts(klp2[i]);
}
if(!kbhit()&&k<=15&&k>=10)
{
system("cls");
char str[]={" GAME OVER"};
for(int i=0;i<strlen(str);i++)
{
cout<<str[i];
Sleep(50);
}
sum=0;
cout<<endl<<endl;
system("pause");
start();
}
if(kbhit())
{
char g=_getch();
if(g==' ')
{
int t=7;
for(int i=20;i>=5;i-=t)
{
Setpos(i,0);
Color(2);
for(int j=0;i<5;j++)
{
Setpos(i+j,10);
puts(klp1[j]);
}
if(k!=1)
{
for(int j=0;j<8;j++)
{
Setpos(j+28,k);
Color(12);
puts(x[j]);
}
k--;
}
Setpos(35,0);
Color(2);
cout<<"____________________________________________________________________________________________________"<<endl<<endl;
cout<<"分数:"<<sum++;
system("cls");
t-=1;
}
for(int i=5;i<=20&&t>0;i+=t)
{
Setpos(i,0);
Color(2);
for(int j=0;i<5;j++)
{
Setpos(i+j,10);
puts(klp1[j]);
}
if(k!=1)
{
for(int j=0;j<8;j++)
{
Setpos(j+28,k);
Color(12);
puts(x[j]);
}
k--;
}
Setpos(35,0);
Color(2);
cout<<"____________________________________________________________________________________________________"<<endl<<endl;
cout<<"分数:"<<sum++;
system("cls");
t+=1;
}
}
}
}
for(int j=0;j<8;j++)
{
Setpos(j+28,k);
Color(12);
puts(x[j]);
}
Color(2);
Setpos(35,0);
Color(2);
cout<<"____________________________________________________________________________________________________"<<endl<<endl;
cout<<"分数:"<<sum++;
system("cls");
}
}
void Color(int a)
{
if(a==0)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
if(a==1)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);
if(a==2)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
if(a==3)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE);
if(a==4)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
if(a==5)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
if(a==6)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE);
if(a==7)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
if(a==8)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED);
if(a==9)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY|BACKGROUND_GREEN|BACKGROUND_BLUE);
if(a==10)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_BLUE);
if(a==11)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_BLUE);
if(a==12)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_GREEN);
if(a==13)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY);
if(a==14)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN|FOREGROUND_BLUE);
}
int main()
{
char str1[100][100]={" ",
" ● ",
" ━/ ",
" ╯> "};
char str2[100][100]={" ",
" ● ",
" ━/ ",
" ┛╲ "};
char str3[100][100]={" ",
" ● ",
" ━/ ",
" ┦ "};
char k[100][100]={" █ ██",
" ███████████",
" █ ██",
" ██",
" █████████",
" ██",
" █████████",
" █ ██",
" █████████"};
int y=0;
while(!kbhit())
{
Color(2);
if(y==0)
{
for(int i=0;i<9;i++)
{
puts(k[i]);
Sleep(50);
}
cout<<" 力怕"<<endl;
Color(8);
cout<<" ┌──────────┐"<<endl ;
cout<<" │ │"<<endl;
cout<<" ├──────────│"<<endl;
cout<<" │ TNT │"<<endl;
cout<<" ├──────────│"<<endl;
cout<<" │ │"<<endl;
cout<<" └──────────┘"<<endl;
y=1;
system("cls");
}
else
{
Color(2);
for(int i=0;i<9;i++)
{
puts(k[i]);
}
cout<<" 力怕"<<endl;
Color(8);
cout<<" ┌──────────┐"<<endl ;
cout<<" │ │"<<endl;
cout<<" ├──────────│"<<endl;
cout<<" │ TNT │"<<endl;
cout<<" ├──────────│"<<endl;
cout<<" │ │"<<endl;
cout<<" └──────────┘"<<endl;
Color(6);
for(int i=0;i<4;i++) puts(str1[i]);
cout<<"跑酷"<<endl;
Sleep(60);
system("cls");
Color(2);
for(int i=0;i<9;i++)
{
puts(k[i]);
}
cout<<" 力怕"<<endl;
Color(8);
cout<<" ┌──────────┐"<<endl ;
cout<<" │ │"<<endl;
cout<<" ├──────────│"<<endl;
cout<<" │ TNT │"<<endl;
cout<<" ├──────────│"<<endl;
cout<<" │ │"<<endl;
cout<<" └──────────┘"<<endl;
Color(6);
for(int i=0;i<4;i++) puts(str2[i]);
cout<<"跑酷"<<endl;
Sleep(60);
system("cls");
Color(2);
for(int i=0;i<9;i++)
{
puts(k[i]);
}
cout<<" 力怕"<<endl;
Color(8);
cout<<" ┌──────────┐"<<endl ;
cout<<" │ │"<<endl;
cout<<" ├──────────│"<<endl;
cout<<" │ TNT │"<<endl;
cout<<" ├──────────│"<<endl;
cout<<" │ │"<<endl;
cout<<" └──────────┘"<<endl;
Color(6);
for(int i=0;i<4;i++) puts(str3[i]);
cout<<"跑酷"<<endl;
Sleep(60);
system("cls");
}
}
cout<<"作者:你猜猜我叫啥"<<endl<<endl;
Color(12);
system("pause");
Color(4);
cout<<"规则"<<endl;
cout<<"按空格跳跃,按s缩小,缩小有闪现技能,按w普通形态,可跳跃"<<endl;
Color(12);
system("pause");
start();
return 0;
}