ios - Swift 3 game button pressed loop -


i have array of images if pressed button image randomly appear. , there image down called array appears randomly once opened game. want conditions statement button pressed. have 5 conditions once button clicked: 1- if pressed , image appeared not same uiimage view down score added 2- if button did not press 2 seconds appear down. 3- if button pressed , same uiimage game over. 4- if calculated 4 images down because didn't hit image in 2 seconds lose.

 var array:[uiimage] = [uiimage(named: "1.png")!,                             uiimage(named: "2.png")!,                             uiimage(named: "3.png")!,                             uiimage(named: "4.png")!,                             uiimage(named: "5.png")!,                             uiimage(named: "6.png")!,                             uiimage(named: "7.png")!,                             uiimage(named: "8.png")!,                             uiimage(named: "9.png")!,                             uiimage(named: "10.png")!] 

var random = arc4random_uniform(10)

@ibaction func mybuttonpressed(button: uibutton) {      var randomnum: uint32 = 10     randomnum = arc4random_uniform(uint32(array.count))      mybutton.setimage(uiimage(named: "bird\(randomnum).png"), for: uicontrolstate.normal)      // mybutton.setimage(uiimage(named: "\(randomnum).png"), for: ui)       self.myimage.animationimages = array      let buttonwidth = mybutton.frame.width     let buttonheight = mybutton.frame.height      // find width , height of enclosing view     let viewwidth = mybutton.superview!.bounds.width     let viewheight = mybutton.superview!.bounds.height      // compute width , height of area contain button's center     let xwidth = viewwidth - buttonwidth     let yheight = viewheight - buttonheight      // generate random x , y offset     let xoffset = cgfloat(arc4random_uniform(uint32(xwidth)))     let yoffset = cgfloat(arc4random_uniform(uint32(yheight)))      // offset button's center random offsets.     mybutton.center.x = xoffset + buttonwidth / 2     mybutton.center.y = yoffset + buttonheight / 2     /* in array{          if mybutton != myimage{             randomnum = arc4random_uniform(uint32(array.count))          }          if else      } */ } 

perhaps try this. first condition, uiimage view variable. uiimage view being displayed on storyboard?

import uikit  class viewcontroller: uiviewcontroller {      var array: [uiimage] = [uiimage(named: "1.png")!,                             uiimage(named: "2.png")!,                             uiimage(named: "3.png")!,                             uiimage(named: "4.png")!,                             uiimage(named: "5.png")!]        @iboutlet weak var mybutton: uibutton!     var pressed: bool = false;     var score: int = 0;       override func viewdidload() {         super.viewdidload()         // additional setup after loading view, typically nib.          //2nd condition: if button did not press 2 seconds appear down         if(pressed == false){             timer.scheduledtimer(timeinterval: 0.2, target: self, selector: #selector(viewcontroller.dosomething), userinfo: nil, repeats: true)         }       }      override func didreceivememorywarning() {         super.didreceivememorywarning()         // dispose of resources can recreated.     }      @ibaction func ispressed(_ sender: uibutton) {          pressed = true;          var randomnum: uint32 = 10         randomnum = arc4random_uniform(uint32(array.count));          mybutton.setimage(uiimage(named: "\(randomnum).png"), for: .normal)          // 1st condition: if pressed , image appeared not same uiimage view down score added         if( uiimage(named: "\(randomnum).png") != mybutton.currentimage){              //add view down score             score += 1;         }         // 3rd condition: if button pressed , same uiimage game on         else{              // game on         }        }      func dosomething() {         // not sure mean appear down         print("action")     }  } 

i not quite sure 4th condition does. please clarify


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -