Design issue - please help

I am creating a text adventure. There is a player class, and a map class. I will create many objects of class map, each one contains a 5 by 5 two-dimensional array for navigating a map. My question is, with what I have thus far, at the point where I want my player to say... move through a door, that takes him to the next map object, how can I accomplish that, and what would the code look like, again using what I have thus far?

If you can answer this I will worship you for life. Thank you so much for your time.

My files.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef GAME_AREA_H
#define GAME_AREA_H
#include <iostream>

class game_area
{
	public:
		
		game_area(const std::string file);
		static const int boardLimit = 5;
		
		void display();//DEBUGGING FUNCTION
		
		
	private:
		
		std::string area[boardLimit][boardLimit];
		
		
};

#endif 

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
#include "game_area.h"
#include <iostream>
#include <fstream>

game_area::game_area(const std::string file)
{
	std::ifstream load_map( file.c_str() );
	if ( load_map.fail() )
	{
		std::cout << "An error occured while trying to open file '" << file << "'." << std::endl;
	}
	else
	{
		for ( int x = 0; x < boardLimit; x++ )
		{
			for ( int y = 0; y < boardLimit; y++ )
			{
				load_map >> area[x][y];
			}
		}		
	}
}

void game_area::display()//DEBUGGING FUNCTION
{
			for ( int x = 0; x < boardLimit; x++ )
		{
			for ( int y = 0; y < boardLimit; y++ )
			{
				std::cout <<  area[x][y] << " ";
			}
			std::cout << std::endl;
		}
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#ifndef PLAYER_H
#define PLAYER_H
#include "game_area.h"
#include <iostream>

class player
{
	public:
		player();
		void updateLocation();
		
	private:
		int xCoord, yCoord;
		std::string currentLocation, lastLocation;
		static const int north = -1, west = -1, east = 1, south = 1;
};

#endif 

1
2
3
4
5
6
7
8
#include "player.h"
#include "game_area.h"
#include <iostream>

player::player()
{
	
}
Last edited on
Yea and the duplicate was resolved lol.. oh well. :)
Topic archived. No new replies allowed.