What c++ code can be used to make an 'X' move through a maze. I have some code, but I'm not sure where to go from there. I have divided the program into three files, A header file, a main file and a .cpp implementation file.
In my implementation file I have: - #include "Maze.h"
-
-
Maze::Maze()
-
{
-
-
}
-
void Maze::mazeTraversal(char maze[][COLS], int row, int col, int direction)
-
{
-
enum Direction {DOWN, RIGHT, UP, LEFT};
-
-
switch(option)
-
{
-
case DOWN:
-
cout<<LEFT<<endl;
-
break;
-
case RIGHT:
-
cout<<DOWN<<endl;
-
break;
-
case UP:
-
cout<<RIGHT<<endl;
-
break;
-
case LEFT:
-
cout<<UP<<endl;
-
}
-
}
-
void Maze::printMaze()
-
{
-
cout<<"please press enter"<<endl;
-
cout<<validMove()<<endl;
-
cin.get();
-
-
-
}
-
Maze::~Maze()
-
{
-
-
}
In my main.cpp I have: - #include "Maze.h"
-
-
int main()
-
{
-
-
int rowStart = 2;
-
int colStart = 0;
-
Maze mazeObj;
-
enum Direction{DOWN, RIGHT, UP, LEFT};
-
-
char tempMaze [12][12] =
-
{{'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', '0'},
-
{'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'} };
-
-
mazeObj.mazeTraversal(tempMaze, rowStart, colStart, RIGHT);
-
}
In my header file I have: - #include <iostream>
-
#include <string>
-
-
using namespace std;
-
-
#ifndef MAZE_H
-
#define MAZE_H
-
class Maze
-
{
-
private:
-
enum Direction {DOWN, RIGHT, UP, LEFT};
-
static const int ROWS = 12;
-
static const int COLS = 12;
-
public:
-
Maze();
-
~Maze();
-
void mazeTraversal(char maze [][ COLS ], int row, int col, int direction);
-
void printMaze(const char maze [][ COLS ] );
-
bool validMove(const char maze[] [COLS], int row, int col);
-
bool coordsAreEdge(int row, int col);
-
-
};
-
#endif
-
-
1 3976
First, you write a program to display your maze array.
Second, locate where in your array the object is to be located
Third, make a copy of your array. Always keep te original with no changes. It is your master.
Fourth, put an X in the copied array at the correct spot
Fifth, display the copied array.
To move to the next square, just make another copy of the master array, put your X on the copy and re-display the copy. You will see the X appear to move. Like a cartoon.
If you clear your screen so your displays always overlay one another you will see the X travel.
You may need to put a sleep in your loop displaying the copies to slow things down enough so your eye can follow the X.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: serge calderara |
last post by:
Dear all,
I have define a suer type as follow
Structure USER_PARAM_LIST
Dim LastUser As String
Dim SaveEntry As Boolean
End Structure
and a variable of that type
|
by: Frank Rizzo |
last post by:
I have VS.NET 2003.
For some reason the Object Browser window appears as one of the tabs for
every project I open. Even if I just open VS.NET without any projects,
it still appears.
How can...
|
by: Barkster |
last post by:
I don't usually create installers for my projects cause we have dotnet on
all our machines and I normally just copy the exe and any required Dll's to
the folder where I want to run. Normally I...
|
by: Lal - Luxor |
last post by:
please help me.
how to work object.move will work on ve.net
regards
lal
|
by: Michael Yanowitz |
last post by:
Hello:
Are there any tools to convert non-object-oriented code
into object-oriented code?
If not, perhaps something that I can pass in two (or more)
classes and will create a base-class and...
|
by: vedran |
last post by:
Hello,
How can I move objects in directpython???
|
by: catchrohith |
last post by:
Hi all
I have a flash object im my webpage. When the close button associated with it is clicked it should automatically flows to a particular position on the screen. Again clicking on...
|
by: Lax |
last post by:
Say we have a static external object (object defined outside of any
block with static qualifier) in a file.
We are telling the compiler that we intend that object to be accessed
by functions in...
|
by: Andrej Tv |
last post by:
Hi.
I'm having troubles to come up with a way to assign an object's method to a DOM-node created by the object without hardcoding object's name.
For example:
function currancySwitcher(){
...
|
by: Rajesh Kesari |
last post by:
I have a parent form with 3 subforms- after entering data in subform 1 I want cursor to move to a control in subform 2 and likewise to sub3 afterwards; what is the best way of doing that;
I tried...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |