Like Tree1Likes
  • 1 Post By datainjector

maze ****

This is a discussion on maze **** within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> #include <stdlib.h> //#include <conio.h> #define SIZE 12 void movement( int [][SIZE], int , int *, int * ...

  1. #1
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356

    maze ****

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    //#include <conio.h>
    
    #define SIZE 12
    
    void movement( int [][SIZE], int , int *, int * );
    void printarray( int [][SIZE] );
    
    int main(void)
    {
     int area[SIZE][SIZE] = { 1,1,1,1,1,1,1,1,1,1,1,1,
                              1,0,0,0,1,0,0,0,0,0,0,1,
                              0,0,1,0,1,0,1,1,1,1,0,1,
                              1,1,1,0,1,0,0,0,0,1,0,-1,
                              1,0,0,0,0,1,1,1,0,1,0,1,
                              1,1,1,1,0,1,0,1,0,1,0,1,
                              1,0,0,1,0,1,0,1,0,1,0,1,
                              1,1,0,1,0,1,0,1,0,1,0,1,
                              1,0,0,0,0,0,0,0,0,1,0,1,
                              1,1,1,1,1,1,0,1,1,1,0,1,
                              1,0,0,0,0,0,0,1,0,0,0,1,
                              1,1,1,1,1,1,1,1,1,1,1,1 };
     int position, cnt_main, cnt_sub;
     int choice, row, col;
     row = 3, col =0;
    
     printf(" m       m      a       zzzzzzz   Eeeeeeee\n"
    		" M m   m M     a  a      z        E       \n"
    		" M   m   M    aAAAAa       z      Eeeeeeee\n"
    		" m       m   a      a        z    E       \n"
    		" m       m  a        a  zzzzzzz   Eeeeeeee\n");
     while (area[3][11] == -1 )
     {
    	puts("");
        choice =  getch();
    	movement( area , choice, &row, &col);
    	system("cls");
    	printarray( area );
     }
     system("cls");
     printf("\nCongratulation you have won!!!\n");
    
    
    
    
    
          return 0;
    }
    void movement ( int array[SIZE][SIZE], int choice, int *row, int *col )
    {
    
    	switch(choice){
    		case 'w' :
    			if ( array[--(*row)][*col] != 1 ){
    				array[(*row)][*col] = 2;
    				array[++(*row)][*(col)] = 0;
    				--(*row);
    				}
    			else
    				array[++(*row)][*col] = 2;
    			break;
    	   case 's' :
    			if ( array[++(*row)][*col] != 1 ){
    				 array[*row][*col] = 2;
    				 array[--(*row)][(*col)] = 0;
    				 ++(*row);
    			}
    			else
    				array[--(*row)][*col] = 2;
    			break;
    	  case 'a' :
    			if ( array[*row][--(*col)] != 1 ){
    				array[*row][*col] = 2;
    				array[*row][++(*col)] = 0;
    				--(*col);
    			}
    			else
    				array[*row][++(*col)] = 2;
    			break;
    	  case 'd' :
    			if ( array[*row][++(*col)] != 1 ){
    				array[*row][*col] = 2;
    				array[*row][--(*col)]= 0;
    				++(*col);
    			}
    			else
    				array[*row][--(*col)] = 2;
    			break;
    	}
    }
    void printarray( int area[SIZE][SIZE] )
    {
    	int cnt_main, cnt_sub;
    
    
    	for ( cnt_main =0; cnt_main <= SIZE-1; cnt_main++ ){
    		for ( cnt_sub = 0; cnt_sub <= SIZE-1; cnt_sub++ ){
    			if ( area[cnt_main][cnt_sub] == 1)
    				printf("");    //puthcar(2);
    			else if ( area[cnt_main][cnt_sub] == 0)
    				printf(" ");
    			else if ( area[cnt_main][cnt_sub] == -1)
    				printf("");        //putchar() Check it out your self
    			else
    				printf("");
    		}
    		printf("\n");
    	}
    }
    Okay Well the only thing i wanted to know like since getch () is not ANSI is there any unbuffered ANSI fucntion that can help me do what getch can do ???
    duanerule likes this.
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You posted that entire program just to ask if there was an ANSI standard unbuffered input function? That's amusing. The answer is no.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    Originally posted by quzah
    You posted that entire program just to ask if there was an ANSI standard unbuffered input function? That's amusing. The answer is no.

    Quzah.
    If you have read ...my post named....help with f I/O...then you should know why did this miracle happen...just ignore me
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having trouble solving maze.
    By eurus in forum C Programming
    Replies: 3
    Last Post: 02-17-2006, 01:52 AM
  2. Q: Recursion to find all paths of a maze
    By reti in forum C Programming
    Replies: 7
    Last Post: 11-26-2002, 09:28 AM
  3. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-25-2002, 12:00 AM
  4. Algorithm to walk through a maze.
    By Nutshell in forum C Programming
    Replies: 30
    Last Post: 01-21-2002, 01:54 AM
  5. Maze game, complete with maze editor and an example maze!
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 01-20-2002, 03:27 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21