作业介绍
char maze[18][24]= {"************** ********",//1
"* * * *",//2
"* ************ * ** * *",//3
"* * **** * *",//4
"* ********** * * * *",//5
"* ** * * ******",//6
"* ** ***** ***** * ** *",//7
"* * * *",//8
"****** * ********** *",//9
"* * * * * $ *",//10
"* **** * * ****** *****",//11
"* * * * * * * *",//12
"* * ****** * ** * * * *",//13
"* * * ** * * * *",//14
"* ********** ** * *",//15
"* * *",//16
"*************** *******",//17
"***********************"};//18
#include<bits/stdc++.h>//完整迷雾
#include<windows.h>
#include<conio.h>
using namespace std;
int main()
{
char maze[18][24]= {"************** ********",//1
"* * * *",//2
"* ************ * ** * *",//3
"* * **** * *",//4
"* ********** * * * *",//5
"* ** * * ******",//6
"* ** ***** ***** * ** *",//7
"* * * *",//8
"****** * ********** *",//9
"* * * * * $ *",//10
"* **** * * ****** *****",//11
"* * * * * * * *",//12
"* * ****** * ** * * * *",//13
"* * * ** * * * *",//14
"* ********** ** * *",//15
"* * *",//16
"*************** *******",//17
"***********************"};//18
int x,y;
srand(time(0));
x = rand() % 18;
y = rand() % 23;
while(maze[x][y] != ' '){
x = rand() % 18;
y = rand() % 23;
}
maze[x][y] = 'i';
int i,j;
for(i = 0;i < 18;++i){
for(j = 0;j < 23;++j){
cout << maze[i][j] << " ";
}
cout << endl;
}
char c;
while(true)
{
c=getch();
if(c=='w'&&maze[x-1][y]!='*')
{
maze[x][y]=' ';
x--;
maze[x][y]='i';
}//上
if(c=='s'&&maze[x+1][y]!='*')
{
maze[x][y]=' ';
x++;
maze[x][y]='i';
}//下
if(c=='a'&&maze[x][y-1]!='*')
{
maze[x][y]=' ';
y--;
maze[x][y]='i';
}//左
if(c=='d'&&maze[x][y+1]!='*')
{
maze[x][y]=' ';
y++;
maze[x][y]='i';
}//右
system("cls");
for(int i = 0;i < 18;++i){
for(int j = 0;j < 23;++j){
if(i>x-2&&i<x+2&&j>y-2&&j<y+2)
cout << maze[i][j] << " ";
else
cout<<" ";
}
cout << endl;
}
}
return 0;
}
最后一题为案例代码存储
- 状态
- 已结束
- 题目
- 4
- 开始时间
- 2023-10-4 0:00
- 截止时间
- 2023-11-30 23:59
- 可延期
- 24 小时