In your code you have the line:
char race[6];
this should be:
char race[7];"
Since you have several race names longer then 5 chars:
Goblin
Faerie
Dragon
and you need 1 char for the ''/0''
Hope this helps.
Text RPG
NoirRaven, thanks a bunch; I added 1 to the length of the variables storing the character's race and class, and it works great now. It's hard being a newbie. I am very successful in VB, but I'm just starting out in C++. BTW, I know goto is bad form. I'll change it to loops soon enough, but I just want to get a working product first. Is there any other bad form in my source.
One thing, I didn't use void procedures (or whatever they're called) because I heard they're bad form. Is this right? because it would be more efficient if I used voids for some things.
BTW, is my story a bit better now?
[edited by - gamechampionx on May 22, 2002 9:01:41 PM]
One thing, I didn't use void procedures (or whatever they're called) because I heard they're bad form. Is this right? because it would be more efficient if I used voids for some things.
BTW, is my story a bit better now?
[edited by - gamechampionx on May 22, 2002 9:01:41 PM]
Check out Drunken Brawl at http://www.angelfire.com/games6/drunken_brawl!
Glad I could Help.
I was not the person who commented on using goto, though you should avoid them even to "get things going" because once you start to remove them you have to rethink the flow of logic to match the new control structure, and that will lead to the hell of debugging...
As for the story, who cares what the story is, at this time the point of what you are doing is to learn how to program in C++ and make a game, and if I remember correctly both DOOM and Tetris had no stories (ok DOOM had "a portal to hell was opened and all your buddies were turned to zombies, here is a shotgun...have fun",) and no one complained to much, so don''t be hindered by a "lame" story or writers block. I do think it was a good idea to remove the "press a key to continue" parts, the player should never have to do something for no reason.
Have fun and good luck.
I was not the person who commented on using goto, though you should avoid them even to "get things going" because once you start to remove them you have to rethink the flow of logic to match the new control structure, and that will lead to the hell of debugging...
As for the story, who cares what the story is, at this time the point of what you are doing is to learn how to program in C++ and make a game, and if I remember correctly both DOOM and Tetris had no stories (ok DOOM had "a portal to hell was opened and all your buddies were turned to zombies, here is a shotgun...have fun",) and no one complained to much, so don''t be hindered by a "lame" story or writers block. I do think it was a good idea to remove the "press a key to continue" parts, the player should never have to do something for no reason.
Have fun and good luck.
I would suggest you add a method to Character to adjust stats.
You could set up the setRace method to work like the setClass method (taking type as a parameter and using that to determine stats) or you could use the other method for both (passing all the stats as arguments), figured i'd give an example of each. Anyways, at the very least, this will save you about 50 lines of code.
Also use tolower() on y/n arguements. saves you from having to check y Y n N, so you can just do y or n.
Finally, continue like you are for learning purposes, but if you keep going with this procedural style you're eventually gonne hit a giant brick wall that will be hard to hack through to actually get any kind of gameplay in.
[My site|SGI STL|Bjarne FAQ|C++ FAQ Lite|MSDN|Jargon]
Ripped off from various people
[edited by - wild_pointer on May 23, 2002 2:34:02 PM]
struct Character{ int maxmana, maxhp, strength, defense, magic, agility; int mana, hp; int damage; int damageestimate[2]; float battleinterval; char name[20]; char race[7]; char characterclass[14];void setRace( int str, int def, int mag, int agil, char* spec ){ strength = str; defense = def; mag = magic; agil = agil; strcpy( race, spec )}void setClass( char* cl ){ if( strcmp( cl, "Blood Mage" ) == 0 ) { strength += 20; magic += 20; defense += 20; agility += 20 } if( strcmp( cl, "Thief" ) == 0 ) { ... } ...}};
You could set up the setRace method to work like the setClass method (taking type as a parameter and using that to determine stats) or you could use the other method for both (passing all the stats as arguments), figured i'd give an example of each. Anyways, at the very least, this will save you about 50 lines of code.
Also use tolower() on y/n arguements. saves you from having to check y Y n N, so you can just do y or n.
Finally, continue like you are for learning purposes, but if you keep going with this procedural style you're eventually gonne hit a giant brick wall that will be hard to hack through to actually get any kind of gameplay in.
[My site|SGI STL|Bjarne FAQ|C++ FAQ Lite|MSDN|Jargon]
Ripped off from various people
[edited by - wild_pointer on May 23, 2002 2:34:02 PM]
[size=2]
I''m getting rid of "goto"s. Just wondering if I could do something like:
if (blah blah)
{
exit this stupid loop;
}
If so, what''s the word you use to exit?
if (blah blah)
{
exit this stupid loop;
}
If so, what''s the word you use to exit?
Check out Drunken Brawl at http://www.angelfire.com/games6/drunken_brawl!
quote: Original post by gamechampionx
I'm getting rid of "goto"s. Just wondering if I could do something like:
if (blah blah)
{
exit this stupid loop;
}
If so, what's the word you use to exit?
That's not a loop . The two keywords are 'return' and 'break'. You use return to jump out of a function - if it expects a return value, then you have to have something following the return of the correct type.
You can use break to jump out of a loop: e.g.
for ( ; ; ){ if (some condition) break; // jumps outside of loop here}
The if statement isn't a loop and will only get executed once.
EDIT: many people frown on using break except in some circumstances (e.g. infinite loop). The usual practise is to use variables, e.g.
bool bDone = false;do{ // something if (some condition) bDone = true;}while (bDone == false);
EDIT 2: ...or, of course, you can avoid that bool entirely if you want...
do{ // something} while (!some_condition);
[edited by - Alimonster on May 23, 2002 9:44:34 PM]
[edited by - Alimonster on May 23, 2002 9:47:27 PM]
Yea, if statements check to see if a condition is true, and then execute a set of instructions only one (so it''s not a loop). For is an example of a loop, as stated above; another are the while and do/while loops. I usually use return to break out of a loop.
Also, another time I see break used a lot is in switch/case structures.
Also, another time I see break used a lot is in switch/case structures.
Peon
theres also continue , which will jump back to the top of the loop instead of exiting it like break does.
what i suggest you do is make a Console class that wraps up various functions you might use. if making a win32 console app, then look up the win32consoleApi, which is a set of nifty functions used to manipulate the win32 console. it lets you do alot of cool stuff, like change text and fill colors, and work with buffers, and events. there are win32 console demos on msdn.
what i suggest you do is make a Console class that wraps up various functions you might use. if making a win32 console app, then look up the win32consoleApi, which is a set of nifty functions used to manipulate the win32 console. it lets you do alot of cool stuff, like change text and fill colors, and work with buffers, and events. there are win32 console demos on msdn.
I''ve been working on a text RPG for ages now - it''ll go to graphics as soon as I learn that... but your code could seriously do with some optimisation - But I''ll leave that for you to learn about that''s what''s so great about programming...
Anyway, if you need any help, email me at byssian_taros@hotmail.com . I''m by no means the best programmer around, but I''ve been doing a text RPG for so long, I know quite a bit about how to make them work nicely...
Anyway, if you need any help, email me at byssian_taros@hotmail.com . I''m by no means the best programmer around, but I''ve been doing a text RPG for so long, I know quite a bit about how to make them work nicely...
Use char pointers or string.
IE,
IE,
#include <string>//Dont add .h or else Olusyi will have your headstring name; //Your name! Easy huh?int main(){ ...}
---START GEEK CODE BLOCK---GCS/M/S dpu s:+ a---- C++ UL(+) P(++) L+(+) E--- W++ N+ o K w(--) !O !M !V PS- PE+Y+ PGP+ t 5 X-- R tv+ b+ DI+ D G e* h! r-- !x ---END GEEK CODE BLOCK---
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement