Hello everyone ,
This is my very first post and i am have started learning C programming 2 months back so you can say i am a beginner in C ... but i have tried hard currently understanding conditional statments (IF-ELSE) , Loops , arrays and functions .
I have been given a task in my university that i need to design a "maze traversal game" such that the maze changes itself randomly everytime a new user starts the game after thinking and trying day and night for past days i have managed to write the code of the maze in such a way that the square walls of the maze is built using arrays while the inside the squared walls the maze changes itself randomly but the problem i am facing is i simply can't think of any code such that if a user starts to play the game he starts at position X and walks himself all the way through the End position and major thing is whenever a new user is going to start the maze , the maze will be automatically generated but in such a way that a way will also be induced in the maze that the user starts from the starting position and ends at the ending point.
Kindly i have tried hard thinking of such a code but if anyone can help me , i would be grateful .
the code which i have written roughly so far is
i have also attached the pictures of the maze traversal game which is clearly described in 3 steps , how the maze should be , how it changes randomly and also along with changing itself , it shows a valid path from starting and ending point and also a pain is the starting and ending points also changes randomly.Code:#include<stdio.h> #include<conio.h> #include<time.h> int main () { char maze[12][12]; int x,y,a,b,c; char question; srand((unsigned) time (NULL)); printf("******************************************\nWelcome to the maze game !\t\t *\nPlease note the keys to play the game\t *\nUP\tDOWN\tRIGHT\tLEFT\t\t *\n[i]\t[m]\t[h]\t[l]\t\t *\n******************************************"); printf("\n\n"); do { for(a=0;a<12;a++) { maze[0][a]='#'; maze[11][a]='#'; } for(b=0;b<12;b++) { maze[b][0]='#'; maze[b][11]='#'; } for (x=1;x<=10;x++) for (y=1;y<=10;y++) { c=rand()%10; if(c>1 && c<6 ) maze[x][y]='#'; else maze[x][y]='.'; } for (x=0;x<12;x++) { printf("\n"); for (y=0;y<12;y++) { printf("%c",maze[x][y]); } } printf("\n Press [c] to continue : "); fflush(stdin); scanf("%c",&question); }while( question == 'c'); printf("\n"); printf("\n"); return 0; }
i have used Quincy 2005 to write the code above and it works without anysort of errors .
Please help , kindly check the pictures attached , i really am not able to understand an algorithm.
Thanks



LinkBack URL
About LinkBacks


