Skip to content

손영빈// base: main( 필수 기능 구현) <- compare: dev(도전 기능 구현) #1

Open
ybin4548 wants to merge 3 commits into
yeongbin_mainfrom
yeongbin_dev
Open

손영빈// base: main( 필수 기능 구현) <- compare: dev(도전 기능 구현) #1
ybin4548 wants to merge 3 commits into
yeongbin_mainfrom
yeongbin_dev

Conversation

@ybin4548
Copy link
Copy Markdown
Collaborator

하나의 함수 내부에 동작들을 전부 생성할 경우, 코드가 지저분해질 수 있어서 필요 기능들에 따라 함수로 분리했습니다.
startGame 함수로 호출하여 게임을 시작할 수 있습니다.
과제 속의 기능들만 구현해뒀기에 최적화가 덜 된 부분들이 존재합니다.
비슷한 개념들은 여러 방법으로 접근해서 풀어보고자 했습니다.

Comment thread baseballgame/game.swift

totalCount += 1 //기록 저장용 Count + 1

let inputChars = Array(input) //입력받은 값을 배열에 담음
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

20번 줄에서 guard let num = Optional(input.compactMap{ Int(String($0)) }) 코드로 num: [Int]로 정의해주신 걸로 봤습니다!

그래서 inputChars에 다시 Array(input)으로 넣지 않아도 inputChars = num을 바로 사용해주시거나 따로 새로운 정의 없이 num을 그대로 사용하셔도 좋을 것 같습니당!

그렇게하면 40번 줄 for문 내에서 inputChars를 타입 변환 없이 그대로 사용하실 수 있을 것 같아요ㅎㅎ

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

아이코, 그냥 휙 넘어갔던 부분이라 생각도 못하고있었던 것 같아요.
감사합니다 !

print("게임 기록 보기")
for (idx, score) in scoreRecord.enumerated() { //고차함수 enumerated를 사용하여 idx: 인덱스 score: 점수 반환 후 출력
print("\(idx + 1)번째 게임 : 시도 횟수 - \(score)")
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

배열의 인덱스 값을 이용하여 플레이 횟수를 유추하는 방법 너무 인상적입니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants