ios - whats the proper way to add up coins and scores? -
whats proper way, i've been using if statements way set wrong believe because scores , coins not being added whole number being replaced if statements...
example:
- (ibaction)btncheck:(id)sender { nsstring *answer = [_textbox.text stringbyreplacingoccurrencesofstring:@" " withstring:@""]; // block user getting incorrect answer no text in text field 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 = max (score +100, 0); [scorelabel settext:[nsstring stringwithformat:@"score: %d", score]]; coins = coins +5; if (score == 100) {coins = 8;} if (score == 0) {coins = 0;} if (score == 4) {coins = 4;} if (score == 3) {coins = 3;} if (score == 2) {coins = 2;} if (score == 1) {coins = 1;} [coinslabel settext:[nsstring stringwithformat:@"%d", coins]]; } else { // not correct. notify user, or don't [_wrongone sethidden:no]; score = min(score -5, 0); [scorelabel settext:[nsstring stringwithformat:@"score: %d", score]]; } if (score < 100) { closeonechange.text = @"correct!"; _imagecorp.image = [uiimage imagenamed:@"boxg_25.png"]; } else { closeonechange.text = @"perfect!"; _imagecorp.image = [uiimage imagenamed:@"telioo.png"]; } //correct button - perfect button } //perfect & correct button sets hidden - (ibaction)closeone:(id)sender { [_closeone sethidden:yes]; } oh , i'd user start @ least 50 coins before game starts, i'm having trouble figuring out how well..
by setting
coins = 8; etc. in if statements replace value of coins new value (here: 8) - if want add have write
coins = coins + 8; , did counting coins in line
coins = coins + 5; some more tips:
you should use if (...) { } else if (...) { } statements instead of using if's - once if statement true, others won't executed anymore.
if want rid of leading , trailing spaces of user input should use
nsstring* inputtext = [_textbox.text stringbytrimmingcharactersinset:[nscharacterset whitespaceandnewlinecharacterset];
Comments
Post a Comment