main.c//Maze Game Code implementation//#include <stdio.h> #define ROW 6//macro Definition Line # define COL 6//Macro definition column/** * Print map * * @param arr Map Array */void Print_arr (char Arr[row][col]) {for (int i = 0; i < ROW, i + +) {for (int j = 0; J < COL; J + +) {printf ("%c", Arr[i][j]); } printf ("\ n"); }}int Main (int argc, const char * argv[]) {char Map[row][col] = {{' # ', ' # ', ' # ', ' # ', ' # ', ' # '}, {‘#‘, ‘@‘, ‘#‘, ‘#‘, ‘ ‘, ‘ ‘}, {‘#‘, ‘ ‘, ‘#‘, ‘#‘, ‘ ‘, ‘#‘}, {‘#‘ , ‘ ‘, ‘ ‘, ‘#‘, ‘ ‘, ‘#‘}, {‘#‘, ‘#‘, ‘ ‘, ‘ ‘, ‘ ‘, ‘#‘}, {‘#‘, ‘#‘, ‘ #‘, ‘#‘, ‘#‘, ‘#‘}}; Print_arr (map); printf ("Maze game: W.", S., A. Left, D. right q. Exit \ n "); Char direction, ch, street = ', people = ' @ '; int currentx = 1, currenty = 1; while (1) {scanf ("%c", &direction); scanf ("%c", &ch); switch (direction) {case ' W ': CAse ' W ': if (map[currentx-1][currenty] = = Street) {Map[currentx-1][currenty] = people; Map[currentx][currenty] = "; currentx--; } break; Case ' s ': Case ' s ': if (map[currentx+1][currenty] = = Street) {map[currentx+1 ][currenty] = people; Map[currentx][currenty] = "; currentx++; } break; Case ' A ': Case ' a ': if (map[currentx][currenty-1] = = Street) {map[currentx][ CurrentY-1] = people; Map[currentx][currenty] = "; currenty--; } break; Case ' d ': Case ' d ': if (map[currentx][currenty+1] = = Street) {map[currentx][ CURRENTY+1] = people; Map[currentx][currenty] = "; currenty++; } break; Case ' Q ': Case ' Q ': printf ("Exit game \ n"); return 0; Break } print_arr (map); if (currenty = = 5) {printf ("Congratulations, get out of the maze!"); Break }} return 0;}
The realization of C-language maze game