본문 바로가기

플레이그라운드

(17)
Playgrounds '플레이그라운드' 17. '코드'let  상수를 정의 하여  world.place ( expert, atColumn:1,row:1)  캐릭터 위치를 지정해줍니다. func 사용하여 함수를 정의 합니다. let expert = Expert()world.place(expert, atColumn:2, row: 6)func turnAround() {expert.turnLeft()expert.turnLeft()}func turnLockCollectGem() {expert.turnLeft()expert.turnLockUp()turnAround()expert.moveForward()expert.collectGem()turnAround()expert.moveForward()expert.turnRight()}turnLockCollectGem()..
Playgrounds '플레이그라운드' 16. '코드'목표: 함수를 작성하여 특정 횟수만큼 앞으로 이동해보세요.let expert = Expertfunc move (distance: Int) {}move(distance:숫자)let expert = Expert()func move (distance: Int) {for i in 1 ... distance {expert.moveForward()}move(distance: 6)expert.turnRight()move(distance:2)expert.turnRight()move(distance:5)expert.turnLeft()move(distance:5)expert.turnLeft()expert.turnLockUp()expert.turnLeft()move(distance:3)expert.turnRight(..
Playgrounds '플레이그라운드' 15. '코드'반복 패턴의 함수를 정의해 보세요.func [반복 사용 가능한 명칭을 입력해주세요] () {[                                         ]}[                                          ][                                          ] func [go]() {turnLeft()}moveForward()collectGem()moveForward()toggleSwitch()moveForward()go()moveForward()collectGem()moveForward()toggleSwitch()moveForward()collectGem()moveForward()collectGem()go()moveForward..
Playgrounds '플레이그라운드' 14. .코드.let expert = Expert()expert.moveForward()expert.turnLockUp()expert.turnLeft()expert.turnRight()Expert 유형의 인스턴스를 초기화하고 turnLockUp() 메소드로 퍼즐을 풀어 보세요.for i in 1 ... 3 {expert.moveForward()}expert.turnLockUp()expert.turnLeft()expert.turnLeft()for i in 1 ... 3 {expert.moveForward()}expert.turnLeft()for i in 1 ... 3 {expert.moveForward()}expert.collectGem()expert.turnLeft()expert.turnLeft()for i i..
Playgrounds '플레이그라운드' 13. '코드' 각 포털의 상태를 변경하여 보석을 수집해 보세요.bluePortal.isActive = falsebluePortal.isActive = truepinkPortal.isActive = falsepinkPortal.isActive = truebluePortal.isActive = falsepinkPortal.isActive = falsefor i in 1 ...3 {moveForward()}collectGem()pinkPortal.isActive =trueturnRight()turnRight()moveForward()turnRight()turnRight()moveForward()collectGem()turnRight()turnRight()bluePortal.isActive = truefor i in..
Playgrounds '플레이그라운드' 12. '코드'포털을 비활성화하여 스위치에 도달해 보세요.greenPortal.isActive = truegreenPortal.isActive = falsegreenPortal.isActive = falsefor i in 1 ... 6 {moveForward()}toggleSwitch()turnRight()turnRight()for i in 1 ... 3 {moveForward()}toggleSwitch()turnRight()turnRight()for i in 1 ... 6 {moveForward()}toggleSwitch()
Playgrounds '플레이그라운드' 11. '코드'gemCounter에 초기 값0을 할당합니다.보석을 발견한 경우 해당 보석을 수집하고 gemCounter 값을 1만큼 증가시킵니다.for i in 1 ... 7 {moveForward()collectGem()}if !isOnGem {gemCounter = gemCounter + 1gemCounter = gemCounter + 1gemCounter = gemCounter + 1}turnRight()for i in 1 ...2 {moveForward()collectGem()}if !isOnGem {gemCounter = gemCounter + 1}turnRight()for i in 1 ...7 {moveForward()collectGem()}if !isOnGem {gemCounter = gemCoun..
Playgrounds ‘플레이그라운드’ 10. '코드'var gemCounter = 의 초기 값을 0으로 설정합니다.var를 사용하여 변수에 이름을 지정하세요.보석을 수집 합니다.var gemCounter = 0moveForward()moveForward()collectGem()gemCounter = 1