So, I'm creating a small text-adventure game to sharpen my skills and get me out of my comfort zone, but I'm stuck on how to accomplish something. The way I have it setup so far is there will be multiple 10x10 maps represents areas such as a forest, house, etc. with each index being a map_tile with exits, descriptions, items, etc. How could I get the player to move from for example, exit one map object at map[1][3] and enter the castle map[3][9]? I don't need code ( it might be helpful though ) just ideas!
Would this be a bad way to do it? These are two different classes, but the actor class is dependent on the information of the map. Would this be considered bad programming practice?
#ifndef ACTOR_H
#define ACTOR_H
#include "Map_Segment.h" // So we can hold the current map we are on
#include <iostream>
class Actor
{
public:
Actor();
void set_coordinates(constint x, constint y);
int get_x();
int get_y();
void move_north();
void move_east();
void move_south();
void move_west();
private:
int xCoord, yCoord;
Map_Segment *currentMap; // pointer to the current map we are dealing with
};
#endif
That was just an example, at certain places in the map, you will go from one area to another. For instance if there was a castle door at forest[0][0], and the user goes inside castle, the map will change castle[5][4], so of course I will change the coordinates. I do like your suggestion coder777. I might try to wrap my head around that and implement it.
I suggest that you put all information regarding the gate in this struct that does not change throughout the whole program processing. Then make a global accessible const array [put it in a header]. There is no problem accessing constants from everywhere.
By the way: You certainly need more startup info for your game. Make them all const and global accessible. Accessing a constant object is always ok.