Sign in to follow this  

room progression(again)

This topic is 4868 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

my freind has been harping me to make a harry potter game for some time. so, I finally got sick of it and told her I would, but im lost. im using a revised version of the battle system I made for my other game called armor core arenas. my probem is, I still dont know how to make the rooms. I donwloaded the text adventure tutorial off of gametutorials, but I was lost. I am interested in using arrays, because it seems like the best choice. so, could somebody better clarify this or point me to another tutorial? edit: the game is a text adventure

Share this post


Link to post
Share on other sites
An array might not be the best data-structure for your text game. Consider making a "Space Node" with a description of itself, and pointers to a North, South, East, West "Space Node"

Something like this

* *
| |
*-*

The * represent space nodes, and the lines represent links. So in the upper left node, the player can go west, south. In the upper right node, the player can go east, south.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
this is jakpandora(really. I dont fell like signing in) I dont really know how to set up a name on aim, but my email is Mic46686@aol.com can anyone else help?

Share this post


Link to post
Share on other sites
i think using nodes is a little more difficult than using an arary.

what you need to do is create a two dimensional array, this basically creates a grid ...

for example ...
int grid[5][5];

0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0

now you can give yourself a position withen this grid (x, y)
and make numbers withen this grid coraspond to differnt rooms.

so say you are at position (2, 4)
note: arrays start at 0 not 1 ... you would be there in the grid ...

0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 X 0 0
0 0 0 0 0

you can make it so at differnt positions you get specific options on which direction to go and so on ... when you want to move you can increase your x position and or your y position ... here is an example ...



#include <iostream>
using namespace std;

void room_type_1 (int &x, int &y)
{
char d;
cout << "you can move in any direction" << endl;
cout << "which direction do you want to go? (N, S, W, E): ";
cin >> d;
if (d == 'n') y --;
if (d == 's') y ++;
if (d == 'w') x --;
if (d == 'e') x ++;
}

void room_type_2 (int &x, int &y)
{
char d;
cout << "you can move north and south" << endl;
cout << "which direction do you want to go? (N, S): ";
cin >> d;
if (d == 'n') y --;
if (d == 's') y ++;
}

int main ()
{
int grid[5][5] = {
{ 1, 1, 1, 1, 1 },
{ 1, 1, 2, 1, 2 },
{ 1, 1, 1, 1, 1 },
{ 1, 1, 2, 1, 2 },
{ 1, 1, 2, 1, 2 }
};
int x = 2;
int y = 3;
bool done = false;
do
{
cout << "x: " << x << endl;
cout << "y: " << y << endl;
if (grid[x][y] == 1)
room_type_1 (x, y);
else if (grid[x][y] == 2)
room_type_2 (x, y);
} while (!done);
return 0;
}





i hope this helps you ... also make sure you dont let your x and y positions go below 0 or over the max ...

Share this post


Link to post
Share on other sites
What I did was make a one-dimensional array of structs- a struct for each room which included the desription and where all the directions lead (as ints storing array indeces of other rooms, or -1 for walls). It's basically a linked structure like Onemind described, except implemented using a one-dimensional array. This method is very simple to code, but you need to map out the rooms and assign them numbers ahead of time. Also you can't create rooms at runtime. You can however link rooms together at run time.

By the way, I like the sound of "Harry Potter: Armor Core Arenas" for the title :).

Share this post


Link to post
Share on other sites

This topic is 4868 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this