我把弹球小游戏的界面搞好看了
上代码:
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
string q="o",db="-----",kk[31]={
"",
" ____________________________________________________________________________________________________ ",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" _____________________________________________________________________________________________________"
};
long long x,y,dx,dy,hb=2,fs=0;
bool f=1,ax=0;
void csh();//初始化
void in();//输入
void out();//输出
void qgs();//球坐标的更新
void pd();//判断结束
void color(int c)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c);
}
void gb()
{
CONSOLE_CURSOR_INFO cursor;
cursor.bVisible=FALSE;
cursor.dwSize=sizeof(cursor);
HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(handle, &cursor);
}
int main()
{
gb();
color(11);
csh();
while(f)
{
system("cls");
in();
out();
qgs();
pd();
if(!f)break;
for(long long i=1;i<=3;i++)
{
in();
if(ax)
out();
Sleep(1);
}
}
color(185);
system("cls");
printf("你得了%d分\n按空格退出",fs);
char t=getch();
while(t!=' ')t=getch();
return 0;
}
void csh()
{
system("mode con cols=101 lines=31");
srand(time(0));
x=3;
y=rand()%100+1;
dx=1;
dy=1;
}
void in()
{
if(GetKeyState('A')<0)
{
if(hb>2)
{
hb-=2;
ax=1;
}
}
else
if(GetKeyState('D')<0)
{
if(hb<99-4)
{
hb+=2;
ax=1;
}
}
else
ax=0;
}
void out()
{
system("cls");
for(long long i=1;i<=30;i++)
{
for(long long j=1;j<=101;j++)
{
if(i==x&&j==y)
{
color(10);
cout<<q;
}
else
if(i==29&&j==hb)
{
color(14);
j+=4;
cout<<db;
}
else
{
color(11);
cout<<kk[i][j];
}
}
cout<<"\n";
}
}
void qgs()
{
if(x==2||(x==28&&(hb==y||y==hb+1||y==hb+2||y==hb+3||y==hb+4)))dx*=-1;
if(y==2||y==100)dy*=-1;
x+=dx;
y+=dy;
if(x==28&&(hb==y||y==hb+1||y==hb+2||y==hb+3||y==hb+4))fs++;
}
void pd()
{
if(x==30)
f=0;
}
大家如果觉得我写得好
请点赞、收藏、关注我哦!
声明: