Multi-dimensional array help
Back with another question concerning my RPG. I had the idea to do a multi-dimensional array to represent a map, with each element in the array being it's own square, Depending on where you are, you can move in any of the 4 directions, unless you are on an edge. Also, I wanted to have specific squares represent towns and such.
The only problem is I'm not very good with arrays. I can initialize it, but that's about it. I just need some suggestions to get me going in the right direction.
Ellisande
Junior Poster in Training
53 posts since Jun 2008
Reputation Points: 10
Solved Threads: 2
My question is this -- are you planning on having only 2 dimensions for the map or 3 in the event that you want to do some kind of map-switch?
Just 2, a chessboard with special squares (only bigger of course)
er, now that I think about it though, is it possible to have like dungeons or something that have their own specific map layouts?
Ellisande
Junior Poster in Training
53 posts since Jun 2008
Reputation Points: 10
Solved Threads: 2
Why would you want to fill up the array with chars though?
Ellisande
Junior Poster in Training
53 posts since Jun 2008
Reputation Points: 10
Solved Threads: 2
a char will hold a single character, which is just an 8-bit int.
what information are you trying to contain in any 'square'?
this doesnt seem very meaningful, to have one char value in any square...
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
You'll have to give me more details on your program - I'm thinking that you're making a text-based RPG to be seen in the Console screen, so the first thing that came to mind were pre-placed characters from a text file.
Oh I see. Well my original intent was to start with just a basic coordinate system, with no visible map displayed on the screen. As you move, it would display what square you moved to by outputting your coordinates. And the last feature I wanted was to have certain squares be represented by towns (and eventually dungeons), so for now I want to keep it simple until I've learned more in C++.
---|---|---|---
---|---|---|---
---|---|---|---
---|x | t |---
x <- you are here. Then you're given the option to move north, east or west.
t <- town here. Step on this square and you'll get to do town things like store/inn.
Ellisande
Junior Poster in Training
53 posts since Jun 2008
Reputation Points: 10
Solved Threads: 2
Doing so with characters is your best bet unless you're using Windows API and you're forming an application.
this doesnt make any sense. what's any of this got to do with Windows API?
you've got an 8x8 matrix of single characters... what meaningful information can you have in such a thing?
you should make an 8x8 matrix of a structure that describes every important aspect of any board position.
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
Then you just want to display the numbers and maybe display the numbers of the valid locations to move to next?
In that case I really don't think you need arrays or file i/o. You just need to have predefined coordinates for places.
Yeah... actually now that I think about it, that sounds like it would work. I could do if(x=7, y=2){ type statements to represent towns, and increment/decrement x/y coordinates depending on which direction you pick.
I'm just not sure what the most efficient way to define the borders is, to make sure that the x/y coordinates won't get higher or lower than I want them to.
Ellisande
Junior Poster in Training
53 posts since Jun 2008
Reputation Points: 10
Solved Threads: 2
Okay, I think I get it now, the only question I have is what does the : x(col), y(row) - on part mean?
Ellisande
Junior Poster in Training
53 posts since Jun 2008
Reputation Points: 10
Solved Threads: 2
#include <iostream>
using namespace std;
typedef struct Location
{
int x, y;
Location(int col, int row) : x(col), y(row){}
};
Location Start(2,2);
int main(){
cout<< Location.start;
cin.get();
}
I'm doing something wrong =\
Ellisande
Junior Poster in Training
53 posts since Jun 2008
Reputation Points: 10
Solved Threads: 2
Aha! I see now, it's just as if I were using a variable in a class, except with the structure name. And the typedef struct Location is making a structure that has x,y coordinates.
With that said, it sounds like it will be simple enough to make a switch that lets you choose which direction you go, with an if inside it that checks if it is on the border or not.
Ellisande
Junior Poster in Training
53 posts since Jun 2008
Reputation Points: 10
Solved Threads: 2
Now the problem I'm having is how do I use a struct like Location Inn like you described above to give you different options depending on your location in the grid? I'm able to move around my grid from 1-10 in both the x/y directions, but that's all I've got so far.
Ellisande
Junior Poster in Training
53 posts since Jun 2008
Reputation Points: 10
Solved Threads: 2