掌握调试Visual Studio 2010 - 初学者指南 [ ^ ] 使用Visual Studio 2010进行基本调试 - YouTube [ ^ ] 1.11 - 调试程序(步进和断点)|学习C ++ [ ^ ] 调试器仅显示您的代码正在执行的操作,您的任务是与应该执行的操作进行比较。 I have been making a game to walk through mazes and solve them for a college project.I have been trying to make my character move and, oddly it was working perfectly for like 20 minutes with the character moving and the steps counting. After that, it just stopped working and the code was the same. Was it a problem with the compiler (DEV C++) or the code is faulty?W, A, S, D is for moving but everytime i press one, the character does not move and just spams steps: 0 for every click.What I have tried:The main part (player is a ascii character; ex/ey are the coordinates of the entrance; sx/sy are the coordinates of the end) :steps=0;do{do{key=getch();printf("steps: %d", steps);if(key=='w'){steps+=1;if(*(lab+pointerpoint(ex, ey-2))==track){system("cls");*(lab+pointerpoint(ex, ey))=track;*(lab+pointerpoint(ex, ey-2))=player;printlab();}else{steps-=1;continue;}}if(key=='s'){steps+=1;if(*(lab+pointerpoint(ex, ey+2))==track){system("cls");*(lab+pointerpoint(ex, ey))=track;*(lab+pointerpoint(ex, ey+2))=player;printlab();}else{steps-=1;continue;}}if(key=='a'){steps+=1; if(*(lab+pointerpoint(ex-2, ey))==track){system("cls");*(lab+pointerpoint(ex, ey))=track;*(lab+pointerpoint(ex-2, ey))=player;printlab();}else{steps-=1;continue;}}if(key=='d'){steps+=1;if(*(lab+pointerpoint(ex+1, ey))==track){system("cls");*(lab+pointerpoint(ex, ey))=track;*(lab+pointerpoint(ex+2, ey))=player;printlab();}else{steps-=1;continue;}}} while( *(lab+pointerpoint(ex, ey)) != *(lab+pointerpoint(sx, sy)) );} while(key!='q');//The function that generates the maze (N is size):void labgen(int x, int y){if(N%2==0) N++;sx=N-1; sy=N;maze = (char *)malloc(sizeof(char)*N*N+sizeof(char));*(maze+pointerpoint(N, N)+1)='\0';int i=0;for( ; i<N*N ; i++){*(maze+i)=wall;}*(lab+pointerpoint(ex, ey))=player;*(lab+pointerpoint(ex, ey+1))=track;*(lab+pointerpoint(sx, sy))=track;nextblock(ex, ey+1); }//Functions that deal with points:char point(int x, int y){if(x<1||y<1||x>N||y>N) return '0';int point = N*(y-1)+x -1;return *(lab+point);}int pointerpoint(int x, int y){int point = N*(y-1)+x -1;return point;} 解决方案 Oddities are against your code, you are the only one able to tell because we can't run your code.Your code do not behave the way you expect, or you don't understand why !There is an almost universal solution: Run your code on debugger step by step, inspect variables.The debugger is here to show you what your code is doing and your task is to compare with what it should do.There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.Debugger - Wikipedia, the free encyclopedia[^]Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]Basic Debugging with Visual Studio 2010 - YouTube[^]1.11 — Debugging your program (stepping and breakpoints) | Learn C++[^]The debugger is here to only show you what your code is doing and your task is to compare with what it should do. 这篇关于在C中遇到迷宫游戏的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-23 01:11