#include <stdio.h> void printMaze(char MAZE[50][50]); int main(void) { int yValue = 9; int xValue = 0; int escapeXvalue = 49; int escapeYvalue = 9; int escapeYvalue2 = 39; char movement; //50 x 50 array MAZE using '*' to represent walls and ' ' to represent a moveable path char MAZE[50][50] = { {'*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*'}, {'*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*'}, {'*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*'}, {'*',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*'}, {'*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*','*','*','*','*','*','*','*','*',' ','*'}, {'*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*',' ',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ','*'}, {'*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*',' ','*','*','*',' ','*',' ','*','*','*','*','*','*','*',' ','*',' ','*'}, {'*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*',' ','*','*','*',' ','*',' ','*','*','*','*','*','*','*',' ','*',' ','*'}, {'*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*','*','*','*','*','*','*','*','*','*',' ',' ',' ','*','*','*',' ','*',' ','*','*','*','*','*','*','*',' ','*',' ','*'}, {'0',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*','*','*','*','*','*','*',' ','*',' ',' '}, {'*',' ','*',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*','*','*','*','*','*','*',' ','*',' ','*'}, {'*',' ','*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*','*','*','*','*','*','*',' ','*',' ','*'}, {'*',' ','*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ','*'}, {'*',' ','*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*','*','*','*','*','*','*','*','*','*','*',' ','*'}, {'*',' ','*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ','*'}, {'*',' ','*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*','*','*','*','*','*','*','*','*',' ','*',' ','*'}, {'*',' ','*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*'}, {'*',' ','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*'}, {'*',' ','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*'}, {'*',' ','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ','*'}, {'*',' ','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*'}, {'*',' ','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*'}, {'*',' ','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*'}, {'*',' ','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*','*','*','*','*','*','*','*','*',' ','*',' ','*'}, {'*',' ','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ','*'}, {'*','*','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*','*','*','*','*','*','*','*','*',' ','*',' ','*'}, {' ',' ',' ',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ','*'}, {'*',' ','*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*','*','*','*','*','*','*','*','*',' ','*'}, {'*',' ','*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*','*','*','*','*','*','*','*','*',' ','*'}, {'*',' ','*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*','*','*','*','*','*','*','*','*',' ','*'}, {'*',' ','*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*','*','*','*','*','*','*','*','*',' ','*'}, {'*',' ','*',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ','*'}, {'*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*','*','*','*','*','*','*','*','*',' ','*',' ','*'}, {'*',' ','*',' ','*','*','*',' ',' ',' ',' ',' ','*','*',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*','*','*','*','*','*','*','*','*',' ','*',' ','*'}, {'*',' ','*',' ','*','*',' ',' ','*','*','*',' ','*','*',' ','*','*',' ','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*'}, {'*',' ','*',' ','*','*',' ','*','*','*','*',' ','*','*',' ','*','*',' ','*','*',' ',' ',' ',' ',' ',' ','*','*',' ',' ',' ',' ',' ','*','*',' ','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*'}, {'*',' ','*',' ','*','*',' ','*',' ',' ','*',' ','*','*',' ','*','*','*','*','*','*','*','*','*','*',' ','*','*',' ','*','*','*',' ',' ','*',' ','*','*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ','*'}, {'*',' ','*',' ','*','*',' ','*','*',' ','*',' ','*','*',' ',' ',' ',' ',' ','*','*','*','*','*','*',' ','*','*',' ','*','*','*','*',' ','*',' ','*','*',' ','*','*','*','*','*','*','*','*','*','*','*'}, {'*',' ','*',' ','*','*',' ','*','*',' ',' ',' ','*','*','*','*','*','*',' ','*','*','*','*','*','*',' ','*','*',' ','*','*','*','*',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*','*','*','*','*'}, {'*',' ','*',' ','*','*',' ','*','*','*','*','*','*','*','*','*','*','*',' ','*','*','*','*','*','*',' ',' ',' ',' ','*','*','*','*',' ','*',' ','*','*','*','*','*','*','*','*',' ','*','*','*',' ',' '}, {'*',' ','*',' ','*','*',' ','*','*','*','*','*','*','*','*','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*','*','*','*','*','*','*','*',' ','*','*','*',' ','*'}, {'*','*','*',' ','*','*',' ','*','*','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*','*','*','*','*','*','*','*',' ','*','*','*',' ','*'}, {'*',' ',' ',' ','*','*',' ',' ',' ','*',' ','*','*','*','*',' ','*','*','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*','*','*','*','*','*','*','*',' ','*','*','*',' ','*'}, {'*',' ','*','*','*','*',' ','*',' ','*',' ','*','*','*','*',' ','*','*','*','*','*',' ','*','*','*','*','*','*','*','*','*','*','*',' ','*',' ','*','*','*','*','*','*','*','*',' ','*','*','*',' ','*'}, {'*',' ','*','*','*','*',' ','*',' ','*',' ',' ',' ','*','*',' ','*','*','*','*','*',' ','*','*','*','*','*','*','*','*',' ',' ',' ',' ','*',' ','*','*','*','*','*','*','*','*',' ','*','*','*',' ','*'}, {'*',' ','*','*','*','*',' ','*',' ','*','*','*',' ','*','*',' ','*','*','*','*','*',' ','*','*','*','*','*','*','*','*',' ','*','*','*','*',' ','*','*','*','*','*','*','*','*',' ','*','*','*',' ','*'}, {'*',' ','*','*','*','*',' ','*',' ',' ','*','*',' ','*','*',' ','*','*','*','*','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*','*','*','*',' ','*','*','*','*','*','*','*','*',' ',' ',' ',' ',' ','*'}, {'*',' ','*','*','*','*',' ','*','*',' ','*','*',' ','*','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*','*','*','*','*','*','*','*',' ','*','*','*','*','*'}, {'*',' ',' ',' ',' ',' ',' ','*','*',' ',' ',' ',' ','*','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*'}, {'*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*'}}; //infinite loop only untill logic for figuring out how MAZE logic should work //loop iterates through user choices for movement through the MAZE while(1){ if ((yValue == escapeYvalue && xValue == escapeXvalue) || (yValue == escapeYvalue2 && xValue == escapeXvalue)) { system("clear"); printf("You beat the game! n"); return 0; } printMaze(MAZE); printf("Enter direction you want to move A(left) S(down) D(right) W(up)n"); movement = getchar(); /* the 'if' statements in the cases represent checks to make sure the move doesn't conflict with out of bounds in the array or traversal through a '*' */ switch(movement){ case 'A' : case 'a' : //player is moving character to the left if(xValue > 0 && MAZE[yValue][xValue - 1] == ' '){ printf("A action executedn"); MAZE[yValue][xValue] = ' '; xValue --; MAZE[yValue][xValue] = '0'; } else{ printf("A action could not be executedn"); } system("clear"); break; case 'D' : case 'd' : //player is moving character to the right if(xValue < 50 && MAZE[yValue][xValue + 1] == ' '){ printf("D action executedn"); MAZE[yValue][xValue] = ' '; xValue ++; MAZE[yValue][xValue] = '0'; } else{ printf("D action could not be preformedn"); } system("clear"); break; case 'S' : case 's' : //player is moving character down if(yValue < 50 && MAZE[yValue + 1][xValue] == ' '){ printf("S action executedn"); MAZE[yValue][xValue] = ' '; yValue ++; MAZE[yValue][xValue] = '0'; } else{ printf("S action could not be executedn"); } system("clear"); break; case 'W' : case 'w' : //player is moving character up if(yValue > 0 && MAZE[yValue - 1][xValue] == ' '){ printf("W action executedn"); MAZE[yValue][xValue] = ' '; yValue --; MAZE[yValue][xValue] = '0'; } else{ printf("W action could not be preformedn"); } system("clear"); break; } } } void printMaze(char MAZE[][50]) { for (int x = 0; x < 50; x++) { for(int y = 0; y < 50; y++) { printf("%c ", MAZE[x][y]); } printf("n"); } }
相关知识
《天龙八部》种花大全:攻略指南,让你成为游戏中的园艺大师
绿色学校创建工作总结15篇
最新创建绿色学校工作计划及工作记录(通用12篇)
绿色学校创建工作计划(精选6篇)
如何在JavaScript中按字符和新集合拆分列表?
创建绿色校园工作总结(7篇)
花艺布置如何在婚礼上起到关键性作用?
如何在阳台养花 阳台养花的技巧
学校环保工作总结与反思(精选15篇)
我的花店,我做主
网址: 如何在我为学校创建的游戏中实现指针 https://m.huajiangbk.com/newsview104729.html
上一篇: NOIP初赛知识点复习总结资料讲 |
下一篇: 受益一生的45种思维方法 |