일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
31 |
- Learning
- Swift
- 2대 연결
- Generalizing a Funcetion
- Polite
- 컴터 연결
- Uniting Worlds
- 렛츠톡 첫 화면
- feel torn
- Connect and Solve
- Grammarly
- allege
- 구글이 좋아하는 강한 SEO 작성 방법
- 신세지다
- Playground
- 코린이
- BASIC
- 인앱 결제
- Playgrounds
- 기초
- 코딩
- 해당 비즈니스 및 사이트명을 포함할 수 있도록 페이지 텍스트를 편집하세요 - wix.com
- Making Your Own Portals
- collect the total
- 맥
- obliged
- progamming
- SwiftUI
- crank up and down
- coding
- Today
- Total
IT
day 7 - type 본문
if you want to build a house, you use a blueprint.
A blueprint shows the features of your house, such as the kitchen, bathrooms, and bedrooms.
When you use a blueprint to build multiple houses, you know that the houses will look similar.
In programming, a type is like a blueprint, and an instance is like a house that you built from the blueprint.
In a type, features are called properties, and behaviors are called methods.
Goal : Modify the state of each portal to gather the gems.
func turnAround() {
turnLeft()
turnLeft()
}
bluePortal.isActive = false
pinkPortal.isActive = false
while !isBlocked {
moveForward()
if isOnGem {
collectGem()
}
}
turnAround()
pinkPortal.isActive = true
moveForward()
turnAround()
moveForward()
collectGem()
turnAround()
moveForward()
bluePortal.isActive = true
moveForward()
moveForward()
collectGem()
turnAround()
bluePortal.isActive = false
while !isBlocked {
moveForward()
if isOnGem {
collectGem()
}
}
Comment) 점 앞에 붙은 것을 인스턴스라고 한다.
Goal : Modify the state of two portals to solve the puzzle
turnRight()
orangePortal.isActive = false
moveForward()
for i in 1 ... 2 {
moveForward()
turnRight()
moveForward()
toggleSwitch()
turnLeft()
turnLeft()
}
orangePortal.isActive = true
moveForward()
orangePortal.isActive = false
for i in 1 ... 3 {
moveForward()
collectGem()
turnLeft()
turnLeft()
moveForward()
turnLeft()
}
moveForward()
collectGem()
moveForward()
greenPortal.isActive = false
moveForward()
for i in 1 ... 2 {
moveForward()
collectGem()
turnLeft()
turnLeft()
moveForward()
turnLeft()
}
moveForward()
greenPortal.isActive = true
turnRight()
turnRight()
moveForward()
greenPortal.isActive = false
for i in 1 ... 4 {
moveForward()
toggleSwitch()
turnLeft()
turnLeft()
moveForward()
turnLeft()
}
comment ) while 를 쓰지 않았다. 정해진 횟수를 움직이는 데는 'for ' statement is better. and I learned what 'instance' is.
when I write here 'Grammarly' helped me to correct the sentence. it is very helpful. It's a good experience.
Random Gems Everywhere
let totalGems = randomNumberOfGems
var collectedGems = 0
func turnAround() {
turnLeft()
turnLeft()
}
func flipStateOfBothPortals() {
pinkPortal.isActive = !pinkPortal.isActive
bluePortal.isActive = !bluePortal.isActive
}
func moveForwardCollectingGems() {
if isOnGem {
collectGem()
collectedGems += 1
}
if isBlocked {
turnAround()
flipStateOfBothPortals()
} else {
moveForward()
}
}
if isBlocked {
turnAround()
pinkPortal.isActive = false
}
while !(collectedGems == totalGems) {
moveForwardCollectingGems()
}
comments) func 에 많은 점들을 포함시켰다. I can use 'func' more efficiently. I think the matter is how can I find this code in the google
'Learn to Code' 카테고리의 다른 글
Day 9 - Parameters (0) | 2022.06.06 |
---|---|
Day 8 - Initialization (0) | 2022.05.20 |
day 6 - var [변수] vs let [상수] (0) | 2022.05.12 |
How-To : "이 애플 ID로 업데이트할 수 없음" 오류 메시지 대처법 (0) | 2022.05.06 |
day 3 - logical operator (0) | 2022.04.28 |