Object Oriented Programming (OOP) is an immense topic and, truthfully, I’m only part way on my journey. You can start by checking out its entry on Wikipedia.
Basically, OOP uses the concepts of ‘classes’ (which you can think of as blue prints for building a house) and ‘objects’ (actual houses built from those blue prints). You can build (instantiate) as many objects from a given class as you want -- platform resources permitting. The core tenant of OOP is that you define how data objects manipulate their own internal state and interact with each other rather than writing procedures to operate on your data.
A pared-down example of how I (as an intermediate-level C++ programmer) might implement your Player concept as a class is shown below, along with Serial port output from the program.
//--------------------- Declare the Player class (blue print)---------------------
class Player {
private:
uint32_t ident;
uint8_t tIndex;
static uint8_t tIndexCounter;
public:
Player() : ident(0), tIndex(0) {}
void setIdent(uint32_t id);
uint32_t getIdent();
void setTIndex(uint8_t tI);
uint8_t getTIndex();
static bool allTurnsZero();
};
//--------------------- Define what each of the class's members do ---------------------
uint8_t Player::tIndexCounter = 0;
void Player::setIdent(uint32_t id) {
ident = id;
}
uint32_t Player::getIdent() {
return ident;
}
void Player::setTIndex(uint8_t tI) {
if ((tI == 0) && (tIndex != 0)) {
tIndexCounter--;
} else if ((tI != 0) && (tIndex == 0)) {
tIndexCounter++;
}
tIndex = tI;
}
uint8_t Player::getTIndex() {
return tIndex;
}
bool Player::allTurnsZero() {
return (tIndexCounter == 0);
}
const uint8_t numPlayers = 10;
//--------------------- Instantiate (build) objects of the class ---------------------
Player players[numPlayers];
void setup() {
Serial.begin(115200);
delay(2000);
Serial.println("Starting");
Serial.println();
for (uint8_t i = 0; i < numPlayers; i++) {
players[i].setIdent(random(1, 1000)); // Set each object's Ident
players[i].setTIndex(random(1, 25)); // Set each object's T-index
}
//--------------------- Print out the objects we've built ---------------------
for (uint8_t i = 0; i < numPlayers; i++) {
Serial.print("Player Number: ");
Serial.print(i);
Serial.print(", Player Ident: ");
Serial.print(players[i].getIdent());
Serial.print(", Player T-Index: ");
Serial.println(players[i].getTIndex());
}
Serial.println();
Serial.println();
//--------------------- Set each object's T-index back to zeero ---------------------
//--------------------- use the 'allTurnsZero() method to see when all T-indexs are zero ---------------------
for (uint8_t i = 0; i < numPlayers; i++) {
Serial.print("Setting T-Index of Player Ident ");
Serial.print(players[i].getIdent());
Serial.print(" to zero. All players finished = ");
players[i].setTIndex(0);
Serial.println(Player::allTurnsZero()? "True": "False");
}
}
void loop() {}
Starting
Player Number: 0, Player Ident: 824, Player T-Index: 2
Player Number: 1, Player Ident: 348, Player T-Index: 3
Player Number: 2, Player Ident: 185, Player T-Index: 9
Player Number: 3, Player Ident: 673, Player T-Index: 15
Player Number: 4, Player Ident: 162, Player T-Index: 14
Player Number: 5, Player Ident: 829, Player T-Index: 6
Player Number: 6, Player Ident: 763, Player T-Index: 3
Player Number: 7, Player Ident: 910, Player T-Index: 24
Player Number: 8, Player Ident: 53, Player T-Index: 2
Player Number: 9, Player Ident: 44, Player T-Index: 5
Setting T-Index of Player Ident 824 to zero. All players finished = False
Setting T-Index of Player Ident 348 to zero. All players finished = False
Setting T-Index of Player Ident 185 to zero. All players finished = False
Setting T-Index of Player Ident 673 to zero. All players finished = False
Setting T-Index of Player Ident 162 to zero. All players finished = False
Setting T-Index of Player Ident 829 to zero. All players finished = False
Setting T-Index of Player Ident 763 to zero. All players finished = False
Setting T-Index of Player Ident 910 to zero. All players finished = False
Setting T-Index of Player Ident 53 to zero. All players finished = False
Setting T-Index of Player Ident 44 to zero. All players finished = True