should i do it this way?(C++)

Started by
14 comments, last by pulpfist 18 years, 4 months ago
I was just wondering, (I have thought and thought and I cannot seem to figure out how to do this properly)I am trying to make a simple txt game and I was thinking maybe I should set a variable for every area and then when that variable = true then i set the old room to false and I just let the player carry on from there. A few problems, 1) I should use pointers for this? 2) Is this the way to do it, or am I just a moron? I just want to start out with like a game with 1 wepon 1 thing of armor like 3 rooms, a couple of enemys, and that would set me good for now. But I cannot even achieve such a small feat as this. I need help! Thanks, death
Advertisement
im still fairly new at this too but here is how it somes to mind for me and i may be wrong. i would create an array of room structs or classes. then have a variable in the class or struct that is a boolean value or a global var that holds the index number of the current roon in the array.

like this
ROOM rooms[5]; // array of 5 rooms 0 = foyer 1 = kitchen 2 = blah blah
int current_room = 0; // set the current room to 0 element or the foyer ..

this may not be the way to do it but its a suggestion.

Good luck
"choices always were a problem for you......" Maynard James Keenan
I think you could use an array to have a map.

//this gives you nine roomsbool rooms[3][3];int playerposx;int playerposy;//check to make sure that the current players position is set to true.if (rooms[playerposx][playerposy] = false)rooms[playerposx][playerposy] = true;//you could also set the previous player position to false//when you set the current one to true just have variables//for the previous positions as well.
Gor435 - My Journal - MySpace - Facebook
//check to make sure that the current players position is set to true.
if (rooms[playerposx][playerposy] = false)
rooms[playerposx][playerposy] = true;


im not quite sure I understand this..?
I agree with the array/map ideas.
By the way, are you familiar with concepts like classes, functions, arrays,
not to mention the game-loop?

EDIT:
if (rooms[playerposx][playerposy] = false)
if (rooms[playerposx][playerposy] == false)

These lines has very different effect ^^
here is something i just did .. again im havent done anything like this but its a start ...

in this map rooms are joined by '|' or '-' .
for example you get to room 4 from room 0 or room 5 but not from 7 or 3.

/*
[6]-[7]-[8]
| |
[3] [4]-[5]
| | |
[1]-[0]-[2]

*/

struct ROOM
{
char name[10];
char description[30];
int ID;
int north; // holds the element or id # of the room to the north
int south; // holds the element or id # of the room to the south
int west; // west
int east; // east
};


something like this maybe? you can add functionality for items and enemies to be inside.

*doh my map didnt come out the way i had it so it may not make much sense now lol
"choices always were a problem for you......" Maynard James Keenan
Quote:Original post by pulpfist
I agree with the array/map ideas.
By the way, are you familiar with concepts like classes, functions, arrays,
not to mention the game-loop?

EDIT:
if (rooms[playerposx][playerposy] = false)
if (rooms[playerposx][playerposy] == false)

These lines has very different effect ^^


classes no, functions some, arrays no, game loop yes :)

I understand the difference, the first one sets whatever said to be true, while the second one checks to see if what said b4 is true.

i.e.

alive = true;

if (alive == true) {
cout<<"You are alive\n";
} else{
cout<<"you are dead.\n";
}

just an example, i know i didnt delcare the variable or anything but thats the jist of it. (Just trying to show you I understand :) )
Quote:Original post by rherm23
here is something i just did .. again im havent done anything like this but its a start ...

in this map rooms are joined by '|' or '-' .
for example you get to room 4 from room 0 or room 5 but not from 7 or 3.

/*
[6]-[7]-[8]
| |
[3] [4]-[5]
| | |
[1]-[0]-[2]

*/

struct ROOM
{
char name[10];
char description[30];
int ID;
int north; // holds the element or id # of the room to the north
int south; // holds the element or id # of the room to the south
int west; // west
int east; // east
};


something like this maybe? you can add functionality for items and enemies to be inside.

*doh my map didnt come out the way i had it so it may not make much sense now lol



ok but how do i link the fact that i go north to get from a to b etc..?

ex how does the program know that I may get to 3 from 1 but not 5 to 6?
I dont want to "dictate" your game design, but as a small example to get started:

ROOM rooms[5][5];int player_row=2, player_col=2;int main(){  while(running)  {    if(keydown['s']          if(player_row < 4)        player_row++;  ...  }    return 0;}


Something like this will let you take one step at the time in four different directions.

This is only pseudo code, maybe its better if you show what you got so far...
this is for linking rooms

you have a room struct i gave earlier .. and a map.

we will initialize room 0 in our array of rooms for an example...

int current_room = 0;

ROOM house[9]; // 9 rooms in our house
house[0].name = "entry";
house[0].description = "a small entry";
house[0].north = 4;
house[0].south = -1; // no room to the south
house[0].east = 2;
house[0].west = 1;
.... do this for all your rooms in the array so house[1] and so on

then to check if the next room is open to the player...
lets say that the button for north was hit and the player wants to go north

if(house[current_room].north != -1)
{
current_room = house[current_room].north;
}
else
{
cout << "There is no door that way." << endl;
}

hope that cleared up some of my mess heh. like i said i just started this stuff when i read your post and someone else might have a better solution.

[Edited by - rherm23 on December 19, 2005 2:52:13 PM]
"choices always were a problem for you......" Maynard James Keenan

This topic is closed to new replies.

Advertisement