最近花了一个下午做了这个小游戏(自我感觉还不错)
ADW控制*
上左右控制+
$是终点
话不多说,上代码:
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
long long wj1x=14,wj1y=1,wj2x=14,wj2y=1,cs=0;
bool f=1,t1=1,t2=1,sy;
string dt[21]={
"",
" ================================================================ = ==",
" ",
" == === == ",
" === === = ",
" = == = ",
" = ",
" == = == = ",
" ====== = ",
" == ========= = ",
" ==== = ",
" == = ",
" == == = = = ",
" == = = = = ==== ",
" $",
" ======== = = = = = = = = = = = = = = == = = = = = = = =====",
" ",
" "
};
void out();
void in();
void lx();
void js();
int main()
{
system("mode con cols=75 lines=17");
while(f)
{
system("cls");
out();
in();
js();
if(cs==1)
lx();
Sleep(10);
if(cs==1)cs=-1;
cs++;
}
system("cls");
if(!sy)cout<<"*赢了!";
else cout<<"+赢了!";
cout<<"\n按Enter结束";
char t=getch();
while(t!=13)t=getch();
return 0;
}
void out()
{
for(long long i=1;i<=16;i++)
{
for(long long j=1;j<=75;j++)
{
if(i==wj1x&&j==wj1y)cout<<"*";
else
if(i==wj2x&&j==wj2y)cout<<"+";
else
cout<<dt[i][j];
}
cout<<endl;
}
return ;
}
void in()
{
if(GetKeyState('A')<0&&(dt[wj1x][wj1y-1]==' '||dt[wj1x][wj1y-1]=='$')&&wj1y-1>0)
{
wj1y--;
}
if(GetKeyState('D')<0&&(dt[wj1x][wj1y+1]==' '||dt[wj1x][wj1y+1]=='$')&&wj1y-1<=100)
{
wj1y++;
}
if(GetKeyState('W')<0&&(dt[wj1x-1][wj1y]==' '||dt[wj1x-1][wj1y]=='$')&&t1)
{
wj1x--;
for(long long i=1;i<=2;i++)
if(dt[wj1x-1][wj1y]==' ')wj1x--;
t1=0;
}
if(GetKeyState(37)<0&&(dt[wj2x][wj2y-1]==' '||dt[wj2x][wj2y-1]=='$')&&wj2y-1>0)
{
wj2y--;
}
if(GetKeyState(39)<0&&(dt[wj2x][wj2y+1]==' '||dt[wj2x][wj2y+1]=='$')&&wj1y-1<=100)
{
wj2y++;
}
if(GetKeyState(38)<0&&(dt[wj2x-1][wj2y]==' '||dt[wj2x-1][wj2y]=='$')&&t2)
{
wj2x--;
for(long long i=1;i<=2;i++)
if(dt[wj2x-1][wj2y]==' ')wj2x--;
t2=0;
}
return ;
}
void lx()
{
if(dt[wj1x+1][wj1y]==' '||dt[wj1x+1][wj1y]=='$')wj1x++;
else t1=1;
if(dt[wj2x+1][wj2y]==' '||dt[wj2x+1][wj2y]=='$')wj2x++;
else t2=1;
return ;
}
void js()
{
if(dt[wj1x][wj1y]=='$')
{
f=0;
sy=0;
}
if(dt[wj2x][wj2y]=='$')
{
f=0;
sy=1;
}
if(wj1x==16)
{
wj1x=14,wj1y=1;
}
if(wj2x==16)
{
wj2x=14,wj2y=1;
}
return ;
}
这个游戏运行时会闪烁,请大佬见谅
如果大佬觉得还不错,请点赞关注我,你们的鼓励是我进步和更新的动力
声明:
以上是我原创的代码,请勿抄袭,转载请标明作者!!!
|