发布网友 发布时间:2022-05-14 03:10
共2个回答
热心网友 时间:2022-05-22 01:07
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
int main()
{
int i123;
cout<<" ."<<endl;
cout<<" . ."<<endl;
cout<<" . . ."<<endl;
cout<<" . ."<<endl;
cout<<" ."<<endl;
cout<<" T M";
for(i123=500;i123<=1000;i123+=100){
Beep(i123,1000);
}
system("cls");
char a[50][50]={"##############################",
"#o # ## # ### ####",
"# ###### # # # # # ### ####",
"# # ## # # #### # ### ##",
"# # ## ### # # ## ####",
"##### # # ##### ## ####",
"# # ##### # # # # # #",
"# # # ## # #### ## # # ####",
"# # # ## ## # # ####",
"# # # ####### ## ###### # ##",
"# # ## # ## ###### ### #",
"# ###### # ##### # # #",
"# # # ##### ### # ",
"# ######## ##### # ### ### # #",
"# # ## ##### ### ###",
"##### # ## # ######## # #",
"# # ## ## ### # #",
"# # ### ###### ####### #",
"# # ### ## # #",
"##############################"
};
int i,i1,x=1,y=1,n=12,m=29;
char ch;
for(i=0;i<=19;i++){
puts(a[i]);
}
while(x!=n||y!=m){
ch=getch();
if(ch==115||ch==25){
if(a[x+1][y]!=35){
a[x][y]=32;
x++;
a[x][y]=111;
}
}
if(ch==119||ch==24){
if(a[x-1][y]!=35){
a[x][y]=32;
x--;
a[x][y]=111;
}
}
if(ch==97||ch==27){
if(a[x][y-1]!=35){
a[x][y]=32;
y--;
a[x][y]=111;
}
}
if(ch==100||ch==26){
if(a[x][y+1]!=35){
a[x][y]=32;
y++;
a[x][y]=111;
}
}
system("cls");
for(i=0;i<=19;i++){
puts(a[i]);
}
}
for(i1=500;i1<=1000;i1=i1+100){
Beep(i1,1000);
}
cout<<endl<<"你赢了!!!祝贺你!!!";
system("pause");
}
热心网友 时间:2022-05-22 02:25
#include<iostream>
#include<iomanip>//setw的头文件
using namespace std;
char a;//用来输入WASD控制方向
int map[13][13]{//用二维数组做的地图
{5,5,5,5,5,5,5,5,5,5,5,5,5},
{5,2,0,0,0,0,0,0,0,0,0,0,5},
{5,5,5,0,5,5,5,0,5,5,5,0,5},
{5,0,0,0,0,0,5,0,5,0,0,0,5},
{5,0,5,0,5,0,5,5,5,5,5,5,5},
{5,0,5,0,5,0,5,0,5,0,0,0,5},
{5,5,5,0,5,0,5,0,5,5,5,0,5},
{5,0,0,0,5,0,0,0,0,0,0,0,5},
{5,5,5,5,5,0,5,0,5,5,5,0,5},
{5,0,0,0,0,0,5,0,0,0,5,0,5},
{5,5,5,5,5,0,5,5,5,0,5,5,5},
{5,0,0,0,0,0,0,0,5,0,0,0,1},
{5,5,5,5,5,5,5,5,5,5,5,5,5}
};
int x=1,y=1;//玩家所在位置,用x和y控制坐标
void Map(){//打印地图函数
for(int i=0;i<=12;i++){
for(int j=0;j<=12;j++){
cout<<setw(2)<<map[i][j];
}
cout<<endl;
}
}
int Go(int s){//控制方向函数
if(a=='S'){//向下
if(map[x][y]>map[x+1][y]){//判断能否移动
x++;//若能移动,坐标x++,y不变
map[x][y]=map[x-1][y];//覆盖想要移动到的位置 ,也可以直接map[x][y]=1;
map[x-1][y]=0;//将之前的位置变成0
if(map[11][12]==2){//判断是否通关
cout<<"恭喜您通关了"<<endl;
system("pause");
system("cls");
return 0;
}
else system("cls");
}
else{//否则输出无法移动,想再输入可以利用while循环
cout<<"无法移动"<<endl;
system("pause");
system("cls");
}
}
else if(a=='W'){
if(map[x][y]>map[x-1][y]){
x--;
map[x][y]=map[x+1][y];
map[x+1][y]=0;
if(map[11][12]==2){
cout<<"恭喜您通关了"<<endl;
system("pause");
system("cls");
return 0;
}
else system("cls");
}
else{
cout<<"无法移动"<<endl;
system("pause");
system("cls");
}
}
else if(a=='D'){
if(map[x][y]>map[x][y+1]){
y++;
map[x][y]=map[x][y-1];
map[x][y-1]=0;
if(map[11][12]==2){
cout<<"恭喜您通关了"<<endl;
system("pause");
system("cls");
return 0;
}
else system("cls");
}
else{
cout<<"无法移动"<<endl;
system("pause");
system("cls");
}
}
else if(a=='A'){
if(map[x][y]>map[x][y-1]){
y--;
map[x][y]=map[x][y+1];
map[x][y+1]=0;
if(map[11][12]==2){
cout<<"恭喜您通关了"<<endl;
system("pause");
system("cls");
return 0;
}
else system("cls");
}
else{
cout<<"无法移动"<<endl;
system("pause");
system("cls");
}
}
else{//输入错可重新输入
cout<<"请输入WASD"<<endl;
system("pause");
system("cls");
}
}
int main()
{
while(true){
Map();//打印地图
cin>>a;//输入方向
Go(a);//使用函数
}
return 0;
}