ios - Loop an Array in order and repeat -
i creating local multiplayer text based game involve unlimited number of players. have created array hold players names inputed user on launch of app. having problems trying work out how display array index index , repeat on self such as
player 1 turn
player 2 turn
player 1 turn
player 2 turn
player 1 turn
and forth until questions have been asked (think of quiz game)
so far have come not doing job
int i; int count; (i = 0, count = [_players count]; < count; = + 1) { nsstring *element = [_players objectatindex:i]; self.turnlabel.text =( i, element); nslog(@"the element @ index %d in array is: %@", i, element); }
previously when working without , array used simple if statement checked value of string , counted how many times been shown , added , and if value less previous string app determined other players turn. working array cant seem work out how this.
basically how go showing each index in array in turn , repeating until game ends?
edit game ends when runs out of questions generating plist.
each player take in turns player 1 player 2 player 3 , player 1 , player 2 , forth. asked 1 question @ time.
sorry in advance if basic question i'm very new xcode first week now.
what want hold reference current player. loop through questions. if player gets them correct, continue next question, if player gets wrong, increment player reference. check when increment player see if it's necessary go player #1.
so, example:
nsarray *playerarray = @[@"player 1", @"player 2", @"player 3"]; nsuinteger currentplayerindex = 1;
player has turn, if gets incorrect,
currentplayerindex++;
then check:
if (curentplayerindex >= playerarray.count) { currentplayerindex = 0; }
hope helps.
Comments
Post a Comment