-
Notifications
You must be signed in to change notification settings - Fork 231
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
[숫자 야구 게임] 장은영 미션 제출합니다. #228
base: main
Are you sure you want to change the base?
Conversation
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.
기본적으로 변수명과 클래스명은 명사로, 함수명은 동사로 지어주어야 합니다!
코틀린 컨벤션 가이드를 참고하시면 좋을 것 같아요.
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.
그리고 자동 정렬을 습관화하시면, 더 쉽게 코틀린 컨벤션을 지킬 수 있답니다!
코드를 읽어보니 :
띄어쓰기가 잘 안 되어 있는 것 같더라고요.
자동 정렬 단축키
윈도우: ctrl+shift+alt+L
맥: command+option+L
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.
좋은 정보 감사합니다 @sseung416 님!
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.
좋은 정보 감사합니다 !
computer.add(randomNumber) | ||
} | ||
} | ||
println(computer) |
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.
디버그용으로 작성하신 출력문인 것 같은데, 커밋 전에는 꼭 지워주세요!
fun compareNumber(ball:Int, strike: Int): String { | ||
|
||
var str = "" | ||
if (ball == 0 && strike == 0) { | ||
print("낫싱") | ||
} | ||
else if (ball == 0 && strike > 0) { | ||
print("${strike}스트라이크") | ||
} | ||
else if (strike == 0 && ball > 0) { | ||
print("${ball}볼") | ||
}else{ | ||
print("${ball}볼 ${strike}스트라이크")} | ||
return str | ||
} |
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.
str
을 선언한 이유가 있으신가요? 분기문에서는 str
의 값을 변경하는 작업이 보이지 않아서 여쭙니다!
그리고 코틀린 컨벤션에서는 다중 if
문보다는 when
을 권장하기 때문에 when
사용 고려해보시면 좋을 것 같습니다!
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.
승연님 말씀대로 val str = when() 해서 분기하면 더 좋을 것 같아요!
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.
return 값으로 돌려줘야해서 구현에 급급해서 그렇게 짰었네요..! 다음번엔 when() 사용 해봐야겠습니다 !
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.
은영님 코드 잘 봤습니다!! 고생하셨어요!! 다음주차도 같이 열심히 힘내봐요!!
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.
좋은 정보 감사합니다 @sseung416 님!
const val START_MESSAGE = "숫자 야구 게임을 시작합니다." | ||
const val INPUT_NUMBER_MESSAGE = "숫자를 입력해주세요 : " | ||
const val THREE_STRIKE_MESSAGE = "3개의 숫자를 모두 맞히셨습니다! 게임 종료" | ||
const val RESTART_MESSAGE = "게임을 새로 시작하려면 1, 종료하려면 2를 입력하세요." |
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.
🥰
TODO("프로그램 구현") | ||
var computer: List<Int> = listOf() | ||
var user: List<Int> | ||
var areUReady = true |
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.
이거 귀엽네요 areUReady ㅎㅎ
그래두 승연님 말씀대로 바꾸시면 더 좋을 것 같아요!
var ball = 0 | ||
var strike = 0 | ||
|
||
for (i in computer.indices) { |
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.
저도 지영님께 배웠는데, forEachIndexed 사용해도 좋을 것 같아요!
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.
다음번엔 forEachIndexed 활용해보겠습니다 👍 감사합니다!
fun compareNumber(ball:Int, strike: Int): String { | ||
|
||
var str = "" | ||
if (ball == 0 && strike == 0) { | ||
print("낫싱") | ||
} | ||
else if (ball == 0 && strike > 0) { | ||
print("${strike}스트라이크") | ||
} | ||
else if (strike == 0 && ball > 0) { | ||
print("${ball}볼") | ||
}else{ | ||
print("${ball}볼 ${strike}스트라이크")} | ||
return str | ||
} |
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.
승연님 말씀대로 val str = when() 해서 분기하면 더 좋을 것 같아요!
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.
안녕하세요 은영님!
1주차 고생많으셨습니다ㅎㅎ 2주차도 같이 화이팅해요 🥰🔥
const val START_MESSAGE = "숫자 야구 게임을 시작합니다." | ||
const val INPUT_NUMBER_MESSAGE = "숫자를 입력해주세요 : " | ||
const val THREE_STRIKE_MESSAGE = "3개의 숫자를 모두 맞히셨습니다! 게임 종료" | ||
const val RESTART_MESSAGE = "게임을 새로 시작하려면 1, 종료하려면 2를 입력하세요." |
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 class
를 활용해보셔도 좋을 것 같습니다!
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 class 생각도 못했네요,,..! 좋은 의견 감사합니다 !
if(user.contains(0)) { | ||
throw IllegalArgumentException("1~9 사이의 값을 입력해주세요") | ||
} | ||
if(user.size != 3) { | ||
throw IllegalArgumentException("3자리 수를 입력해주세요") | ||
} | ||
if(user.toSet().size != 3) { | ||
throw IllegalArgumentException("중복 되지 않는 숫자를 입력해주세요") | ||
} | ||
if(user.isEmpty()){ | ||
throw IllegalArgumentException("값을 넣어주세요") | ||
} |
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.
if
문이 3개 이상 사용된다면 when
사용을 고려해보시는건 어떨까요?
if(user[i] !in computer){ | ||
continue | ||
} |
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.
이 조건문은 user[i] 가 computer 에 속하지 않는다면 -> continue
인 것 같아요.
그렇다면 if (user[i] in computer)
에 대한 처리도 필요할 것 같아보입니다!
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.
고려하지 못했던 부분이네요,,감사합니다 👍
No description provided.