Winner Calculation troubles

Discussion in 'iOS Programming' started by HarryWorksInc, Mar 23, 2010.

  1. HarryWorksInc macrumors regular

    Joined:
    Feb 21, 2010
    #1
    I have a game in which the players will go one after the other and then the view will quit and go to a different view, currently i have coded as so
    HTML:
    	int winner1;
    	int winner2;
    	int winner1S;
    	int winner2S;
    	int winner;
    	
    	if (Player1Score < Player2Score) {
    		winner1=1;
    		winner1S=Player1Score;
    	} else {
    		winner1=2;
    		winner1S=Player2Score;
    	}
    	if (Player3Score < Player4Score) {
    		winner2=3;
    		winner2S=Player3Score;
    	} else {
    		winner2=4;
    		winner2S=Player4Score;
    	}
    	if (winner2S < winner1S) {
    		winner=winner2;
    	} else {
    		winner=winner1;
    	}
    	
    	NSString *winnerstring = [[NSString alloc] initWithFormat:@"%d", winner];
    	[[NSUserDefaults standardUserDefaults] setObject:winnerstring forKey:@"CCW"];
    	[self.delegate CreatureCaptureDidFinish:self];
    This doesn't seem to be working. If anyone knows of a way I can simply organize the scores into highest to lowest I would be very grateful.
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Create an object class that represents each player and holds, at least, their index and score. Create instances of this class for each player. Store them in an array. Sort the array using one of NSArray's sorting instance methods.
     
  3. HarryWorksInc thread starter macrumors regular

    Joined:
    Feb 21, 2010

Share This Page