Array or Class

Started by
2 comments, last by gamesmaster2 22 years, 2 months ago
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
The road to hell is paved in good intentions
Advertisement
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
The Wild Wild West - Desperado!
to include a texct file as a header:
In text.txt:
  Hello, my name is billy boy!\nThey call me jim for some reason though.\netc.  


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!\nThey call me jim for some reason though.\netc.";  

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
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.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.

This topic is closed to new replies.

Advertisement