ios - How to block score to not go below zero? -
i'm making word game can't figure out how make 0 final point in basic scoring i've created. user must not exceed minus in or score, lowest score can zero...
- (ibaction)btncheck:(id)sender { nsstring *answer = [_textbox.text stringbyreplacingoccurrencesofstring:@" " withstring:@""] if([answer isequaltostring:@""]){ } else if ([answer isequaltostring:@"q"]) { // string correct, resign keyboard _keyboard.hidden = yes; _textxclear.hidden = yes; //perfect button [_closeone sethidden:no]; [_wrongone sethidden:yes]; score = score +100; [scorelabel settext:[nsstring stringwithformat:@"score: %d", score]]; coins = coins +5; [coinslabel settext:[nsstring stringwithformat:@"%d", coins]]; } else { [_wrongone sethidden:no]; score = score -5 ; [scorelabel settext:[nsstring stringwithformat:@"score: %d", score]]; closeonechange.text = @"correct!"; }
oh , if score becomes 0 user must receive 1 coin.
how this?
just use max
score = max(0, score - 5);
Comments
Post a Comment