Archived

This topic is now archived and is closed to further replies.

gamesmaster2

Array or Class

Recommended Posts

gamesmaster2    122
I have a lot of questions so bear with me with the post I am about to drop.But this post is about an rpg game I''m trying to do. Now what I was trying to do is to have all the elements of a character (hp, defense, attack power, exp) to be under one thing so that they can all be changed after you defeat a enemy. At first I started out with alot of cout statements (to tell the story and to have the name of the character displayed in the sentence to give it more of a personal touch) until someone said that I can acheive alot of what I wanted through an array.They also said that I can put the story in a text file and make it into a header to be accessed by the program later rather than write out the story using couts. But reading on in my book 1.I didn''t see anything in my book about how to get my program to access text files let alone making them into headers. and 2.I notice Classes could also be used (at least in theory).To put everything under one roof.Can anyone tell me which one is best for an rpg??Arrays or Classes.I hope I explained it ok .I tried to be as detailed as I could. The road to hell is paved in good intentions

Share this post


Link to post
Share on other sites
WildWest    184
I would use classes!
There are some reasonse for this:

1. you can have have a bse class e.g. "Character" fro which you can derive other characters e.g. "Warrior", "Thief"....

2. you can store all your stats in member variables

3. you can implement one methods like "ShowCharacterStats" to show all infos you want

4. many more

Hope this helps a lot!


The Wild Wild West - Desperado!

Edited by - Wildwest on February 6, 2002 6:15:26 AM

Share this post


Link to post
Share on other sites
Steveyboy    122
to include a texct file as a header:
In text.txt:
  
Hello, my name is billy boy!\n
They call me jim for some reason though.\n
etc.


In main.cpp:
  
#include "main.h"
// Other #includes...


char[] szStoryText = "
#include "text.txt"
"
;

I think :s
The compiler takes the #include statement as a copy & paste from the text file, so it thinks of the above as being combined into:
  
#include "main.h"
// Other #includes...


char[] szStoryText = "
Hello, my name is billy boy!\n
They call me jim for some reason though.\n
etc.
"
;

In this way, you can have the story in a text file, and copy it into a string (well, a char array in this case) at compile time.
Better yet would be to read the story from a text file at run-time, using file access, but that may be a bit complex if you are just starting to program.

And on tha arrays / classes front:
you should always use classes! This gets you into an object orientated way of thinking, which is a good thing for future employers, and also makes your code a LOT more manageable / readable.

HTH, Steve

Share this post


Link to post
Share on other sites
Promit    13246
structs are nice too. Although OOP is cool, dont jump to it for everything all th time.

Then again, fo a game, i lke to use inheritance, abstraction, etc.

-----------------------------
The sad thing about artificial intelligence is that it lacks artifice and therefore intelligence.

Share this post


Link to post
Share on other sites