int main(int argc, char **argv) { if (argc > 2 || (argc == 2 && strcmp(argv[1], "print"))) { printf( "I expect no command line argument or \"print\" as unique command line argument.\n"); return EXIT_FAILURE; } if (!get_input()) { printf("Incorrect input.\n"); return EXIT_FAILURE; } convertMaze(); if (argc == 2) { drawMaze(); return EXIT_SUCCESS; } countGates(); countWalls(); countInAccAreas(); countAccAreas(); countCuldesacs(); countPaths(); outputResult(); return EXIT_SUCCESS; }
void repaintWindow(void) { drawMaze(); ShowPosition(MY_X_LOC, MY_Y_LOC, MY_DIR); ShowView(MY_X_LOC, MY_Y_LOC, MY_DIR); //draws maze ShowAllPositions(); NewScoreCard(); XFlush(dpy); }
/* *对迷宫进行路径搜索 *数组的数字有以下含义 *0.该点没有被探索过,且可行 *1.该点不可行 *2.该点是可行的,且进行了向东的探索 *3.该点是可行的,且进行了向南的探索 *4.该点是可行的,且进行了向西的探索 *5.该点是可行的,且进行了向北的探索 *6.该点是入口 *9.该点是出口 *-1.该点已经遍历完毕四个方向,不能找到有效的路径,则置为-1 */ void ShowPath() { int curx=0,cury=0; int count=0; int flag=0; Node *Stacks=NULL; InitStack(Stacks); do{ if(maze[curx][cury]==9) { flag=1; } switch(pass(curx,cury)){ case 2: maze[curx][cury]=2; push(Stacks,curx,cury); cury++; break; case 3: maze[curx][cury]=3; push(Stacks,curx,cury); curx++; break; case 4: maze[curx][cury]=4; push(Stacks,curx,cury); cury--; break; case 5: maze[curx][cury]=5; push(Stacks,curx,cury); curx--; break; case -1: maze[curx][cury]=-1; if(!isEmpty(Stacks)) pop(Stacks,&curx,&cury); break; } count++; }while(!isEmpty(Stacks)&&flag==0); if(flag==1) { printf("The path is :\n"); printf("\n"); drawMaze(); }else { printf("\nSorry,you fail\n"); } }
void runGame(Matrix maze, Matrix fog, Position exit, Position hero) { static Slot slot[2] = {emptyCell, wallCell}; while(1) { clear(); drawMaze(maze, fog, hero); if(exit.x == hero.x && exit.y == hero.y) { printf("\n\nYOU HAVE WON!!!!\n"); return ; } Direction direction = getKey(); Position target = hero; switch(direction) { case Up: --target.y; break; case Down: ++target.y; break; case Right: ++target.x; break; case Left: --target.x; break; case Mistake: break; default: assert(0); } slot[maze.matrix[target.y][target.x]](&hero, target, fog); } }
/* *主函数 */ int main() { loop: printf("plase input the number of row m(m>0,m<100):"); scanf("%d",&m); printf("plase input the number of line n(n>0,n<100):"); scanf("%d",&n); if(m<0||m>100||n<0||n>100){ printf("The number is error,process will exit !\n"); exit(-1); } printf("The character is 'a',it is area.\n"); printf("The character is 'b',it is wall.\n"); printf("\n"); InitMaze(); printf("The oid Maze:\n"); printf("\n"); drawMaze(); printf("\n show the path ?(y/n)"); fflush(stdin); if(toupper(getch())=='Y') { printf("\n"); ShowPath(); printf("\n go on play ?(y/n)"); fflush(stdin); if(toupper(getch())=='Y') { goto loop; } else { exit(1); } } else { exit(1); } getch(); return 0; }
void main(){ init(); drawMaze(); }
PNG * SquareMaze::drawMazeWithSolution () { PNG * outPNG = drawMaze(); vector< int > path = solveMaze(); int x = 5; int y = 5; for(size_t i = 0; i < path.size(); i++) { if(path[i] == 0) { for(int j = 0; j < 11; j++) { (*outPNG)(x + j, y)->red = 255; (*outPNG)(x + j, y)->green = 0; (*outPNG)(x + j, y)->blue = 0; } x += 10; } else if(path[i] == 1) { for(int j = 0; j < 11; j++) { (*outPNG)(x, y + j)->red = 255; (*outPNG)(x, y + j)->green = 0; (*outPNG)(x, y + j)->blue = 0; } y += 10; } else if(path[i] == 2) { for(int j = 0; j < 11; j++) { (*outPNG)(x - j, y)->red = 255; (*outPNG)(x - j, y)->green = 0; (*outPNG)(x - j, y)->blue = 0; } x -= 10; } else { for(int j = 0; j < 11; j++) { (*outPNG)(x, y - j)->red = 255; (*outPNG)(x, y - j)->green = 0; (*outPNG)(x, y - j)->blue = 0; } y -= 10; } } /*draw the exit*/ int mazex = x /10; int mazey = height - 1; for(int k = 1; k < 10; k++) { (*outPNG)(mazex * 10 + k, (mazey + 1) * 10)->red = 255; (*outPNG)(mazex * 10 + k, (mazey + 1) * 10)->green = 255; (*outPNG)(mazex * 10 + k, (mazey + 1) * 10)->blue = 255; } return outPNG; }
/* This function will modify the resulting bitmap from drawMaze to show the solution and the exit. Starting at pixel (5,5) each direction in the solution vector corresponds to a trail of 11 red pixels in the given direction. If the first step is downward, pixels (5,5) through (5,15) are colored red. Then if the second step is right, pixels (5,15) through (15,15) are colored red. Then if the third step is up, pixels (15,15) through (15,5) are colored red. etc. The exit is also undone. */ BMP* SquareMaze::drawMazeWithSolution() { int x=5, y=5; int nextX=x , nextY=y; int k=0; int size =(int) solution.size(); BMP* maze= drawMaze(); for (int i = 0 ; i < size ; i++) { //move right if(solution[i]==0) { nextX=x+10; //for red line by exit if(i==size-1) nextX++; for( ; x<nextX ; x++) { ((*maze)(x,y)->Red)=255; ((*maze)(x,y)->Green)=0; ((*maze)(x,y)->Blue)=0; } } //move down else if(solution[i]==1) { nextY=y+10; //for red line by exit if(i==size-1) nextY++; for( ; y<nextY ; y++) { ((*maze)(x,y)->Red)=255; ((*maze)(x,y)->Green)=0; ((*maze)(x,y)->Blue)=0; } } //move left else if(solution[i]==2) { nextX=x-10; //for red line by exit if(i==size-1) nextX--; for( ; x>nextX ; x--) { ((*maze)(x,y)->Red)=255; ((*maze)(x,y)->Green)=0; ((*maze)(x,y)->Blue)=0; } } //move up else if(solution[i]==3) { nextY = y-10; for(; y>nextY ; y--) { ((*maze)(x,y)->Red)=255; ((*maze)(x,y)->Green)=0; ((*maze)(x,y)->Blue)=0; } } } //create exit whiten the pixels with coordinates //(x*10+k, (y+1)*10) for k from 1 to 9. for (k=1 ; k <=9 ; k++) { x= (xIndex*10)+k; y= (HEIGHT)*10; ((*maze)(x,y)->Red)=255; ((*maze)(x,y)->Green)=255; ((*maze)(x,y)->Blue)=255; } return maze; }
int main() { int i; int x; int y; int bottomOfMaze = 0; int mazewidth = 0; char rowOfMaze[102]; char buf[102]; char userInput; FILE *smileFile; i = 0; x = 0; y = 0; initscr(); cbreak (); noecho (); bottomOfMaze = drawMaze(); refresh(); while(i==0) { userInput = getch(); i = movement(userInput, bottomOfMaze); refresh(); } if (i == 2) { move(0, 0); smileFile = fopen("face.txt", "r"); if (smileFile != NULL) { while ((fgets(buf,102, smileFile)!=NULL)||(x < 2)) { i = 0; mazewidth = strlen(buf); while (i<mazewidth) { rowOfMaze[i] = buf[i]; i++; } mvprintw(y, 0, "%s", rowOfMaze); y++; x++; } i = 0; while (i<15) { mvprintw(y, i, " "); i++; } } else { printf("There appears to be an error in opening the file"); } fclose(smileFile); getch(); } endwin(); return (0); }