728x90
최대한 간결하게, 모듈화하도록 노력해보았다.
let totalGems = randomNumberOfGems
var myGem = 0
bluePortal.isActive = false
func move() {
if isBlocked {
turnAround()
portalProgress()
}
moveForward()
}
func collectMyGem(){
if isOnGem {
collectGem()
myGem += 1
}
}
func turnAround(){
turnRight()
turnRight()
}
func portalProgress(){
pinkPortal.isActive.toggle()
bluePortal.isActive.toggle()
}
while totalGems != myGem {
move()
collectMyGem()
}
728x90
'iOS > Swift' 카테고리의 다른 글
Swift 에서의 프로퍼티(Property) (0) | 2025.03.21 |
---|---|
Swift 에서의 Generics(제너릭) (0) | 2025.03.20 |
SwiftUI 로 고차함수 예제코드 (0) | 2025.03.19 |
Swift 에서의 초기화와 초기화 해제 (init, deinit) 그리고 self (0) | 2025.03.19 |
Swift 에서의 일급 함수 (First-Class Function) (0) | 2025.03.18 |