剪刀石頭布APP

這週的第二個APP

比擲骰子多了一個判斷書由的 i f

內容是相差不多的

程式碼如下:

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var imageVV1: UIImageView!

@IBOutlet weak var imageVV2: UIImageView!

@IBOutlet weak var labeltext: UILabel!

let imageName = [“布”,”石頭”,”剪刀”]

var player = “”

var npcplayer = “”

override func viewDidLoad() {

super.viewDidLoad()

// Do any additional setup after loading the view.

}

@IBAction func button(_ sender: Any) {

npcplayer = imageName.randomElement()!

player = imageName.randomElement()!

imageVV1.image = UIImage(named: npcplayer)

imageVV2.image = UIImage(named: player)

if npcplayer == “剪刀” {

if player == “剪刀” {

labeltext.text = “平手”

} else if player == “石頭”{

labeltext.text = “我贏了^^”

} else {

labeltext.text = “我輸了QQ”

}

} else if npcplayer == “石頭” {

if player == “剪刀” {

labeltext.text = “我輸了QQ”

} else if player == “石頭”{

labeltext.text = “平手”

} else {

labeltext.text = “我贏了^^”

}

} else {

if player == “剪刀” {

labeltext.text = “我贏了^^”

} else if player == “石頭”{

labeltext.text = “我輸了QQ”

} else {

labeltext.text = “平手”

}

}

}

}

--

--