Hey guys, wondering if some can help me (im sure you guys will be able)
So im starting to make a C++ RPG, and i need some clarity.
iv started out the battle function like so
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
|
//Enemies.h --
struct Creature_Snake{
unsigned HP = 10;
unsigned ATK = 1;
unsigned DEF = 1;
...
...
};
struct Creature_Snail{
unsigned HP = 20;
unsigned ATK = 1;
unsigned DEF = 6;
...
...
};
//Functions.cpp --
...
Battle(Creature_Snake){
//Enter battle with a snake
}
Battle(Creature_Snail){
//Enter battle with a snail
}
|
So i was wondering how i would go about only having ONE battle function that would work properly no matter what the enemy was. That way i culd give all the enemies base stats in my "Enemies.h" and then send them all to a single function
I want something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
//Enemies.h --
Creature Snake{
//level one Stats
}
Creature Snail{
//level one Stats
}
//Functions.cpp --
Battle(Creature enemy)
{
//Enter battle with an enemy
}
|
I feel like the answer is right under my fingertips, but i have never gotten to the point in my C++ exercises that i would make a class that had the properties of another class.
Or a class within a class.... idk how to even word it.
ANOTHER thing (Please dont answer this without looking at my previous problem)
A small tedious thing about ints.
I want to figure out how many numbers are in an integer without jumping through too many hoops.
EX:
How would i go about simplifying this code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
...
...
unsigned i = 0 , number = 0;
std::cin >> i;
//Digits 0-9 (only 1 number)
if(i < 10)
number = 1;
if(i >9 && i < 100)
number = 2;
if(i > 99 && i < 1000)
number = 3;
...
...
...
std::cout << "There are " << number << " numbers in the digit " << i <<std::endl
|
Thank you in advanced my experienced idols ^_^