-
Notifications
You must be signed in to change notification settings - Fork 143
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
Changes from 1 commit
28533c4
06065da
1eee70f
a74a5c9
23de6d9
755cd58
9760ecc
4bc8775
f72f39e
92f6982
08300cf
072113e
94f44e7
88d6de0
b9d3658
5a093ca
846cf14
54b82e2
fab927c
cb163bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -22,29 +22,52 @@ enum GameResult { | |||||||||||||||
case error | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
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()))) | ||||||||||||||||
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. 이 부분은 길어서 가독성이 떨어지는 것 같습니다.
줄바꿈의 예시에요.
Suggested change
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. 오... 함수 내부에서 줄바꿈으로 정리한다는 생각을 해본 적이 없었는데 너무 좋은 것 같습니다! |
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
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() | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
|
@@ -63,8 +86,8 @@ func compare(userOption: GameOptions, computerOption: GameOptions) -> GameResult | |||||||||||||||
} | ||||||||||||||||
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. 와우.. 튜플을 써서 승패판정을 깔끔하게 구현하셨네요. |
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
func matchedValue(_ value: String) -> GameOptions { | ||||||||||||||||
switch value { | ||||||||||||||||
func matchedHand(_ hand: String) -> GameOptions { | ||||||||||||||||
switch hand { | ||||||||||||||||
case "0": | ||||||||||||||||
return .exit | ||||||||||||||||
case "1": | ||||||||||||||||
|
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.
enum을 잘 활용해주신 것 같아요!
원시값도 활용해보면 더 좋을 것 같아요~ 😊
Swift Language Guide - Enumerations