-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Week4 [STEP 1] cherrishRed #4
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,81 @@ | |
|
||
import Foundation | ||
|
||
print("Hello, World!") | ||
class BodyCondition { | ||
var upperBodyStrength = 0 | ||
var lowerBodyStrength = 0 | ||
var muscularEndurance = 0 | ||
var fatigue = 0 | ||
|
||
func printBodyCondition() { | ||
print("--------------") | ||
print("현재의 컨디션은 다음과 같습니다.") | ||
print("상체근력: \(upperBodyStrength)") | ||
print("하체근력: \(lowerBodyStrength)") | ||
print("근지구력: \(muscularEndurance)") | ||
print("피로도: \(fatigue)") | ||
} | ||
} | ||
|
||
var person = BodyCondition() | ||
|
||
struct Exercise { | ||
let name: String | ||
let action: () -> Void | ||
} | ||
|
||
let situp = Exercise(name: "윗몸일으키기", action: { | ||
let random = Int.random(in: 10..<20) | ||
person.upperBodyStrength += random | ||
person.fatigue += random | ||
}) | ||
|
||
let squat = Exercise(name: "스쿼트", action: { | ||
let randomForStrength = Int.random(in: 20..<30) | ||
let randomForFatigue = Int.random(in: 10..<20) | ||
person.lowerBodyStrength += randomForStrength | ||
person.fatigue += randomForFatigue | ||
}) | ||
|
||
let running = Exercise(name: "오래달리기", action: { | ||
let randomForEndurance = Int.random(in: 20..<30) | ||
let randomForStrength = Int.random(in: 5..<10) | ||
let randomForFatigue = Int.random(in: 20..<30) | ||
person.muscularEndurance += randomForEndurance | ||
person.lowerBodyStrength += randomForStrength | ||
person.upperBodyStrength += randomForStrength | ||
person.fatigue += randomForFatigue | ||
}) | ||
|
||
let activeRest = Exercise(name: "동적휴식", action: { | ||
let randomForFatigue = Int.random(in: 5..<10) | ||
person.fatigue += randomForFatigue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 휴식인데, 피로도가 증가하고 있습니다! 😱 |
||
}) | ||
|
||
class Routine { | ||
let name: String | ||
var exercises: [Exercise] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 딱히 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 혹시나 루틴을 변경할 수 도 있지 않나, 싶어서 일단은 변수로 생성 했습니다. |
||
|
||
init(name: String, exercises: [Exercise]) { | ||
self.name = name | ||
self.exercises = exercises | ||
} | ||
|
||
func doRoutine(){ | ||
print("--------------") | ||
print("\(self.name)을 시작합니다.") | ||
for count in 0..<exercises.count { | ||
exercises[count].action() | ||
print("\(exercises[count].name)") | ||
} | ||
} | ||
} | ||
|
||
let hellRoutine = Routine(name: "헬루틴", exercises: [situp, situp, | ||
activeRest, | ||
squat, squat, | ||
activeRest, | ||
running, running]) | ||
hellRoutine.doRoutine() | ||
person.printBodyCondition() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
왜 변수로 인스턴스를 생성하셨나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
운동하는 메서드를 사용하면서 person 안에 있는 프로퍼티 들이 변경되기 때문에 변수를 사용했습니다.