Hello all I am trying to make a code for a game that I want to make as of right now I am kinda stuck on classes and wanted use the list initialization to make it easier for to enter the players attributes here is my class below this is part of my main code as I did not want to make a header or another .cpp file yet.
class Player {
public:
string name;
int id;
int height;
double closeshot;
double midshot;
double threeshot;
double dribble;
double defense;
double jump;
Player() {};
Player(string a, int b, int c, double d, double e, double f, double g, double h, double i);
}pg1,pg2,sg1,sg2;
Player::Player(string a, int b, int c, double d, double e, double f, double g, double h, double i) {
name = a;
id = b;
height = c;
closeshot = d;
midshot = e;
threeshot = f;
dribble = g;
defense = h;
jump = i;
}
Here is my player initiliaztion list below.
Player pg1( "Player1Home", 1, 61, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00 );
Player pg2( "Player1Away", 6, 72, 10.00, 10.00, 10.00, 10.00, 10.00, 15.00 );
Player sg1( "Player2Home", 2, 61, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00 );
Player sg2( "Player2Away", 7, 71, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00 );
Any help would be appreciate im still relatively new at this.
So I decided to just go back to structs as they are just easier to work with
struct Player {
string name;
int id;
int height;
double closeshot;
double midshot;
double threeshot;
double dribble;
double defense;
double jump;
}pg1,pg2,sg1,sg2;
And this is how I added in my values
pg1.name = "Player1Home";
pg1.id = 1;
pg1.height = 61;
pg1.closeshot = 10.00;
pg1.midshot = 10.00;
pg1.threeshot = 10.00;
pg1.dribble = 10.00;
pg1.defense = 10.00;
pg1.jump = 10.00;
pg2.name = "Player1Away";
pg2.id = 6;
pg2.height = 61;
pg2.closeshot = 10.00;
pg2.midshot = 10.00;
pg2.threeshot = 10.00;
pg2.dribble = 10.00;
pg2.defense = 10.00;
pg2.jump = 10.00;
sg1.name = "Player2Home";
sg1.id = 2;
sg1.height = 61;
sg1.closeshot = 10.00;
sg1.midshot = 10.00;
sg1.threeshot = 10.00;
sg1.dribble = 10.00;
sg1.defense = 10.00;
sg1.jump = 10.00;
sg2.name = "Player2Away";
sg2.id = 7;
sg2.height = 61;
sg2.closeshot = 10.00;
sg2.midshot = 10.00;
sg2.threeshot = 10.00;
sg2.dribble = 10.00;
sg2.defense = 10.00;
sg2.jump = 10.00;
The rest of my code just works better when I leave it this way.