ios - How to subtract coins once from each button action? -
i've place 3 buttons first button allows animation reveal other buttons, user should spend 10 points on each action.
meaning when press button #2 must lose 10 coins (-10 coins) same goes action #3.
-(ibaction)btnhint:(id)sender { [uiview beginanimations:nil context:null]; [uiview setanimationduration:0.5]; cgpoint center = [hints center]; center.x = 160; center.y = 230; [hints setcenter:center]; [uiview commitanimations]; hintview.text = @"founded in 1996, , sub of telecome"; if(minuspoint) { coins = coins -10; //minus point minuspoint = no; } } - (ibaction)firsthintq:(id)sender { hintview.text = @"founded in 1996, , sub of telecome"; } - (ibaction)secondhintq:(id)sender { [_candletwo setimage:[uiimage imagenamed:@"candle2_03.png"] forstate:uicontrolstatenormal]; hintview.text = @"type in text here 2"; } - (ibaction)thirdhintq:(id)sender { hintview.text = @"type in third hint here"; [_candlethree setimage:[uiimage imagenamed:@"candle2_03.png"] forstate:uicontrolstatenormal]; }
and, how display -10 points on coins label?
make conins
global of type int. let coin label coinlabel
. make 3 bool
global variable such btn1pressed,btn2pressed,btn3pressed
. in viewdidload
make btn1pressed = btn2pressed = btn3pressed =false;
. this:
-(ibaction)btnhint:(id)sender { [uiview beginanimations:nil context:null]; [uiview setanimationduration:0.5]; cgpoint center = [hints center]; center.x = 160; center.y = 230; [hints setcenter:center]; [uiview commitanimations]; hintview.text = @"founded in 1996, , sub of telecome"; } - (ibaction)firsthintq:(id)sender { hintview.text = @"founded in 1996, , sub of telecome"; if(!btn1pressed) { if((coins -10) >= 0){ coins = coins -10; btn1pressed = true coinlabel.text = [nsstring stringwithformat:@"%d",coins]; } else{ //show alert user has not enough coins } } } - (ibaction)secondhintq:(id)sender { [_candletwo setimage:[uiimage imagenamed:@"candle2_03.png"] forstate:uicontrolstatenormal]; hintview.text = @"type in text here 2"; if(!btn2pressed) { if((coins -10) >= 0){ coins = coins -10; btn2pressed = true coinlabel.text = [nsstring stringwithformat:@"%d",coins]; } else{ //show alert user has not enough coins } } } - (ibaction)thirdhintq:(id)sender { hintview.text = @"type in third hint here"; [_candlethree setimage:[uiimage imagenamed:@"candle2_03.png"] forstate:uicontrolstatenormal]; if(!btn3pressed) { if((coins -10) >= 0){ coins = coins -10; btn3pressed = true coinlabel.text = [nsstring stringwithformat:@"%d",coins]; } else{ //show alert user has not enough coins } } }
hope helps .. :)
Comments
Post a Comment