This is a small idea of how you might join a number of rooms together
http://cboard.cprogramming.com/showt...&highlight=RPG
For each "door" ( int next[4]; ), you could add a number of properties, say
Code:
enum {
DOOR_NORMAL,
DOOR_MAGIC_BLOCKED, // needs a spell to remove the magic
DOOR_TRAP, // takes you to a random place
}
So for example, where you would previously do this
[code]room_num = rooms[room_num].next[SOUTH];]/code]
You would then have
Code:
if ( rooms[room_num].door_type[SOUTH] == DOOR_MAGIC_BLOCKED ) {
printf( "The way is magically blocked!\n" );
else if ( rooms[room_num].door_type[SOUTH] == DOOR_TRAP ) {
room_num = rand() % MAX_ROOMS;
} else {
room_num = rooms[room_num].next[SOUTH];
}
In your spell casting code, you'd have
Code:
rooms[room_num].door_type[SOUTH] = DOOR_NORMAL;
To each room, add
- a list of objects you can use
- a list of characters you can interact with
Objects would be broken down into major and minor types
Major types: weapons, armour, spells, potions, keys, amulets, ...
Minor types: sword, axe, bow, ...
Each major type has attributes say damage, range, accuracy. Use these to decide how much damage is done to an opponents.
Eg. sword has high damage and low accuracy, a bow has low damage and high accuracy.
So an example attack with a bow might read
You shoot and hit the ogre
You shoot and hit the ogre
You shoot and miss, the ogre draws nearer
You shoot and hit the ogre
You shoot and hit the ogre
You shoot and hit the ogre, the ogre is dead!
Whereas with a sword, it might read (because of the low accuracy, and close range)
You swing and miss the ogre, the ogre hits you
You swing and miss the ogre, the ogre hits you
You swing and miss the ogre, the ogre hits you
You swing and miss the ogre, the ogre hits you
You strike a solid blow and the ogre is no more!
Characters can be categorised as friendly, neutral or hostile. Friendly characters will tell you things, give you things, and perhaps help you in battles.
The whole point is to make sure you design the appropriate data structures. As you can see from my original example, all of the information is in the rooms array (which can be read from a file at runtime). All the code knows is how to get from room to room (in essence, a simple assignment).
Code:
direction = whichDirection(); // ask which direction to move in
room_num = rooms[room_num].next[direction];
printf( "You are in the %s\n", rooms[room_num].name );
Make a small program around that, and just practice walking around the small map provided.