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

묵찌빠게임 [STEP 1] Doogie, Eddy #114

Merged
merged 20 commits into from
Feb 17, 2022
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
28533c4
docs: flowchart 작성
doogie97 Feb 15, 2022
06065da
feat: 메뉴 출력 함수, 입력 함수, 유효성 검사 함수 구현
kimkyunghun3 Feb 15, 2022
1eee70f
feat: 유저 유효성 검사 함수 분리 구현
doogie97 Feb 15, 2022
a74a5c9
refactor: 함수 네이밍 수정 및 세부 코드 조정
kimkyunghun3 Feb 15, 2022
23de6d9
feat: 컴퓨터 랜덤값 생성 함수 구현
doogie97 Feb 15, 2022
755cd58
refactor: 비교함수 통합, 함수 위치 수정
kimkyunghun3 Feb 15, 2022
9760ecc
refactor: enum 구현에 따른 함수 수정, 네이밍 수정
doogie97 Feb 15, 2022
4bc8775
Merge branch '5_doogie' of https://github.com/doogie97/ios-rock-paper…
doogie97 Feb 15, 2022
f72f39e
Revert "refactor: enum 구현에 따른 함수 수정, 네이밍 수정"
doogie97 Feb 15, 2022
92f6982
Auto stash before revert of "refactor: enum 구현에 따른 함수 수정, 네이밍 수정"
kimkyunghun3 Feb 15, 2022
08300cf
Revert "Auto stash before revert of "refactor: enum 구현에 따른 함수 수정, 네이밍…
doogie97 Feb 15, 2022
072113e
Revert "Revert "refactor: enum 구현에 따른 함수 수정, 네이밍 수정""
doogie97 Feb 15, 2022
94f44e7
chore: 불필요한 타입과 초기화 값 제거
kimkyunghun3 Feb 15, 2022
88d6de0
refactor: 유저값, 컴퓨터 값 매칭함수 병합 및 네이밍 수정
doogie97 Feb 16, 2022
b9d3658
refactor: 애매한 네이밍 수정, 불필요한 argument label 생략
kimkyunghun3 Feb 16, 2022
5a093ca
refactor: 결과 출력내용과 함수를 모아둔 enum 생성, compareValue 함수및 매개변수 네이밍 수정
doogie97 Feb 16, 2022
846cf14
refactor: nil 병합 연산방식으로 유저 입력 받는 함수 수정
kimkyunghun3 Feb 16, 2022
54b82e2
docs: Step2 flowchart 추가
doogie97 Feb 16, 2022
fab927c
refactor: 매칭 함수 내 스위치문을 열거형 속 초기화로 구현
kimkyunghun3 Feb 17, 2022
cb163bc
feat: 묵찌빠 비교함수 구현과 이에 따른 함수명 변경
doogie97 Feb 17, 2022
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
Prev Previous commit
Next Next commit
refactor: 결과 출력내용과 함수를 모아둔 enum 생성, compareValue 함수및 매개변수 네이밍 수정
  • Loading branch information
doogie97 committed Feb 16, 2022
commit 5a093ca2b862b660da4b285acf47ec60439b3b41
47 changes: 35 additions & 12 deletions RockPaperScissors/RockPaperScissors/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,52 @@ enum GameResult {
case error
}
Copy link
Member

@leeari95 leeari95 Feb 15, 2022

Choose a reason for hiding this comment

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

enum을 잘 활용해주신 것 같아요!
원시값도 활용해보면 더 좋을 것 같아요~ 😊
Swift Language Guide - Enumerations


enum ResultTexts {
static let winText = "이겼습니다!"
static let drawText = "비겼습니다!"
static let loseText = "졌습니다!"
static let endText = "게임 종료"
static let errorText = "잘못된 입력입니다. 다시 시도해주세요."
static func printWin() {
print(winText)
print(endText)
}
static func printDraw() {
print(drawText)
showMenu()
}
static func printlose() {
print(loseText)
print(endText)
}
static func printEnd() {
print(endText)
}
static func printError() {
print(errorText)
showMenu()
}
}

func showMenu() {
print("""
가위(1), 바위(2), 보(3)! <종료 : 0> :
""", terminator: " ")
showResult(compare(userOption: matchedValue(receiveNumber()), computerOption: matchedValue(makeRandomNumber())))
showResult(compare(userOption: matchedHand(receiveNumber()), computerOption: matchedHand(makeRandomNumber())))
Copy link
Member

Choose a reason for hiding this comment

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

이 부분은 길어서 가독성이 떨어지는 것 같습니다.
두가지 방법으로 개선해볼 수 있을 것 같아요.

  • 줄바꿈을 해서 가독성 개선
  • 파라미터에 default 값을 할당해줘서 개선 (Default Parameter Values)
    어떻게 개선해볼지는 여러분들의 선택입니다.

줄바꿈의 예시에요.

Suggested change
showResult(compare(userOption: matchedHand(receiveNumber()), computerOption: matchedHand(makeRandomNumber())))
showResult(
compareStepOne(
userOption: matchedHand(receiveNumber()),
computerOption: matchedHand(makeRandomNumber())
)
)

Choose a reason for hiding this comment

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

오... 함수 내부에서 줄바꿈으로 정리한다는 생각을 해본 적이 없었는데 너무 좋은 것 같습니다!
다만, default값을 할당한다는게 파라미터에 기본값을 할당해 준다는 내용으로 이해 했는데 그 기본값이 어떤게 되어야 할 지 잘 생각이 되지 않습니다!

}

func showResult(_ gameResult: GameResult) {
switch gameResult {
case .win:
print("이겼습니다!")
print("게임 종료")
ResultTexts.printWin()
case .draw:
print("비겼습니다!")
showMenu()
ResultTexts.printDraw()
case .lose:
print("졌습니다!")
print("게임 종료")
ResultTexts.printlose()
case .exit:
print("게임 종료")
ResultTexts.printEnd()
case .error:
print("잘못된 입력입니다. 다시 시도해주세요.")
showMenu()
ResultTexts.printError()
}
}

Expand All @@ -63,8 +86,8 @@ func compare(userOption: GameOptions, computerOption: GameOptions) -> GameResult
}
Copy link
Member

Choose a reason for hiding this comment

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

와우.. 튜플을 써서 승패판정을 깔끔하게 구현하셨네요.
최고에요!!! 👍🏻

}

func matchedValue(_ value: String) -> GameOptions {
switch value {
func matchedHand(_ hand: String) -> GameOptions {
switch hand {
case "0":
return .exit
case "1":
Expand Down