I meant to fix issues with case sensitivity; that's a huge no-no that I started with but tried to fix. I'll look more carefully into case sensitivity. Likewise, I keep meaning to make my classes capitalized, but objects lowercase.
I'll definitely make my data private. It was mostly public because this is my first time actually working with objects and I didn't want to deal with potential errors with scope/permissions (I'll admit I took an OOP class in java that taught us about keeping stuff private, but I was a lazy student then and didn't pay attention... I vaguely know about destructors and overloading, and whatnot. Don't worry, I do regret being lazy back then). I'm definitely going to try to privitize as much as I can after I feel comfortable with my objects working properly.
As for the "unfortunately modular", I meant it in terms of a bigger hassle for readers on this website in that they have to create a project, etc. just to compile it. I did intentionally modularize it for the "good reasons" that you're thinking of, though.
I'll recode the sRand; thanks!
I'm not 100% sure if my recursion issue is what I think it is, but if you mean how the program runs infinitely with no exit, I have temporarily done that intentionally as I'm working in steps. My current idea is to playtest the basics - creating a single character with set stats, and letting him battle an infinite number of enemies, one at a time, until he dies or gets bored. I had initially playtested my battle system by letting him fight just one premade enemy and then killing the game as soon as he won. The current step is to run an infinite loop that tests stability of my objects and whether my values stay after a battle... unfortunately, that's where my problem is - the values reset. I want the warrior to remain hurt after his initial battle.
I created a test program (I do a lot of these, haha) to see if my logic with passing objects is correct, and the results suggest I'm thinking this properly:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <stdio.h>
class Variables{
private:
int variable1;
public:
void setVariable(int myNum)
{
variable1 = myNum;
}
int getVariable()
{
return variable1;
}
};
int myFunction(Variables* myVariable1);
int myFunction(Variables myVariable1); //overloaded function
int main()
{
Variables myVariable;
myVariable.setVariable(10);
printf("%d\n",myVariable.getVariable()); //should say 10 hopefully
myVariable.setVariable(myVariable.getVariable()-4);
printf("%d\n",myVariable.getVariable()); //should say 6 hopefully
myFunction(myVariable);
printf("%d\n",myVariable.getVariable()); //should still say 6 hopefully
myFunction(&myVariable);
printf("%d\n",myVariable.getVariable()); //should say 50 hopefully
}
int myFunction(Variables myVariable1)
{
myVariable1.setVariable(20);
return 0;
}
int myFunction(Variables* myVariable1)
{
myVariable1->setVariable(50);
return 0;
}
| |
The data does not "reset" when I pass by reference in this mini program, but it does in my actual game. Perchance do you know why he's healing in between fights? I noticed that in your statement about recursion (speaking of which, am I understanding correctly that you're referring to my intentional loop as the infinite recursion, or am I misunderstanding?) that you said my player goes through a "fixup"; does that mean my player is healing himself at that step? I am trying to find out where he might heal, but aside from intentionally choosing option 2 (create hero), he shouldn't get a chance to heal up.
Once I verify he keeps damage between fights, I'm going to make the fight non-recursive and give an option to exit.
Also, to anyone reading this: don't worry about the printf's. I know they must be really annoying to see in C++ code, but I'm going to get around to replacing all of them with couts. It's just that I've been doing C (regular) for years, so I am very used to printf. Heh heh.
By the way, thanks for looking into this and the advice, kbw!