Skip to content
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

Merged
merged 3 commits into from
Jan 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 77 additions & 1 deletion CodeStarterCamp_Week4/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

왜 변수로 인스턴스를 생성하셨나요?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

운동하는 메서드를 사용하면서 person 안에 있는 프로퍼티 들이 변경되기 때문에 변수를 사용했습니다.


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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

휴식인데, 피로도가 증가하고 있습니다! 😱

})

class Routine {
let name: String
var exercises: [Exercise]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

딱히 exercises에 변경이 일어날만한 코드가 보이지 않는데, 혹시 변수를 채택한 이유가 있나요? 🙂

Copy link
Author

Choose a reason for hiding this comment

The 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()