thiết lập game bull eyes

Upload: minh-ducc

Post on 26-Feb-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/25/2019 Thit Lp Game Bull Eyes

    1/12

    THIT LP V PHT TRIN GAME BULLs EYE

    I) Thng tin game :

    - H thng s random 1 s ngu nhin ra mn hnh, thanh slider s m! "#nh !h$%

    t& ' -( 1'' *ng +i! !a ng.i !h/i l 0hi 23o th thanh slider !h4nh 56! +o +# tr4 mh thng !ho s7n 89u 23o !h4nh 56! s "! 1'' "i;m, s "i;m s n 2hi +#tr4 "? !h@n !6!h 5a +# tr4 !a h thng, 8g.i !h/i tA Bu% "#nh s trCn "; l=% 29t Bu, 29tBu s "! !Dng dEn theo t&ng round n9u 2hng nh=n 0h4m start F+er

    - G4 d: h thng random !ho +# tr4 1, ng.i !h/i 23o th "9n "Jng +# tr4 mang s1 th s "! 1'' "i;m

    - *6!h t4nh "i;m: 1'' K gi6 tr# h thng L gi6 tr# hin t$i !a ng.i !h/i M s "i;m 89u !h/i nhiNu round th h thng s !Dng dEn s "i;m

    - Oame "! 0h6t triPn u

    1.2) Thut T!"#- hai

  • 7/25/2019 Thit Lp Game Bull Eyes

    2/12

    import UIKit

    class ViewController: UIViewController {

    var gameScore: NSUserDefaults!

    var currentValue: Int = 0var targetValue: Int = 0

    var score: Int = 0

    var round: Int = 0

    @IBOutlet weak var lblTargetValue: UILabel!

    @IBOutlet weak var lblScore: UILabel!

    @IBOutlet weak var lblRound: UILabel!

    @IBOutlet weak var slider: UISlider!

    func startNewRound() {

    round += 1

    targetValue = Int(arc4random() % 100)

    currentValue = 50

    slider.value = Float(currentValue)

    }

    func startNewGame() {

    score = 0

    round = 0

    startNewRound()

    }

    @IBAction func startOver(sender: AnyObject) {

    startNewGame()

    updateLabels()

    }

    func updateLabels() {lblTargetValue.text = String(targetValue)

    lblScore.text = String(score)

    lblRound.text = String(round)

    }

    @IBAction func sliderMovied(slider: UISlider) {

    print("The value of the slider is now: \(Int(slider.value))")

  • 7/25/2019 Thit Lp Game Bull Eyes

    3/12

    currentValue = Int(slider.value)

    }

    @IBAction func showAlert(sender: AnyObject) {

    let difference = abs(targetValue - currentValue)

    let points = 100 - differencescore += points

    let alert = UIAlertController(title: "The Bull's Eye Game", message: "The value of the slider is: \

    (currentValue)" + "\nYou scored \(points) points", preferredStyle: .Alert)

    let action = UIAlertAction(title: "Ok", style: .Default, handler: nil)

    alert.addAction(action)

    presentViewController(alert, animated: true, completion: nil)

    startNewRound()

    updateLabels()

    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    gameScore.setObject("\(score)", forKey: "temp")

    }

    override func viewDidLoad() {

    super.viewDidLoad()

    // Do any additional setup after loading the view, typically from a nib.

    startNewGame()

    updateLabels()

    gameScore = NSUserDefaults()

    }

    override func didReceiveMemoryWarning() {

    super.didReceiveMemoryWarning()

    // Dispose of any resources that can be recreated.

    }

    }

    AboutViewController :

    import UIKit

  • 7/25/2019 Thit Lp Game Bull Eyes

    4/12

    class AboutViewController: UIViewController {

    @IBAction func close(sender: AnyObject) {

    dismissViewControllerAnimated(true, completion: nil)

    }

    override func viewDidLoad() {

    super.viewDidLoad()

    // Do any additional setup after loading the view.

    }

    override func didReceiveMemoryWarning() {

    super.didReceiveMemoryWarning()

    // Dispose of any resources that can be recreated.

    }

    /*

    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    // Get the new view controller using segue.destinationViewController.

    // Pass the selected object to the new view controller.

    }

    */

    }

    GameOverViewController

    import UIKit

    class GameOverViewController: UIViewController {

    var gameScore: NSUserDefaults!

    @IBOutlet weak var lblScoreOver: UILabel!

    @IBAction func playAgain(sender: AnyObject) {

    self.dismissViewControllerAnimated(true

  • 7/25/2019 Thit Lp Game Bull Eyes

    5/12

    , completion: nil)

    }

    override func viewDidLoad() {

    super.viewDidLoad()

    // Do any additional setup after loading the view.gameScore = NSUserDefaults()

    lblScoreOver.text = gameScore.objectForKey("temp") as! NSString as String

    }

    override func didReceiveMemoryWarning() {

    super.didReceiveMemoryWarning()

    // Dispose of any resources that can be recreated.

    }

    /*

    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    // Get the new view controller using segue.destinationViewController.

    // Pass the selected object to the new view controller.

    }

    */

    }

    InfoViewController:

    import UIKit

    class InfoViewController: UIViewController {

    override func viewDidLoad() {

    super.viewDidLoad()

    // Do any additional setup after loading the view.

    }

    override func didReceiveMemoryWarning() {

    super.didReceiveMemoryWarning()

  • 7/25/2019 Thit Lp Game Bull Eyes

    6/12

    // Dispose of any resources that can be recreated.

    }

    /*

    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    // Get the new view controller using segue.destinationViewController.

    // Pass the selected object to the new view controller.

    }

    */

    }

    Main.storybroad:

  • 7/25/2019 Thit Lp Game Bull Eyes

    7/12

  • 7/25/2019 Thit Lp Game Bull Eyes

    8/12

  • 7/25/2019 Thit Lp Game Bull Eyes

    9/12

  • 7/25/2019 Thit Lp Game Bull Eyes

    10/12

    IV) H0" th7D" G;5#V# 't Fu /0 th0"h tu n mNm 5!odeJ Thi9t lC0 thnh !ng game VullWs X%eJ Oame

  • 7/25/2019 Thit Lp Game Bull Eyes

    11/12

    $h

  • 7/25/2019 Thit Lp Game Bull Eyes

    12/12

    $h