473,385 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

I'm stuck with my Maze project. I can't get it to display and what codes to use to g

3
It focuses on the computer AI, is always fast, and uses no extra memory. Requirements are for me to use OOPs concepts and C++ programming. This project should be written using 3 files (.h file should contain the class header, one .cpp file for the implementation and one .cpp file for main. All control structres must use {} even if the control structure contains only one statement.

I think I know what I'm doing, however, stuck at the moment and can't figure out how to put the CPP for the implementation. HELP!!!

This is my Maze.h file:

Expand|Select|Wrap|Line Numbers
  1. //The purpose of this game is to go through a maze and 
  2. //use a program that uses the computer to find the way through the 
  3. //maze
  4.  
  5. #include <iostream>
  6. #include <string>
  7.  
  8. using namespace std;
  9.  
  10. #ifndef MAZE_H
  11. #define MAZE_H
  12. class Maze
  13. {
  14. private:
  15.     enum Direction {DOWN, RIGHT, UP, LEFT};
  16.     static const int ROWS = 12;
  17.     static const int COLS = 12;
  18. public:
  19.     Maze();
  20.     void mazeTraversal(char maze [][ COLS ], int row, int col, int direction);
  21.     void printMaze(const char maze [][ COLS ] );
  22.     bool validMove(const char maze[] [COLS], int row, int col);
  23.     bool coordsAreEdge(int row, int col);
  24.  
  25. };
  26. #endif
  27.  
  28.  
  29. Below is my Maze.cpp implementation file:
  30.  
  31. #include "Maze.h"
  32.  
  33. void Maze::mazeTraversal(char maze[][COLS], int row, int col, int direction)
  34. {
  35.  
  36. }
  37. void Maze::printMaze(const char maze[][COLS])
  38. {
  39.     cout<<"please press enter"<<endl;
  40.     cout<<validMove()<<endl;
  41.     cin.get();
  42.     enum Direction {DOWN, RIGHT, UP, LEFT};
  43.  
  44.     switch(option)
  45.     {
  46.     case DOWN:
  47.         cout<<LEFT<<endl;
  48.         break;
  49.     case RIGHT:
  50.         cout<<DOWN<<endl;
  51.         break;
  52.     case UP:
  53.         cout<<RIGHT<<endl;
  54.         break;
  55.     case LEFT:
  56.         cout<<UP<<endl;
  57.     }
  58.  
  59. }
  60.  
  61.  
  62. And last, this is my Main.cpp file (the "1" indicate the wall of the maze while the "0" indicate the path):
  63.  
  64. #include "Maze.h"
  65.  
  66. int main()
  67. {
  68.     int rowStart = 3;
  69.     int colStart = 1;
  70.     Maze mazeObj;
  71.     enum Direction{DOWN, RIGHT, UP, LEFT};
  72.  
  73.     char tempMaze [12][12] = 
  74.     {{'1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1'},
  75.     {'1', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '1'},
  76.     {'0', '0', '1', '0', '1', '0', '1', '1', '1', '1', '0', '1'},
  77.     {'1', '1', '1', '0', '1', '0', '0', '0', '0', '1', '0', '1'},
  78.     {'1', '0', '0', '0', '0', '1', '1', '1', '0', '1', '0', '0'},
  79.     {'1', '1', '1', '1', '0', '1', '0', '1', '0', '1', '0', '1'},
  80.     {'1', '0', '0', '1', '0', '1', '0', '1', '0', '1', '0', '1'},
  81.     {'1', '1', '0', '1', '0', '1', '0', '1', '0', '1', '0', '1'},
  82.     {'1', '0', '0', '0', '0', '0', '0', '0', '0', '1', '0', '1'},
  83.     {'1', '1', '1', '1', '1', '1', '0', '1', '1', '1', '0', '1'},
  84.     {'1', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '1'},
  85.     {'1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1'} };
  86.  
  87.     mazeObj.mazeTraversal(tempMaze, rowStart, colStart, RIGHT);
  88.     mazeObj.printMaze();
  89. }
Apr 29 '13 #1
1 1693
weaknessforcats
9,208 Expert Mod 8TB
In your class Maze you have:

Expand|Select|Wrap|Line Numbers
  1. void printMaze(const char maze [][ COLS ] );
In your main() you have:

Expand|Select|Wrap|Line Numbers
  1. mazeObj.printMaze();
So the printMaze in your main needs a Maze::printMaze() which you have failed to provide. Te one you provided has an argument.

Which brings me to: Why does printMaze in your class have an argument? Should not the object know the ROWS and COLS?

Which brings me to: Why are ROWS and COLS static? Should not the object have a SetRows and SetCols because ROWS and COLS are Maze member variables? Or are you requiring that all Maze objects have the same size maze?

Which brings me to: Why is the maze created by using a variable tempMaze? Should not the default Maze constructor create a default maze on the heap and the Maze destructor deletes it? The idea is the object manages its own data and not the data that is outside the object. If the maze becomes a private member variable then you won't need all these functions with char maze[][COLS] arguments. Instead this is replaced by the this pointer which does not appear in the argument list.
Apr 29 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

22
by: Bernard Fields | last post by:
Greets, all. As the title suggests, I'm trying to make a maze. Specifically, it's a top-down, 2-d maze, preferably randomly generated, though I'm willing to forego that particular aspect as...
0
by: Mark Shehan | last post by:
I am using VS2005 and ASP.NET 2 I want to use IIS to host some .NET remoting. I have a website I created called RemotingHost. I created another class project called RemotingServer and in there...
0
by: John Dann | last post by:
I have a program that needs to access a prewritten external data file that is supplied with the program. I want to place this data file in...
3
by: bb nicole | last post by:
Below is my login function, it can work well, but after i include it at my homepage, the print message is in the login page... What should it do to make the print message invalid username or...
3
bhing
by: bhing | last post by:
Hiya all!!! i would like to ask about the http logs i found in logs directory in tomcat. This is some of the codes i clipped: ----------------------------------------------------------- ...
7
by: JoeP | last post by:
Hi All, What codes grab the IP address? Thanks, Joe
4
MMcCarthy
by: MMcCarthy | last post by:
http://bytes.com/images/howtos/projectscope_blocks.jpgAs a freelance IT consultant for over 10 years, I’ve come to appreciate well defined project scopes. A project scope is a common understanding...
4
by: liams | last post by:
So, a few days ago I decided to try Project Euler question #22. The question is: Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.