ios - Swift Programming - How to set up app for taking turns -


so attempting code application allow me , friend keep track of dart game. in game there several different buttons allow user add or subtract 1 or 2 users score. have buttons , have created outlets ran question how tell buttons user supposed to scoring. have attached picture of basic ui , of code using. advice really appreciated. need know how tell app users turn is, thinking possible add button "next turn" , push buttons reflect score of player , press "next turn" , switches players. therefore scoring effect next players turn. makes sense me on paper dont know start function. mind taking @ code have make labels reflect score changes, , see if logic makes sense?

import uikit  class viewcontroller: uiviewcontroller {   @iboutlet weak var user1score: uilabel!  @iboutlet weak var user2score: uilabel!  @ibaction func hit(sender: anyobject) {       user1score.text = "+1"  }  @ibaction func miss(sender: anyobject) { }  @ibaction func doubleplus(sender: anyobject) { }  @ibaction func doubleminus(sender: anyobject) { }  @ibaction func tripleplus(sender: anyobject) { }  @ibaction func tripleminus(sender: anyobject) { }  @ibaction func penalty(sender: anyobject) { } 

here image of mainstoryboardui

enter image description here

use class property keep track of current player. store scores in array , use currentplayer index value update. here basic approach:

class viewcontroller: uiviewcontroller {     @iboutlet weak var currentname: uilabel!     @iboutlet weak var user1score: uilabel!     @iboutlet weak var user2score: uilabel!      var names = ["fred", "joe"]     var currentplayer = 0     var scores = [0, 0]      func updateui() {         currentname.text = names[currentplayer]         user1score.text = "\(scores[0])"         user2score.text = "\(scores[1])"     }      @ibaction func changeplayers() {         currentplayer = 1 - currentplayer         updateui()     }      @ibaction func hit() {         scores[currentplayer]++         updateui()         } }     

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -