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] jaySong #13

Open
wants to merge 2 commits into
base: rft_3_jaysong
Choose a base branch
from

Conversation

jysong91
Copy link

@jysong91 jysong91 commented Apr 25, 2024

User와 Computer가 카드선택은 동일하게 있는데, 나머지 승패 등은 유저만 관리하면 될 것 같아서 Player 프로토콜을 만들었습니다.
승패를 판단하는 기능을 구현할 때 if문이 많이 들어갔는데, else를 피하려고 early pattern을 적용해 봤습니다. 다른 방법은 뭐가 있을까요?
UI와 연동을 안해서, user카드도 랜덤으로 선택하도록 일단 해놨습니다.

@zdodev

Copy link

@zdodev zdodev left a comment

Choose a reason for hiding this comment

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

안녕하세요. @jysong91

세 번째 프로젝트까지 잘 진행해보셨네요!
묵찌빠 게임 수행까지 잘 동작합니다👍

실제 앱 실행에는 문제가 없지만 테스트 실행 시 에러가 발생하고 있어 한 번 확인해보면 좋을 것 같습니다!

궁금증과 의견을 코멘트로 남겨보았습니다.
확인해보고 개선해보면 좋을 것 같습니다!

Comment on lines +16 to +18
gameView = GameView(delegate: self)
guard let gameView = gameView else { return }
view = gameView
Copy link

Choose a reason for hiding this comment

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

뷰가 로드되는 단계에서 조기 종료가 발생할 수 있는 구문을 작성하기 보다는 안전하게 처리할 수 있는 구문을 사용해보는 것도 괜찮을 것 같습니다!

let gameView = GameView(delegate: self)
self.gameView = gameView
view = gameView

Copy link
Author

Choose a reason for hiding this comment

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

지역변수를 활용해서 옵셔널언래핑 없이 코드구현이 가능해졌네요, 좋은 것 같습니다

}

private func play(userCard: Card) {
Copy link

Choose a reason for hiding this comment

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

게임 시작과 진행, 종료까지 게임에 대한 로직이 ViewController에서 수행하고 있는 것으로 보입니다. 뷰와는 별개로 게임 수행을 위한 새로운 타입을 만들어 보는 것은 어떨까요? 역할과 책임을 나눠볼 수 있을 것 같습니다!

Copy link
Author

Choose a reason for hiding this comment

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

예를 들면, 게임 로직을 다루는 'GameController' 타입을 만들고, ViewController를 GameController와 GameView를 연결해주는 역할로 변경하는 식일까요?

Copy link

Choose a reason for hiding this comment

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

게임 로직을 다루는 GameController 타입을 만들어서 ViewController(GameView)의 책임을 줄일 수 있는 것도 좋은 방법일 것 같습니다!


private func judgement() {
guard let userCard = user.selectedCard, let computerCard = computer.selectedCard else { return }
let cal = userCard.rawValue - computerCard.rawValue
Copy link

Choose a reason for hiding this comment

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

cal 이름이 표현하는 의미가 모호한 것 같습니다. 조금 더 구체적인 이름을 사용해볼 수 있을까요?

Copy link
Author

Choose a reason for hiding this comment

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

음.. 가위바위보 결과를 계산하는 의미로, calculateResult 는 어떨까요

Copy link

Choose a reason for hiding this comment

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

cal 보다 명확한 이름인 것 같습니다.👍

guard let userCard = user.selectedCard, let computerCard = computer.selectedCard else { return }
let cal = userCard.rawValue - computerCard.rawValue

if cal == 0 {
Copy link

Choose a reason for hiding this comment

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

코드를 작성하고 이후에 if cal == 0 구문을 보았을 때, 그 의미를 파악하기 어려울 것 같습니다. 동일한 값을 나타낸다는 표현을 사용해보는 것이 어떨까요? 의미를 보다 명확하게 이해할 수 있을 것 같습니다!
아래의 if문도 확인해보면 좋을 것 같습니다.

Copy link
Author

Choose a reason for hiding this comment

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

0, 1, 2 같은 숫자들을 위한 enum타입을 만들어서 same, win, lose 등으로 case를 나누면 이해가 좀 더 용이할 것 같네요!

}
}

private func showResultAlert(_ isUserFinalWinner: Bool) {
Copy link

Choose a reason for hiding this comment

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

사용자에게 알림을 제공하는 메서드를 구현해보셨네요.👍

static let paper: String = "🖐️"
static let rock: String = "✊"
static let scissor: String = "✌️"
protocol GameViewDelegate: AnyObject {
Copy link

Choose a reason for hiding this comment

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

Delegate를 잘 정의해보셨네요.👍

@@ -114,10 +176,11 @@ class GameView: UIView {
])
}

init() {
init(delegate: GameViewDelegate) {
Copy link

Choose a reason for hiding this comment

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

DI를 잘 적용해보셨네요!👍

computer.select(card: .rock)

//when
let cal = user.selectedCard!.rawValue - computer.selectedCard!.rawValue
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

@jysong91 jysong91 Apr 27, 2024

Choose a reason for hiding this comment

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

구현부 코드를 테스트하는 형태란 예를들면 어떤 식인가요? user와 computer가 카드 선택하는 부분은 제외하고 승패 판정하는 부분만 테스트하도록 하는 것을 말씀하시는 건가요?

Copy link

Choose a reason for hiding this comment

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

given 단계에서 카드를 선택하는 것은 그대로 작성해도 괜찮을 것 같습니다. when 단계에서 게임의 진행과 결과를 판단하는 로직이 테스트 코드 내에 작성되어 있어서 코멘트를 작성해보았습니다. 어떤 코드를 테스트해보고 싶으셨는지 궁금했습니다!

Copy link
Author

Choose a reason for hiding this comment

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

결과 판단 코드를 테스트해보고 싶었습니다, 이제보니 메서드를 불러오면 되는것을, 내부 코드를 넣어버렸네요..!

let cal = user.selectedCard!.rawValue - computer.selectedCard!.rawValue

if cal == 0 {
user.draw()
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.

묵찌빠로 바꾸면서 draw() 함수가 삭제되었는데, 그 이후에는 단위테스트를 실행하지 않아서 발견을 못했네요..!

//then
XCTAssertNil(user.selectedCard)
XCTAssertEqual(user.winCount, 0)
XCTAssertEqual(user.drawCount, 0)
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.

묵찌빠로 바꾸면서 draw() 함수가 삭제되었는데, 그 이후에는 단위테스트를 실행하지 않아서 발견을 못했네요..

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.

2 participants