I'm just going to go ahead and admit it, this is a homework problem. Please, please, please don't just write the answer. I do want to learn how to do this but I'm stumped.
I'm supposed to be making a maze with these symbols:
. empty spot
0 an item (can be picked up or put down)
^ NORTH
v SOUTH
< WEST
> EAST
@ mover and item in the same spot
and if the mover has passed that spot, it's replaced with a " "
I think I've got making the 2d grid but I'm really stumped on the mover. How am I supposed to store it and how to make it move? I thought I could use a switch statement to associate north, west, south, and east to their respective symbols but I just can't seem to piece it all together.
Here's what I have so far but I can't seem to move forward or understand fully without understanding the mover. I think everything will fall in place afterwards.
this is the header
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include <iostream>
#include <cstdlib>
using namespace std;
#define WALL '#'
#define PATH '.'
#define FREE ' '
#define ITEM '0'
#define NORTH '^'
#define SOUTH 'v'
#define WEST '<'
#define EAST '>'
class Maze
{
public:
Maze(); //makes a 1 col and 1 row grid with an EAST marker
Maze(int r, int c); //makes a grid with a random r and c
Maze (int r, int c, int mr, int mc, int d); //makes a grid with a random r, c, mr (mover's row), mc (mover's column), and d (direction)
bool Move(int s); //moves s spaces
void Display() const;
void Grow(int gr, int gc); //grow grid by gr (rows) and gc (column)
char GetMover();
private:
char maze[40][40];
char Dir;
int rows, columns;
|
and this is the cpp file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#include "maze.h"
Maze::Maze()
{
char maze[1][1] = { '>' );
}
Maze::Maze(int r, int c)
{
if (r < 0 || c < 0)
{
maze[1][1];
}
if (r > 40 || c > 40);
{
maze[40][40];
}
if (r > 1 && r < 40 || c > 1 && c < 40)
{
maze[r][c];
rows = r;
cols = c;
}
}
char Maze::GetMover()
{
switch(Dir)
{
case NORTH: return '^';
case WEST: return '<';
case SOUTH: return 'v';
case EAST: return '>';
default: return 0;
}
}
void Maze::Display() const
{
cout << "The Maze:" << endl;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
if (i == 0 || i == rows - 1)
cout << WALL << ' ';
else if (j == 0 || j == cols - 1)
cout << WALL << ' ';
else
cout << PATH << ' ';
}
cout<< endl;
}
}
|
Again, if I need help on something else I'll ask but I really want to focus on the mover since I think it might clear a few blocks. Thank you!