开头
大家好,我叫这是我58。
程序
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
void printmaze(const char strmaze[11][11]) {
FILE* fp = fopen("maze.c", "w");
int ia = 0;
int ib = 0;
for (ia = 0; ia < 11; ia++) {
fputs("//", fp);
for (ib = 0; ib < 11; ib++) {
fputc(strmaze[ia][ib], fp);
}
fputs("|\n", fp);
}
fputs("//-----------@", fp);
fclose(fp);
}
int main() {
int i = 0;
char ch = 0;
char strmaze[11][11] = {
'P','*','*','*',' ',' ',' ',' ','*','*','*',
' ','*',' ',' ',' ','*','*',' ','*','G','*',
' ','*',' ',' ',' ',' ','*',' ','*',' ',' ',
' ','*','*','*','*',' ','*',' ','*','*',' ',
' ','*',' ',' ',' ',' ','*',' ','*',' ',' ',
' ','*',' ','*','*','*','*',' ','*',' ','*',
' ','*',' ',' ','*',' ','*',' ','*',' ','*',
' ','*',' ',' ','*',' ','*',' ',' ',' ',' ',
' ','*',' ','*','*',' ','*','*','*',' ',' ',
' ',' ',' ',' ','*',' ',' ',' ',' ',' ','*',
' ',' ',' ','*','*','*',' ',' ','*','*','*'
};
char* cp = &strmaze[0][0];
printf("欢迎你来玩文件迷宫,在这个迷宫中,“P”是你,空格是你可以走的地方,“\033[32;1mG\033[0m”为\033[32;1m终点\033[0m,但是关于迷宫的所有信息都会存放到一个名叫\033[4mmaze.c\033[0m的文件上去,你需要找到它才能看清今天要走的迷宫,如果没有它的话,就寸步难行了,而你只要走到\033[32;1m终点\033[0m,就可以\033[32;1m赢\033[0m了,你听懂了吗?");
Sleep(6400);
system("cls");
while ('G' == strmaze[1][9]) {
printmaze(strmaze);
scanf("%c", &ch);
while ('\n' != getchar()) {
;
}
*cp = ' ';
switch (ch) {
case 'w':
for (i = 0; i < 11; i++) {
if (cp == &strmaze[0][i]) {
break;
}
}
11 == i && '*' != *(cp - 11) && (cp -= 11);
break;
case 'a':
for (i = 0; i < 11; i++) {
if (cp == &strmaze[i][0]) {
break;
}
}
11 == i && '*' != *(cp - 1) && cp--;
break;
case 's':
for (i = 0; i < 11; i++) {
if (cp == &strmaze[10][i]) {
break;
}
}
11 == i && '*' != *(cp + 11) && (cp += 11);
break;
case 'd':
for (i = 0; i < 11; i++) {
if (cp == &strmaze[i][10]) {
break;
}
}
11 == i && '*' != *(cp + 1) && cp++;
break;
default:
break;
}
*cp = 'P';
system("cls");
}
system("color 0A");
FILE* fp = fopen("maze.c", "w");
fputs("//恭喜你,你赢了", fp);
fclose(fp);
return 0;
}
程序的流程图
程序游玩的效果
文件迷宫
下一篇博客要做的东西
迷宫制造