I'm trying to learn how to use classes but I am having a hard time trying to understand it so I tried to create a game.
I want to access my 10 players in the heap and I want to initialize the skills of each 10 players. I really don't know what I'm doing please help me. If you think the structure of my program is garbage please tell me and tell me how to properly do it. Thanks
main.cpp
int main()
{
Player *p = new Player[10];
p->createPlayer(&p,10);
}
Header file
class Player
{
public:
Player();
~Player();
int genRanNum(int);
void createPlayer(Player *, int);
private:
int plyrSkill1,plyrSkill2,plyrSkill3;
int plyrId;
};
CPP File
Player::Player()
{
}
int Player::genRanNum(int num)
{
return 1+(rand()%num);
}
void Player::createPlayer(Player *p, int si)
{
for(int i = 0; i < si; i++)
{
*p->staId = i;
*p->staSkills1 = genRanNum(10);
*p->staSkills2 = genRanNum(10);
*p->staSkills3 = genRanNum(10);
}
}