Thread: Maze Project

  1. #31
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    Ok i have anouther question. This one stumps me. Does the fstream fuctions "file.open(file.txt)" not work with #define? I keep getting 98 errors and then i took away the #define stuff and only errors i got where ones i would expect from values not being identified. Whats going on?

  2. #32
    A #define will work simular in function to a variable that you cannot change. Your compiler will change all occurances in your code from 'SizeOfMazeX' to '10' before it compiles your code. Its just an easy way to keep track of things. Without the define, if we were to change the size of the maze we would have to change all the for...loops as well as the definition of the maze array. This makes life easier (and safer).

    You shouldnt be getting any errors... Unless your trying to change the value of SizeOfMazeX or SizeOfMazeY? Possibly by reading to them from a file?
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  3. #33
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    ok file is 400 characters long.....meaning 20x20. I already set the size of maxX to 20 and size of maxY to 20. yet i still get error messages. I dont get it.

  4. #34
    Could you post your updated code in full?
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  5. #35
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    C:\Program Files\Microsoft Visual Studio\MyProjects\Project 2\Main.cpp(29) : error C2039: 'Maze' : is not a member of 'basic_ifstream<char,struct std::char_traits<char> >'

    thats one of them.

  6. #36
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <cmath>
    
    using namespace std;
    
    #define maxX  20;
    #define maxY  20;
    
    #define border  0;
    #define open  1;
    #define blocked 2;
    #define finish  3;
    
    char mouseX = 0;
    char mouseY = 0;
    
    char maze[maxX][maxY];
    
    ifstream InMaze;
    ofstream Maze;
    
    	int main (void)
    	{
    		
    
    		InMaze.open("maze.txt");
    		Maze.open("result.txt");
    
    		int x, y;
    		
    		if (maze[x][y] == 'x')
    			maze[x][y] = border;
    		else if (maze[x][y] == 'o')
    			maze[x][y] = open;
    		else if (maze[x][y] == 'm')
    		{
    			mouseX = x;
    			mouseY = y;
    
    			maze[x][y] = open;
    		}
    		else if (maze[x][y] == 'c')
    					maze[x][y] = finish;
    
    		do
    		{
    
    			if (maze[mouseX][mouseY-1] != blocked)
    				mouseY --;
    			else if (maze[mouseX][mouseY+1] != border)
    				mouseY ++;
    			else if (maze[mouseX-1][mouseY] != border)
    				mouseX --;
    			else if (maze[mouseX+1][mouseY] != border)
    				mouseX ++;
    
    		}while (maze[mouseX][mouseY] != blocked);
    
    		return 0;
    	}
    
    /*
    	void ****()
    	{
    		int x, y;
    
    		for (x = 0; x < maxX; x++)
    		{
    			for (y = 0; y < maxY; y++)
    			{
    				InMaze >> maze[x][y];
    		}
    	}*/

  7. #37
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    im thinking visual studio has been running to long. Mabe I should restart it. I dunno.

  8. #38
    Right away I notice something. #defines are not terminated with a semi-colan.

    This:

    #define maxX 20; //<--- Semi-Colan = bad

    should be this:

    #define maxX 20

    That should solve it... Works now?

    P.S. I'm having the occasional problem connecting to cprogramming.com right now.... not sure why. Replies may become delayed or cease completly. This submission has failed 3 times already... waiting.... still waiting... we'll see what happens...
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  9. #39
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    I now have 80 errors. It went down 18 error messages.

  10. #40
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    its saying that damn neer every varable is not a member of the ifstream char, struct, and all kinds of other stuff.

  11. #41
    They all relate to your use of iostream:

    ifstream InMaze;
    ofstream Maze;

    InMaze.open("maze.txt");
    Maze.open("result.txt");

    I dont have time to explain all that stuff, I'm sorry. Its 12:30 here and I'm one of those poor SOBs that have to get up at 6:30 and go to work. You might want to look up info on file I/O. Check out fopen, fread, and fwrite for (In my opinion) a superior method of file I/O... unless as I suspect, you're required to use iostream... Then look for an iostream tutorial (i'll try to find you one).

    Also, you cant do this:

    int x, y;

    if (maze[x][y] == 'x')
    maze[x][y] = border;
    else if (maze[x][y] == 'o')
    maze[x][y] = open;
    else if (maze[x][y] == 'm')

    x and y aren't set to anything so we dont know what element of the array we're accessing. It will crash. At least do this:

    int x = 0, y = 0;

    but I think you want to reset _all_ the maze so you need to loop through it like before:

    for (x = 0; x < SizeOfMazeX; x++)

    and all that stuff.
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  12. #42
    A couple of tutorials on iostream on this page:

    http://www.programmersheaven.com/zone3/cat34/

    scroll down to find them. Dont know if they're good or not, I just did a search.

    /* Edit */

    I'm afraid I must retire. I'll help again tomorrow if you still require it then. Good luck.
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  13. #43
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    
    using namespace std;
    
    #define maxX 20
    #define maxY 20
    
    
    
    void readin();
    void maze();
    
    ifstream InFile;
    ofstream Outfile;
    
    char mazey[maxX][maxY];
    
    	int main (void)
    	{
    
    		cout << "This is my maze program!" << endl;
    		cout << "All information will be printed to the result.txt file" << endl;
    
    
    		readin();
    		maze();
    
    		return 0;
    	}
    
    	void readin()
    	{
    		InFile.open("maze.txt");
    		Outfile.open("result.txt");
    	}
    
    	void maze()
    	{
    
    		int x = 0;
    		int y = 0;
    		char open=1;
    		char border=0;
    		char cheese=3;
    		char mouseX=0;
    		char mouseY=0;
    
    		for (x = 0; x < maxX; x++)
    		{
    			for (y = 0; y < maxY; y++)
    			{
    				InFile >> mazey[x][y];
    
    				if (mazey[x][y]=='x')
    					mazey[x][y] = border;
    				else
    				if (mazey[x][y]=='o')
    					mazey[x][y] = open;
    				else
    				if (mazey[x][y]=='m')
    				{
    					mouseX = x;
    					mouseY = y;
    
    					mazey[x][y] = open;
    				}
    				else
    				if (mazey[x][y]=='c')
    					mazey[x][y] = 0;
    
    		do
    		{
    			if (mazey[mouseX][mouseY-1] != border)
    			{
    				mouseY--;
    			    Outfile <<mouseY;
    			}
    			else
    			if (mazey[mouseX][mouseY+1] != border)
    			{
    				mouseY++;
    				Outfile << mouseY;
    			}
    			else
    			if (mazey[mouseX-1][mouseY] != border)
    			{
    				mouseX--;
    			    Outfile << mouseX;
    			}
    			else
    			if (mazey[mouseX+1][mouseY] != border)
    			{
    				mouseX++;
    			    Outfile << mouseX;
    			}
    		}while (mazey[mouseX][mouseY] != 0);
    		}
    		}
    	}
    can anyone help me with this? Any one know whats wrong with this code?

  14. #44
    Plenty. First off, whats this:

    if (mazey[x][y]=='c')
    mazey[x][y] = 0;

    You're assigning this element a value of 0 which is the same value as your border. You are, in effect, saying

    if (mazey[x][y]=='c')
    mazey[x][y] = border;

    Which we know is bogus since 'x' is your borders. Change that to = cheese.

    Second, you're closing braces for your for...loops are in the wrong place.

    }while (mazey[mouseX][mouseY] != 0);
    } //<----- Move these guys up to
    } //<----- just above the do statement.

    Third; did you check out those tutorials on iostream? Were they any good? I'm just on a break here and only have a few seconds, so I'm afraid I still cant dedicate much time, sorry...
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  15. #45
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    Um na those tutorials where'nt as good as my book. So i looked that stuff up. that maze[x][y]=0 was a typo. I forgot to take it out, i meant cheese. and where should have the loop been?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 09:05 AM
  2. Dynamic Binding
    By gpr1me in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2006, 09:01 AM
  3. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM