今天更新了小游戏。
加入第二关,完善各种交互效果
加入了加载动画和首页面
#include<bits/stdc++.h>
#include<windows.h>
char mp[6][8]={{'.','#','#','#','.','.','#','.'},{'.','.','.','#','#','.','#','.'},{'#','#','.','#','#','.','.','#'},{'#','#','.','.','.','.','.','#'},{'#','#','#','#','#','#','.','#'},{'.','.','.','#','.','#','.','!'}};
char mp1[9][10]={
{'@','#','#','#','#','#','#','#','#','#'},
{'.','.','#','#','.','#','#','#','#','#'},
{'#','.','#','#','.','#','#','#','#','#'},
{'#','.','#','#','.','#','.','#','.','#'},
{'#','.','#','#','#','#','.','.','.','#'},
{'#','.','#','.','.','.','.','.','.','#'},
{'#','.','#','.','#','#','#','.','.','#'},
{'#','.','.','.','#','.','#','.','.','#'},
{'#','#','#','#','#','.','#','#','.','!'},
};
int vis[4][2]={{0,-1},{0,1},{-1,0},{1,0}};
int res;
using namespace std;
void chek(){
if(res==0)cout<<"NOWAY!"<<endl;
else cout<<"不能这样走!"<<endl;
}
int main(){
cout<<" 加载中 "<<endl;
cout<<" *" ;
Sleep(900);
cout<<"*" ;
Sleep(900);
cout<<"*" ;
Sleep(900);
cout<<"*" ;
Sleep(900);
cout<<"*" ;
Sleep(900);
cout<<"*" ;
Sleep(900);
cout<<"*" ;
Sleep(900);
system("cls");
cout<<" 欢迎来到迷宫冒险小游戏!"<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<" 按下E开始 " <<endl;
char e;
cin>>e;
system("cls");
cout<<"中国人?american? 用0或者1来选择国籍,1代表中国,0 means american。"<<endl;
cin>>res;
system("cls");
if(res==1){
cout<<"掉下去啦…………………………………………"<<endl;
Sleep(2000);
cout<<"你掉进了一个迷宫"<<endl;
cout<<"你需要逃出去"<<endl;
Sleep(2000);
system("cls");
cout<<"你在@的位置,尝试走到感叹号的位置逃出去!!"<<endl;
cout<<"通过w,s,a,d控制方向! w为上,s为下,a为左,d为右"<<endl;
Sleep(4000);
system("cls");
}
else {
cout<<"falling…………………………………………"<<endl;
Sleep(2000);
cout<<"you are in a maze"<<endl;
cout<<"you should leave."<<endl;
Sleep(2000);
system("cls");
cout<<"you are on the place of the @.try to go to the place of the ! and leave!!"<<endl;
cout<<"use w,s,a,d to contrl the way! w is up,s if down,a is left,d is right";
Sleep(2000);
system("cls");
}
mp[0][0]='@';
for(int i=0;i<6;i++){
for(int j=0;j<8;j++)cout<<mp[i][j]<<" ";
cout<<endl;
}
int x,y;
x=y=0;
while(y<6&&x<7){
char ch;
cin>>ch;
if(ch=='w'){
if(mp[y+vis[0][1]][x+vis[0][0]]=='#'){
chek();
}
else {
Beep(584,682);
system("cls");
mp[y][x]='.';
x+=vis[0][0];
y+=vis[0][1];
mp[y][x]='@';
for(int i=0;i<6;i++){
for(int j=0;j<8;j++)cout<<mp[i][j]<<" ";
cout<<endl;
}
}
}
else if(ch=='s'){
if(mp[y+vis[1][1]][x+vis[1][0]]=='#'){
chek();
}
else {
Beep(584,682);
system("cls");
mp[y][x]='.';
x+=vis[1][0];
y+=vis[1][1];
mp[y][x]='@';
for(int i=0;i<6;i++){
for(int j=0;j<8;j++)cout<<mp[i][j]<<" ";
cout<<endl;
}
}
}
else if(ch=='a'){
if(mp[y+vis[2][1]][x+vis[2][0]]=='#'){
chek();
}
else {
Beep(584,682);
system("cls");
mp[y][x]='.';
x+=vis[2][0];
y+=vis[2][1];
mp[y][x]='@';
for(int i=0;i<6;i++){
for(int j=0;j<8;j++)cout<<mp[i][j]<<" ";
cout<<endl;
}
}
}
else if(ch=='d'){
if(mp[y+vis[3][1]][x+vis[3][0]]=='#'){
chek();
}
else {
Beep(584,682);
system("cls");
mp[y][x]='.';
x+=vis[3][0];
y+=vis[3][1];
mp[y][x]='@';
for(int i=0;i<6;i++){
for(int j=0;j<8;j++)cout<<mp[i][j]<<" ";
cout<<endl;
}
}
}
}
Beep(682,584);
Beep(584,682);
if(res==1){
cout<<"太棒了!你成功逃了出去!"<<endl;
cout<<"你想要进入下一关吗?(0,1)选择,0代表想要"<<endl;
}
else {
cout<<"good job!! you leaved"<<endl;
cout<<"do you want to play the next level?(0,1)to choose 0 means want"<<endl;
}
int s;
cin>>s;
y=x=0;
system("cls");
if(s==0){
for(int i=0;i<9;i++){
for(int j=0;j<10;j++)cout<<mp1[i][j]<<" ";
cout<<endl;
}
while(y<9&&x<9){
char ch;
cin>>ch;
if(ch=='w'){
if(mp1[y+vis[0][1]][x+vis[0][0]]=='#'){
chek();
}
else {
Beep(584,682);
system("cls");
mp1[y][x]='.';
x+=vis[0][0];
y+=vis[0][1];
mp1[y][x]='@';
for(int i=0;i<9;i++){
for(int j=0;j<10;j++)cout<<mp1[i][j]<<" ";
cout<<endl;
}
}
}
else if(ch=='s'){
if(mp1[y+vis[1][1]][x+vis[1][0]]=='#'){
chek();
}
else {
Beep(584,682);
system("cls");
mp1[y][x]='.';
x+=vis[1][0];
y+=vis[1][1];
mp1[y][x]='@';
for(int i=0;i<9;i++){
for(int j=0;j<10;j++)cout<<mp1[i][j]<<" ";
cout<<endl;
}
}
}
else if(ch=='a'){
if(mp1[y+vis[2][1]][x+vis[2][0]]=='#'){
chek();
}
else {
Beep(584,682);
system("cls");
mp1[y][x]='.';
x+=vis[2][0];
y+=vis[2][1];
mp1[y][x]='@';
for(int i=0;i<0;i++){
for(int j=0;j<10;j++)cout<<mp1[i][j]<<" ";
cout<<endl;
}
}
}
else if(ch=='d'){
if(mp1[y+vis[3][1]][x+vis[3][0]]=='#'){
chek();
}
else {
Beep(584,682);
system("cls");
mp1[y][x]='.';
x+=vis[3][0];
y+=vis[3][1];
mp1[y][x]='@';
for(int i=0;i<9;i++){
for(int j=0;j<10;j++)cout<<mp1[i][j]<<" ";
cout<<endl;
}
}
}
}
Beep(682,584);
Beep(584,682);
if(res==1){
cout<<"太棒了!你又成功逃了出去!"<<endl;
cout<<"你想要关机吗?(0,1)选择,0代表想要"<<endl;
}
else {
cout<<"good job!! you leaved again。"<<endl;
cout<<"do you want to shutdown?(0,1)to choose 0 means want"<<endl;
}
int s1;
cin>>s1;
if(s1==0)system("shutdown -p");
else {
if(res==1)cout<<"再见,欢迎下次再来!";
else cout<<"goodbye! welcome play again!" ;
}
}
else return 0;
}