Hello.
Currently I'm making a game in C++, its not my first game (Examples of what I've made is "The game of life" in both 3d and 2d, TicTacToe with my own AI algorithms (based on the graph theory), 2D Paratrooper game), however its my first programm that requires allot of parameters to be passed from function to function.
I'm quite familiar with the structured part of C++ and some other languages, however I'm not quite advanced in the object oriented\class part of the C++ language, so this might be my problem.
First thing I would like to say, I do not want to use global parameters, unless they are global constants. In my experience they ruin the code and ruin the concept of structured programming.
Usually If passing certain parameters would be required, I would just pass them by reference:
void foo(int &myvar); {}
But in this case I'm making an RPG game with a huge amount of variables, so I would have to do:
void foo(int &myvar, int &myvar2, ...., int &myvarN); {}
Sometimes, I would need to pass only one or two variables, but I can't just leave all the other variables blank.
So, I assume the best way to solve this problem is using classes, however I couldn't figure out a good way to do so. If you could share some ideas or show some examples that would be great.
Here is a more precise example:
void data() {
param1 = ...
param2 = ...
param3 = ...
....
paramN = ...
result1 = param1+param2*param3
result2 = param3*param1+param2
....
resultN = paramN-paramA+paramB
}
void func1(); {
if(foo == foo2) {
data(); /* How would I pass param1, param2 but not pass any other params? Lets say data() would be data(int a, int b, int c) its impossible to just pass a, b and not c ?*/
}
int main() {
func1();
data();
return 0;
}