ios - When making an if statement can I make it so a void that is already running be overwritten? -
i have bug game red circle, blue circle, , yellow circle. can touch red circle. have random button selector called buttonchanger. whenever method run selects random button , after amount of time button disappears , method runs again. wondering if made statement
if bluecircle.hidden = yes, redcircle.hidden = yes, yellowcircle.hidden = yes{ [self buttonchanger]; }
this stuck. if run if
statement buttons keep changing , continue overlap void until crashes. wondering if inside if
statement can make if
statement overrides previous 1 fine , running , void not overlap. so:
if bluecircle.hidden = yes, redcircle.hidden = yes, yellowcircle.hidden = yes{ if buttonchanger running{ } else{ [self buttonchanger]; } }
if wish see code here is:
#import "viewcontroller.h" #import "viewcontroller.m" @interface viewcontroller () @end int randomnumber; double buttontime; int randomnumberbutton; int score; int highscoreint; @implementation viewcontroller - (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically nib. if ([[uiscreen mainscreen] respondstoselector:@selector(scale)]) { if ([[uiscreen mainscreen] scale] == 2.0) { if([uiscreen mainscreen].bounds.size.height == 667){ // iphone retina-4.7 inch(iphone 6) } else if([uiscreen mainscreen].bounds.size.height == 568){ // iphone retina-4 inch(iphone 5 or 5s) } else{ // iphone retina-3.5 inch(iphone 4s) } } else if ([[uiscreen mainscreen] scale] == 3.0) { //if want detect iphone 6+ if([uiscreen mainscreen].bounds.size.height == 736.0){ //iphone retina-5.5 inch screen(iphone 6 plus) } //iphone retina-5.5 inch screen(iphone 6 plus) } } } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } @end @implementation game{ } -(void)viewdidappear:(bool)animated{ play.hidden = no; } - (void)viewdidload { [super viewdidload]; scorelabeldisplay.hidden = yes; // additional setup after loading view, typically nib. gameover.hidden = yes; menu.hidden = yes; redcircle2.hidden = yes; yellowcircle.hidden = yes; bluecircle.hidden = yes; score = 0; scorelabel.font = [uifont systemfontofsize:25]; scorestring = [nsstring stringwithformat:@"score:%i", score]; scorelabel.text = scorestring; gameover.font = [uifont systemfontofsize:50]; scorelabeldisplay.font = [uifont systemfontofsize:25]; highscore.hidden = yes; highscore.font = [uifont systemfontofsize:25]; nsurl *soundurl = [nsurl fileurlwithpath:[nsstring stringwithformat:@"%@/ding.wav", [[nsbundle mainbundle] resourcepath]]]; audioservicescreatesystemsoundid((__bridge cfurlref)soundurl, &playsoundid); } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } #pragma mark iad delegate methods -(void)bannerviewdidloadad:(adbannerview *)banner{ [uiview beginanimations:nil context:nil]; [uiview setanimationduration:1]; [banner setalpha:2]; [uiview commitanimations]; } -(void)bannerview:(adbannerview *)banner didfailtoreceiveadwitherror:(nserror *)error{ [uiview beginanimations:nil context:nil]; [uiview setanimationduration:1]; [banner setalpha:0]; [uiview commitanimations]; } -(double)generatebuttontime { nsinteger randomnumber = arc4random_uniform(100); double buttomtime = 0; if (randomnumber>50) { if (randomnumber<75) { buttomtime = 0.5; }} if (randomnumber>75){ buttomtime = 1.0; } if (randomnumber<50) { buttomtime = 0.4 ; } if (randomnumber>10){ if (randomnumber<50) { buttomtime = 0.2 ; }} return buttomtime; } -(void)enablebluecircle:(nstimer*)timer { bluecircle.hidden = yes; [self buttonchanger]; } -(void)enableyellowcircle:(nstimer*)timer { yellowcircle.hidden = yes; [self buttonchanger]; } -(void)fixbug{ if (redcircle2.hidden = yes, bluecircle.hidden = yes, yellowcircle.hidden = yes) { [self buttonchanger]; } } -(void)setredcircle:(nstimer*)timer { redcircle2.hidden = yes; [self buttonchanger]; } -(void)buttonchanger{ buttontime = 0; randomnumberbutton = arc4random_uniform(100); if (randomnumberbutton>75) { redcircle2.hidden = yes; yellowcircle.hidden = yes; bluecircle.hidden = no; [nstimer scheduledtimerwithtimeinterval:[self generatebuttontime] target:self selector:@selector(enablebluecircle:) userinfo:nil repeats:no]; } if (randomnumberbutton<30){ redcircle2.hidden = yes; bluecircle.hidden = yes; yellowcircle.hidden = no; [nstimer scheduledtimerwithtimeinterval:[self generatebuttontime] target:self selector:@selector(enableyellowcircle:) userinfo:nil repeats:no]; } if (randomnumberbutton>30) { if (randomnumberbutton<75) { redcircle2.hidden = no; bluecircle.hidden = yes; yellowcircle.hidden = yes; [nstimer scheduledtimerwithtimeinterval:[self generatebuttontime] target:self selector:@selector(setredcircle:) userinfo:nil repeats:no]; } } } - (ibaction)redcirclebutton:(id)sender { randomnumber = 0; score = score + 1; scorestring = [nsstring stringwithformat:@"score:%i", score]; scorelabel.text = scorestring; audioservicesplaysystemsound(playsoundid); } - (ibaction)bluecirclebutton:(id)sender { [self gameover]; } -(void)gameover{ gameover.hidden = no; bluecircle.enabled = no; bluecircle.hidden = yes; yellowcircle.enabled = no; yellowcircle.hidden = yes; redcircle2.hidden = yes; redcircle2.enabled = no; menu.hidden = no; scorelabeldisplay.hidden = no; scorelabeldisplay.text = scorestring; if (score > highscoreint) { highscoreint = score; } highscore.hidden = no; highscorestring = [nsstring stringwithformat:@"highscore:%i", highscoreint]; highscore.text = highscorestring; scorelabel.hidden = yes; } - (ibaction)yellowcirclebutton:(id)sender { [self gameover]; } - (ibaction)playaction:(id)sender { [self buttonchanger]; play.hidden = yes; } @end
this line sounds strange:
if (redcircle2.hidden = yes, bluecircle.hidden = yes, yellowcircle.hidden = yes)
you assigning yes hidden property of redcircle2, bluecircle , yellowcircle , true boolean expression....
you wants this:
if (redcircle2.hidden && bluecircle.hidden && yellowcircle.hidden)
Comments
Post a Comment