Reputation: 3
I am working on programming a small game in c++, but I have a problem with how to give the role to the players. For example, I have four players. The role will start in the first player, and when it reaches the fourth player, the role must return to the first player. Also, in other stages of the game, the role can stop at the third player and then return the role to the second, and so on. Like you are in a circular ring. Is there a way to write the code? I try with this way, but it is not well effective
int i=0;
void AnzahlderPlayers()
{
if (i < 3)
{
i++;
}
else {
i = 0;
}
}
Upvotes: 0
Views: 30
Reputation: 1297
I think what you are looking for is a way to reset i to 0 when it reaches four
The way to do that is:
int i = 0;
void AnzahlderPlayers() {
i = (i+1)%4;
}
Upvotes: 0