Change Playdirection

Hi,

For my project I wanna change the playdirection.
So for example:
Im playing with 3 players (Josh, Eric, Harry). In the first round the direction is like the player-array.
After "something happend", the play direction switch so that now the player-array going backwards.

Example:
First round:

1
2
3
4
5
6
for(int i = 0; i < playersize; i++)
{   
   player[i] 
   // do smth
   // After a bool func is wrong, the array going backwards
}

Josh does smth
Eric does smth
-> Bool func for Eric is wrong
The Next Player now is Josh, then Harry.

I know, maybe its bad explaining, but would be nice if someone can help.

Greetings!

Last edited on
How about this? A little different to your original loop but easy to understand.

1
2
3
4
5
6
7
8
9
int direction = 1;
while (true)
{   
   player[i]; 
   // do smth, set the value of direction to +1 or -1
   i = i + direction;
  if (i == -1) i = playersize - 1; // wrap backwards
  if (i== playersize) i = 0;; // wrap forwards
}


This will go round and round forever, going over all the players over and over, so it's up to you to add logic to break out of the loop.
Last edited on
Thanks!
Topic archived. No new replies allowed.