What are the things...?

Started by
1 comment, last by virus3355 21 years, 1 month ago
What are the things I would need to know about in order to make the following: I want to make a health system... Max Health would be 10. Player(User) vs. Creature(Comp) A random attack damage generator. (1-10) Then have the Damage subtracted from the health. Replace Health value (10) with new value. (10 - dmg = New Value) All the way until someones health is 0 or negatives if that should occur. All the while displaying how much damage has been dealt to player or creature. Finally, what i want to know about making this, is what things would i need to know? ex. Functions, Arrays, etc... btw, im using C++ Thanks
Advertisement
All you really need is a single variable for the player or creature called ''health'' and a random number generator to choose the level of damage. Check out the rand() and srand() documentation for random number info. To monitor the health of a creature or player, just set the default value of the health variable to 10 and then subtract the amount of damage that is created by the random number generator. To show the health value for any creature or player, just print the value in the health variable for that creature. Hope this helps.
"Do or do not, there is no try." -- Yoda
I like object oriented stuff, myself, so I would throw all of that stuff into a class. Maybe two, unless you know how to do inheritence (which I don''t); one for the player, and another for the monster.

Your cPlayer class would have a variable for health, and then maybe a method called dealDamage(int low, int high), which would allow you to generate a minimum and maximum damage (assuming damage is totally random). You could then query the unit to find out if it''s alive, with something like bool isAlive, which would return true if health>0. Finally, either in the dealDamage() method, or even better, in it''s own function, you would have something like displayDamage(int damageAmount), which would simply cout<< (or however you''re doing text output) to the screen.

As far as randomization goes, yeah, check rand() and srand() as cshireman suggested. Remember, before you can generate a random number, you need to seed it with some number, through srand(). Most of the time I have seen it, srand is seeded:

srand(time(NULL)); //or something like that

Sounds like it would be really easy to implement. I really think OO is the way to go

Peon
Peon

This topic is closed to new replies.

Advertisement