 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ao the Unstoppable Guest
|
Posted: Mon Nov 29, 2004 11:03 am Post subject: Test-Based RPGs Programming |
|
|
Hi. I'm relatively new to programming, and I was wondering what the
best way to program a text-based RPG would be. Would I just use switch
statements and if statements for items? Should I divide my source code
into multiple files?
Thanks.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Chris Uzdavinis Guest
|
Posted: Tue Nov 30, 2004 10:58 am Post subject: Re: Test-Based RPGs Programming |
|
|
[email]cyanbloodbane (AT) gmail (DOT) com[/email] (Ao the Unstoppable) wrote in message news:<ba964d1e.0411281837.723c388f (AT) posting (DOT) google.com>...
| Quote: | Hi. I'm relatively new to programming, and I was wondering what the
best way to program a text-based RPG would be. Would I just use switch
statements and if statements for items? Should I divide my source code
into multiple files?
|
It could take a long time to go over a design for such a complex
program but I'd suggest that you do not use switch statements, as it
"hard codes" your options into the program and makes it very
inflexible for later changes, customization, or expansion.
Look into using abstraction, with a plug-in interface. That is, use
abstract base classes and virtual functions. Various objects should
implement a few key interfaces, and your system should work solely
with those interfaces, knowing NOTHING about how they're implemented.
That way you will be able to "install" objects into the game, without
changing the system anywhere. If your system knows about the
individual objects, then your system is limited to only work with
those objects. So do everything possible to keep knowledge about the
objects OUT of the core of the system.
I know this isn't much to get you going, but you're trying to start a
project that is not especially easy to do well.
--
Chris
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
David B. Held Guest
|
Posted: Tue Nov 30, 2004 11:09 am Post subject: Re: Test-Based RPGs Programming |
|
|
Ao the Unstoppable wrote:
| Quote: | Hi. I'm relatively new to programming, and I was wondering what the
best way to program a text-based RPG would be. Would I just use switch
statements and if statements for items? Should I divide my source code
into multiple files?
|
This isn't really relevant to C++, so you should consider looking for
any of the numerous mailing lists and bulletin boards that talk about
MUD codebases. One of the more popular is called Rom (Rivers of MUD),
and I'm sure Google will overwhelm you with references. If you get to
a reasonable level of proficiency, you should look for a mailing list
called MUD-Dev, which is where the self-professed elite MUD/MMORPG
coders and philosophers hang out.
Dave
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ben Hutchings Guest
|
Posted: Fri Dec 03, 2004 11:43 am Post subject: Re: Test-Based RPGs Programming |
|
|
Ao the Unstoppable wrote:
| Quote: | Hi. I'm relatively new to programming, and I was wondering what the
best way to program a text-based RPG would be. Would I just use switch
statements and if statements for items?
|
It would probably be better to use polymorphism. Define an abstract
item class and derive concrete item classes from that. E.g.
class item // ABC for all items
{
public:
virtual std::string description() const = 0;
virtual int value() const = 0;
...
};
class weapon : public item // ABC for weapon items
{
public:
virtual int calc_damage(const character & wielder,
const character & target) const = 0;
...
};
class axe : public weapon // concrete class for axes
{
private:
std::string description() const { return "an axe"; }
int value() const { return 100; }
int calc_damage(const character & wielder,
const character & target) const
{
return (wielder.exp_points() + rand() % 3)
/ target.armour_level();
}
...
};
class character
{
...
std::vector<boost::shared_ptr- inventory_;
...
};
The "map" of the game is probably best described through a collection
of locations. You could just have a large array or map of locations
as static data. For more flexibility you could arrange to load the
location information from a file, so that you can use different maps
without rebuilding the program.
| Quote: | Should I divide my source code into multiple files?
|
Since this is likely to be a non-trivial program, yes, absolutely.
--
Ben Hutchings
Beware of bugs in the above code;
I have only proved it correct, not tried it. - Donald Knuth
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|