这是一款用C++写的好玩的小游戏,只有一百五十多行。话不多说,上游戏源代码。
#include<bits/stdc++.h>
#include<unistd.h>
#include<conio.h>
using namespace std;
void pg(){
cout<<"有一天,你被抓到了王宫里......"<<endl;
sleep(1);
cout<<"你想逃出去......"<<endl;
sleep(1);
cout<<"“O”代表你......"<<endl;
sleep(1);
cout<<"“@”代表出口......"<<endl;
sleep(1);
cout<<"#是墙...... "<<endl;
sleep(1);
cout<<"不要撞墙......"<<endl;
sleep(1);
cout<<"请输入 w(上) s(下) a(左) d(右)"<<endl;
sleep(1);
cout<<"也不要输“w,s,a,d”以外的字符......"<<endl;
sleep(1);
cout<<"会被惩罚。"<<endl;
sleep(1);
}
int main(){
pg();
cout<<"第一关:easy至极:"<<endl;
sleep(1);
char a[6][6]={
{'#','#','#','#','#','#'},
{'#','O',' ','#',' ','@'},
{'#',' ','#','#',' ','#'},
{'#',' ',' ','#',' ','#'},
{'#','#',' ',' ',' ','#'},
{'#','#','#','#','#','#'},
};
int x=1,y=1;
while(1){
system("cls");
for(int q=0;q<=5;q++){
for(int w=0;w<=5;w++) cout<<a[q][w];
cout<<endl;
}
char ch;
ch=getch();
if(ch=='s'&&a[x+1][y]!='#'){
a[x][y]=' ';
x++;
a[x][y]='O';
}
if(ch=='w'&&a[x-1][y]!='#'){
a[x][y]=' ';
x--;
a[x][y]='O';
}
if(ch=='a'&&a[x][y-1]!='#'){
a[x][y]=' ';
y--;
a[x][y]='O';
}
if(ch=='d'&&a[x][y+1]!='#'){
a[x][y]=' ';
y++;
a[x][y]='O';
}
else if(ch!='a'&&ch!='s'&&ch!='d'&&ch!='w'){
cout << "你输错了......" << endl;
sleep (1);
cout << "被电击......" << endl;
sleep (1);
cout << "你很懦弱......" << endl;
sleep (1);
cout << "被电击死了。" << endl;
return 0;
}
else if("O"=="#"){
cout<<"你撞墙了......"<<endl;
sleep(1);
cout<<"死了......。"<<endl;
return 0;
}
if(a[1][5]=='O') break;
system("cls");
for(int i=0;i<=5;i++){
for(int j=0;j<=5;j++) cout<<a[i][j];
cout<<endl;
}
}
sleep(1);
cout<<"你成功逃脱了国王的第一个密室!"<<endl;
sleep(1);
cout<<"第二关:小试牛刀:"<<endl;
sleep(1);
char b[6][6]={
{'#','#',' ',' ',' ','#'},
{' ','O',' ','#','#','@'},
{' ',' ','#','#',' ',' '},
{' ',' ',' ','#',' ','#'},
{'#','#',' ',' ',' ',' '},
{' ',' ',' ',' ',' ',' '},
};
int e=1,r=1;
system("cls");
while(1){
for(int q=0;q<=5;q++){
for(int w=0;w<=5;w++) cout<<b[q][w];
cout<<endl;
}
char c;
c=getch();
if(c=='s'&&b[e+1][r]!='#'){
b[e][r]=' ';
e++;
b[e][r]='O';
}
if(c=='w'&&b[e-1][r]!='#'){
b[e][r]=' ';
e--;
b[e][r]='O';
}
if(c=='a'&&b[e][r-1]!='#'){
b[e][r]=' ';
r--;
b[e][r]='O';
}
if(c=='d'&&b[e][r+1]!='#'){
b[e][r]=' ';
r++;
b[e][r]='O';
}
else if(c!='a'&&c!='s'&&c!='d'&&c!='w'){
cout<<"你输错了......"<<endl;
sleep(1);
cout<<"被电击......"<<endl;
sleep(1);
cout<<"你很懦弱......"<<endl;
sleep(1);
cout<<"被电击死了。"<<endl;
return 0;
}
else if('#'=='O'){
cout<<"你撞墙了......"<<endl;
sleep(1);
cout<<"死了......。"<<endl;
return 0;
}
if(b[1][5]=='O') break;
system("cls");
}
sleep(1);
cout<<"你成功逃脱了国王的第二个密室并成功逃脱王宫!"<<endl;
return 0;
}
如果喜欢这款小游戏,别忘了点赞关注哟!!!?
|