Help needed with code.

Discussion in 'iOS Programming' started by Jeremy1026, Aug 4, 2008.

  1. macrumors 68000

    Joined:
    Nov 3, 2007
    #1
    Sorry for the incredibly un-descriptive title, but I don't even know what's wrong.

    I am trying to make it so that when a peg is selected it disappears, if there are 20 pegs on the board (pegsLeft.) Then if there aren't 20 pegs left on the board I want to application to show possible peg moves. I can get the peg to remove when selected with the board full, but that is it. Can someone diagnose whats wrong with my code...

    Code:
    -(IBAction)moveCrossPeg1 {
    	if (pegsLeft == 20) {
    		crossPeg1.hidden = YES;
    		crossPeg1.enabled = NO;
    		pegsLeft = pegsLeft - 1;
    		pegsLeftLabel.text = [NSString stringWithFormat:@"Pegs Remaining: %i",pegsLeft];
    	}
    	if ((pegsLeft < 20) && (crossPeg7.enabled == NO) && (crossPeg3.enabled == YES)) {
    		crossPeg7.enabled = YES;
    		crossPeg7Choose = YES;
    		UIImage *editPeg = [UIImage imageNamed:@"editpeg.png"];
    		[crossPeg7 setImage:editPeg forState:UIControlStateNormal];
    		[editPeg release];
    	}
    } 
    	
    -(IBAction)moveCrossPeg7 {
    		if (pegsLeft == 20) {
    			crossPeg7.hidden = YES;
    			crossPeg7.enabled = NO;
    			pegsLeft = pegsLeft - 1;
    			pegsLeftLabel.text = [NSString stringWithFormat:@"Pegs Remaining: %i",pegsLeft];
    		}
    		if ((pegsLeft < 20) && (crossPeg1.enabled == NO) && (crossPeg3.enabled == YES)) {
    			crossPeg1.enabled = YES;
    			crossPeg1Choose = YES;
    			UIImage *editPeg = [UIImage imageNamed:@"editpeg.png"];
    			[crossPeg1 setImage:editPeg forState:UIControlStateNormal];
    			[editPeg release];
    			[self goToCross];
    		}
    }
    
     
  2. macrumors newbie

    Joined:
    Jul 8, 2008
    #2
    what's going on with crossPeg3? If it's not enabled, nothing will happen when you have fewer than 20 pegs.
     
  3. macrumors regular

    Joined:
    Jul 12, 2008
    #3
    Am i really the only one who likes to put comprehensive commenting in my code?

    lol....
     

Share This Page