again with the maze.

This is a discussion on again with the maze. within the C++ Programming forums, part of the General Programming Boards category; Ok guys this is the last thread I will post about this topic for a while. Main reason my program ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    73

    again with the maze.

    Ok guys this is the last thread I will post about this topic for a while. Main reason my program is due at 2:30 this afternoon. So i need some help guys. Ok heres what iv got so far;

    Code:
    	for (x1=0; x1<20; x1++)
    			{
    				for (y1=0; y1<20; y++)
    				{
    
    				 InFile >> maze[x1][y1];
    
     	    		 open = 'o';
           
    				 mouse = 'm';
    				}
    			}
    
    		nextsquare!=99;
    				do
    				{
    				
    
    					if (mouse+1 == open)
    					{
    						mouse++;
    						nextsquare = mouse;
    						cout << "down" << endl;
    						Outfile << "down" << endl;
    					}
    					else
    					if (mouse-1 == open)
    					{
    						mouse--;
    						nextsquare = mouse;
    						cout << "up" << endl;
    						Outfile << "up" <<  endl;
    					}
    					else
    					if (mouse+1 == open)
    					{
    						mouse++;
    						nextsquare = mouse;
    						cout << "right" << endl;
    						Outfile << "right" << endl;
    					}
    					else
    					if (mouse-1 == open)
    					{
    						mouse--;
    						nextsquare = mouse;
    						cout << "left" << endl;
    						Outfile << "left" << endl;
    					}
    
    				}while (nextsquare == true);
    Now im having to use iostream. The program keeps crashing I dont know why. Any help?

  2. #2
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    (I never saw your other maze thread)

    How does it keep crashing?

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    When I start the program it prints out one of the directions and then just stops. Ok heres an example..

    down

    _ (thats the little underscore blinking thats all it does). O and since you havnt seen my other thread ill go ahead and fill you in. Im making a program that has to find its way through a maze. I think im doing it right but not sure. I juz added other stuff to the code heres the updated file.

    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    
    using namespace std;
    
    #define max 400
    
    ifstream InFile;
    ofstream Outfile;
    
    char maze[20][20];
    
    	int main (void)
    	{
    
    		char x = 0; 
    		char y = 0;
    		char x1 = 20;
    		char y1 = -20;
    		char x2 = -20;
    		char y2 = 20;
    		char mouse;
    		char cheese;
    		char counter;
    		char nextsquare;
    		char o;
    		char open;
    
    		InFile.open("maze.txt");
    		Outfile.open("result.txt");
    		
    		cout << "This is my maze program!" << endl;
    		cout << "All information will be printed to the result.txt file" << endl;
    
    
    				 InFile >> maze[x1][y1];
    
     	    		 open = 'o';
           
    				 mouse = 'm';
    				 cheese = 'c';
    			
    
    		nextsquare!=cheese;
    				do
    				{
    				
    
    					if (mouse+2 == open)
    					{
    						mouse++;
    						nextsquare = mouse;
    						cout << "down" << endl;
    						Outfile << "down" << endl;
    					}
    					else
    					if (mouse-2 == open)
    					{
    						mouse--;
    						nextsquare = mouse;
    						cout << "up" << endl;
    						Outfile << "up" <<  endl;
    					}
    					else
    					if (mouse+2 == open)
    					{
    						mouse++;
    						nextsquare = mouse;
    						cout << "right" << endl;
    						Outfile << "right" << endl;
    					}
    					else
    					if (mouse-2 == open)
    					{
    						mouse--;
    						nextsquare = mouse;
    						cout << "left" << endl;
    						Outfile << "left" << endl;
    					}
    
    				}while (mouse > 0);
    
    
    
    				if (mouse == 99)
    				{
    					cout << "Maze completed!" << endl;
    					Outfile << "Maze completed!" << endl;
    				}
    			
    		
    		return 0;
    	}
    any ideas? O and any ideas on how to make it search repetedly until the shorest path through the maze is found?

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, 12: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, 08:28 AM
  3. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM
  4. Algorithm to walk through a maze.
    By Nutshell in forum C Programming
    Replies: 30
    Last Post: 01-21-2002, 12: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, 02:27 AM

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