250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- HTML
- effect
- 백엔드
- image
- iPhone
- ipad
- iOS 개발자
- front-end
- php
- 비전공 개발자
- 풀스택
- css3
- CSS
- MAC
- SWIFT
- react
- html5
- keyframes
- 개발자
- jQuery
- javascript
- Animation
- xcode
- 자바스크립트
- hover
- 비전공자
- IOS
- button
- 프론트엔드
- 애니메이션
Archives
- Today
- Total
비전공자 개발일기
Rock Scissors Paper 본문
728x90
SMALL
import UIKit
class ViewController: UIViewController {
// 최상단 레이블
@IBOutlet weak var mainLabel: UILabel!
// 가위 바위 보 이미지
@IBOutlet weak var comImageView: UIImageView!
@IBOutlet weak var myImageView: UIImageView!
// 가위 바위 보 글자
@IBOutlet weak var comChoiceLabel: UILabel!
@IBOutlet weak var myChoiceLabel: UILabel!
var comChoice: Rps = Rps(rawValue: Int.random(in: 0...2))!
var myChoice: Rps = Rps.rock
override func viewDidLoad() {
super.viewDidLoad()
comImageView.image = #imageLiteral(resourceName: "ready")
myImageView.image = UIImage(named: "ready.png")
comChoiceLabel.text = "준비"
myChoiceLabel.text = "준비"
}
@IBAction func rpsBTNTapped(_ sender: UIButton) {
// guard let title = sender.currentTitle else {
// return
// }
let title = sender.currentTitle!
switch title {
case "가위":
myChoice = Rps.scissors
case "바위":
myChoice = Rps.rock
case "보":
myChoice = Rps.paper
default:
break
}
}
@IBAction func selectBTNTapped(_ sender: UIButton) {
switch comChoice {
case Rps.scissors:
comImageView.image = #imageLiteral(resourceName: "scissors")
comChoiceLabel.text = "가위"
case Rps.rock:
comImageView.image = #imageLiteral(resourceName: "rock")
comChoiceLabel.text = "바위"
case Rps.paper:
comImageView.image = #imageLiteral(resourceName: "paper")
comChoiceLabel.text = "보"
}
switch myChoice {
case Rps.scissors:
myImageView.image = #imageLiteral(resourceName: "scissors")
myChoiceLabel.text = "가위"
case Rps.rock:
myImageView.image = #imageLiteral(resourceName: "rock")
myChoiceLabel.text = "바위"
case Rps.paper:
myImageView.image = #imageLiteral(resourceName: "paper")
myChoiceLabel.text = "보"
}
if (comChoice == myChoice) {
mainLabel.text = "비겼다"
} else if (comChoice == .rock && myChoice == .paper || comChoice == .paper && myChoice == .scissors || comChoice == .scissors && myChoice == .rock) {
mainLabel.text = "이겼다"
} else {
mainLabel.text = "졌다"
}
}
@IBAction func resetBTNTapped(_ sender: UIButton) {
comImageView.image = #imageLiteral(resourceName: "ready")
comChoiceLabel.text = "준비"
myImageView.image = #imageLiteral(resourceName: "ready")
myChoiceLabel.text = "준비"
mainLabel.text = "가위 바위 보"
comChoice = Rps(rawValue: Int.random(in: 0...2))!
}
}
728x90
LIST
'SWIFT' 카테고리의 다른 글
UP and Down Number Game in iOS APP (0) | 2022.11.05 |
---|---|
UP and DOWN Number Game (0) | 2022.11.05 |
Dice Game + breakpoint Error (0) | 2022.11.04 |
My First iOS Application + useful shortcut keys in Xcode (0) | 2022.11.03 |
Swift Basic - function, Optional type... (0) | 2022.11.01 |