咕了好久,我先在来发我做的第二个游戏:狙击手
Bug太多请谅解
#include<bits/stdc++.h>
#include<conio.h>
#include<windows.h>
using namespace std;
const int Maxkuan=10,Maxchang=10;
string name;
int now_Guan=1;
char now[Maxkuan+10][Maxchang+10];
char check_move()
{
char chInput;
if(kbhit())
{
chInput=getch();
if(chInput==72)
return 'u'; //up
if(chInput==80)
return 'd'; //down
if(chInput==75)
return 'l'; //left
if(chInput==77)
return 'r'; //right
}
}
void print_help()
{
printf("按方向键控制瞄准镜,按S开枪,*是敌人,+是子弹飞去的地方,#是空地");
}
bool check()
{
for(int i=1;i<=10;i++)
{
for(int j=1;j<=10;j++)
{
if(now[i][j]=='*') return false;
}
}
return true;
}
void put_Gun(int fx,int fy)
{
int Gx,Gy;
for(;check()==false;)
{
Gx=fx,Gy=fy;
system("cls");
char Ch=check_move();
switch(Ch)
{
case 'u':{
if(fx>1)
fx--;
break;
}
case 'd':{
if(fx<10)
fx++;
break;
}
case 'l':{
if(fy>1)
fy--;
break;
}
case 'r':{
if(fy<10)
fy++;
break;
}
}
now[Gx][Gy]='#';
printf("\r");
for(int i=1;i<=10;i++)
{
for(int j=1;j<=10;j++)
{
cout<<now[i][j];
}
cout<<endl;
}
system("cls");
bool flag=false;
if(now[fx][fy]=='*')
{
printf("瞄准到了敌人!\n");
flag=true;
}
now[fx][fy]='+';
for(int i=1;i<=10;i++)
{
for(int j=1;j<=10;j++)
{
cout<<now[i][j];
}
cout<<endl;
}
char ch=getch();
if(ch=='S')
{
if(flag)
{
printf("成功干掉了一个敌人!");
Sleep(1000);
}else{
printf("放空枪是什么鬼?");
Sleep(1000);
}
}
}
}
int main()
{
memset(now,'#',sizeof(now));
puts("欢迎来到游戏:神枪狙击手,本游戏由justin666888独家制作");
Sleep(2000);
system("cls");
puts("请输入您的名字:");
cin>>name;
puts("欢迎您,狙击手!");
while(1)
{
system("cls");
if(now_Guan==10)
{
puts("你歼灭了所有敌人!");
puts("再见");
return 0;
}
puts("------------");
puts("关卡:输入B|>");
puts("商店:输入S|>");
puts("------------");
char ch=getch();
if(ch=='B')
{
memset(now,'#',sizeof(now));
printf("第%d关:",now_Guan);
Sleep(1000);
system("cls");
print_help();
Sleep(1000);
system("cls");
for(int i=1;i<=now_Guan;i++)
{
srand(time(0));
int x=rand()%10+1;
srand(time(0));
int y=rand()%10+1;
if(now[x][y]=='*') i--;
now[x][y]='*';
}
int nowx=5,nowy=5;
put_Gun(nowx,nowy);
puts("你赢了!");
now_Guan++;
}else if(ch=='S'){
puts("没啥可买的");
Sleep(1000);
}else{
puts("输入无效!");
Sleep(1000);
}
}
return 0;
}
祝大家玩的愉快