14일만에 IOS 앱 끝내기 챌린지
(13일차, 14일차) 14일 만에 IOS 앱 끝내기 챌린지 : 슬롯머신 만들기
슈뢰딩거의 고등어
2023. 3. 4. 16:56
Spin 버튼을 누를때마다 그림들이 랜덤으로 바뀌고, 그에 따라 점수가 더해지거나 감해진다.
세 그림이 같으면 +15
그렇지 않으면 -5
//
// ContentView.swift
// Slot
//
// Created by jhmin on 2023/03/04.
//
import SwiftUI
struct ContentView: View {
@State private var score = 1000
@State private var pic1 = "apple"
@State private var pic2 = "apple"
@State private var pic3 = "apple"
var body: some View {
VStack {
Text("SwiftUI Slots!")
Spacer()
Text("Credits: " + String(score))
Spacer()
HStack {
// The images were too wide to begin with so make sure you
// add the resizable and aspectRatio modifiers
Image(pic1).resizable()
.aspectRatio(contentMode: .fit)
Spacer()
Image(pic2).resizable()
.aspectRatio(contentMode: .fit)
Spacer()
Image(pic3).resizable()
.aspectRatio(contentMode: .fit)
}
Spacer()
Button("Spin") {
let array = ["apple", "cherry", "star"]
pic1 = array.randomElement()!
pic2 = array.randomElement()!
pic3 = array.randomElement()!
if(pic1 == pic2 && pic2 == pic3) {
score += 15
}
else {
score -= 5
}
}.padding()
.padding([.leading, .trailing], 40)
.foregroundColor(.white)
.background(Color(.systemPink))
.cornerRadius(25)
.font(.system(size: 18, weight: .bold, design: .default))
Spacer()
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
챌린지 소감
처음 코딩을 해보는 사람들을 대상으로 하는 것이라서 쉽다.
앱 개발을 안해본 사람들이라도 기존에 개발을 해본 사람이라면 모든 코스 내용을 3일 정도에 끝낼 수 있을 것 같다.
앱개발 입문용으로 좋은 챌린지인것 같다.