-
Notifications
You must be signed in to change notification settings - Fork 50
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
[둘리] 1, 2단계 오목 제출합니다. #26
Merged
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
fe3ce07
docs: 오목 기능 목록 작성
tmdgh1592 ca4182c
feat: 1부터 15 위치를 가진 오목알 클래스 구현
tmdgh1592 e13e7da
feat: 중복 오목알 처리를 위한 오목알 일급 컬렉션 구현
tmdgh1592 fa5e2b9
docs: .gitkeep 파일 제거
tmdgh1592 0c398fd
feat: 오목알을 놓은 플레이어가 게임에서 이겼는지 확인하는 기능 구현
tmdgh1592 190d007
feat: 사용자가 오목알을 놓았을 때 상태를 반환하는 기능 구현
tmdgh1592 9d0c276
feat: 오목판에 돌을 올려놓는 기능 구현
tmdgh1592 606cfcf
feat: 플레이어의 오목알을 놓는 턴을 바꾸는 기능 구현
tmdgh1592 f96746e
refactor: 돌을 놓으면 새로운 상태를 가진 플레이어 반환하는 기능 구현
tmdgh1592 e5e8ce4
feat: 플레이어가 놓은 마지막 돌을 리턴하는 기능 구현
tmdgh1592 c472a31
refactor: 오목알을 놓을 수 있는지 확인하는 함수를 Players 클래스로 이동
tmdgh1592 f4f1b15
feat: 오목 게임 진행하는 기능 구현
tmdgh1592 28bb0cd
feat: 오목 게임 입력, 출력 화면 구현
tmdgh1592 f37f93b
feat: 오목 컨트롤러 구현
tmdgh1592 b1fcb5b
refactor: 도메인 패키지 분리
tmdgh1592 11b2666
fix: 중간에 오목알을 뒀을 때 승리 판정하지 않는 오류 수정
tmdgh1592 a0166e0
feat: 렌주룰 기능 추가 (미완성)
tmdgh1592 7eb0bc9
feat: 렌주룰 적용 (완성)
tmdgh1592 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: 오목 게임 입력, 출력 화면 구현
- Loading branch information
commit 28bb0cd59841850f221d69b1df1039481489369a
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import controller.OmokController | ||
|
||
fun main() { | ||
OmokController().start() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package listener | ||
|
||
import domain.Position | ||
import domain.StoneColor | ||
import domain.player.Players | ||
|
||
interface OmokStartEndEventListener { | ||
fun onStartTurn(stoneColor: StoneColor, position: Position) | ||
fun onEndTurn(players: Players) | ||
fun onStartGame() | ||
fun onEndGame(stoneColor: StoneColor) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package listener | ||
|
||
import domain.Position | ||
import domain.StoneColor | ||
|
||
interface OmokTurnEventListener { | ||
fun onTakeTurn(stoneColor: StoneColor): Position | ||
fun onNotPlaceable() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package view | ||
|
||
import domain.Position | ||
|
||
object BoardModel { | ||
private const val RANGE_MIN = 'A' | ||
private const val RANGE_MAX = 'O' | ||
|
||
private val range = (RANGE_MIN..RANGE_MAX).toList() | ||
fun getString(position: Position) = range[position.col] + (Position.POSITION_RANGE.max() - position.row).toString() | ||
fun getColInt(col: String) = range.indexOf(col.toCharArray()[0]) + 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package view | ||
|
||
import domain.StoneColor | ||
|
||
object ColorModel { | ||
private const val BLACK = "흑" | ||
private const val WHITE = "백" | ||
|
||
fun getString(color: StoneColor): String = when (color) { | ||
StoneColor.BLACK -> BLACK | ||
StoneColor.WHITE -> WHITE | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package view | ||
|
||
import domain.Position | ||
import domain.Position.Companion.POSITION_RANGE | ||
import domain.StoneColor | ||
import listener.OmokTurnEventListener | ||
|
||
class InputView : OmokTurnEventListener { | ||
override fun onTakeTurn(stoneColor: StoneColor): Position = askPosition() | ||
|
||
override fun onNotPlaceable() { | ||
reAskPosition(CANT_PLACE_STONE_ERROR_MESSAGE) | ||
} | ||
|
||
private fun askPosition(): Position { | ||
print(ASK_POSITION_MESSAGE) | ||
val input = readln() | ||
if (input.length !in POSITION_INPUT_RANGE) | ||
return reAskPosition(INVALID_FORMAT_ERROR_MESSAGE) | ||
|
||
val col = BoardModel.getColInt(input.first().toString()) | ||
val row = input.substring(ROW_INPUT_SIZE).toIntOrNull() | ||
if (row == null || row !in POSITION_RANGE || col !in POSITION_RANGE) | ||
return reAskPosition(INVALID_FORMAT_ERROR_MESSAGE) | ||
return Position(row, col) | ||
} | ||
|
||
private fun reAskPosition(message: String): Position { | ||
println(message) | ||
return askPosition() | ||
} | ||
|
||
companion object { | ||
private const val ASK_POSITION_MESSAGE = "위치를 입력하세요: " | ||
private const val INVALID_FORMAT_ERROR_MESSAGE = "포맷에 맞지 않는 입력값입니다." | ||
private const val CANT_PLACE_STONE_ERROR_MESSAGE = "해당 위치에는 오목알을 둘 수 없습니다." | ||
private const val MIN_POSITION_INPUT_SIZE = 2 | ||
private const val MAX_POSITION_INPUT_SIZE = 3 | ||
private val POSITION_INPUT_RANGE = MIN_POSITION_INPUT_SIZE..MAX_POSITION_INPUT_SIZE | ||
private const val ROW_INPUT_SIZE = 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package view | ||
|
||
import domain.Position | ||
import domain.StoneColor | ||
import domain.player.Players | ||
import listener.OmokStartEndEventListener | ||
|
||
class OutputView : OmokStartEndEventListener { | ||
override fun onStartGame() { | ||
printStart() | ||
} | ||
|
||
override fun onEndGame(stoneColor: StoneColor) { | ||
printWinner(stoneColor) | ||
} | ||
|
||
override fun onStartTurn(stoneColor: StoneColor, position: Position) { | ||
printTurn(stoneColor, position) | ||
} | ||
|
||
override fun onEndTurn(players: Players) { | ||
printOmokBoard(players) | ||
} | ||
|
||
private fun printStart() { | ||
println(START_MESSAGE) | ||
println(EMPTY_BOARD) | ||
println(TURN_MESSAGE.format(ColorModel.getString(StoneColor.BLACK))) | ||
} | ||
|
||
private fun printOmokBoard(players: Players) { | ||
val board = EMPTY_BOARD.toMutableList() | ||
|
||
players.getBlackPlayer().getPositions().forEach { | ||
board[calculateIndex(it)] = BLACK_STONE | ||
} | ||
players.getWhitePlayer().getPositions().forEach { | ||
board[calculateIndex(it)] = WHITE_STONE | ||
} | ||
println(board.joinToString(separator = "")) | ||
} | ||
|
||
private fun calculateIndex(position: Position): Int = 721 + 3 * position.col - 48 * position.row | ||
|
||
private fun printTurn(stoneColor: StoneColor, position: Position) { | ||
print(TURN_MESSAGE.format(ColorModel.getString(stoneColor))) | ||
println(LAST_STONE_POSITION_MESSAGE.format(BoardModel.getString(position))) | ||
} | ||
|
||
private fun printWinner(stoneColor: StoneColor) { | ||
println(GAME_END_MESSAGE) | ||
println(WINNER_MESSAGE.format(ColorModel.getString(stoneColor))) | ||
} | ||
|
||
companion object { | ||
private const val START_MESSAGE = "오목 게임을 시작합니다." | ||
private const val TURN_MESSAGE = "%s의 차례입니다. " | ||
private const val LAST_STONE_POSITION_MESSAGE = "(마지막 돌의 위치: %s)" | ||
private const val GAME_END_MESSAGE = "게임이 종료되었습니다." | ||
private const val WINNER_MESSAGE = "%s의 승리입니다." | ||
private val EMPTY_BOARD: String = """ | ||
| 15 ┌──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┐ | ||
| 14 ├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤ | ||
| 13 ├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤ | ||
| 12 ├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤ | ||
| 11 ├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤ | ||
| 10 ├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤ | ||
| 9 ├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤ | ||
| 8 ├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤ | ||
| 7 ├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤ | ||
| 6 ├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤ | ||
| 5 ├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤ | ||
| 4 ├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤ | ||
| 3 ├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤ | ||
| 2 ├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤ | ||
| 1 └──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┘ | ||
| A B C D E F G H I J K L M N O | ||
""".trimMargin() | ||
private const val BLACK_STONE = '●' | ||
private const val WHITE_STONE = '○' | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
InputView가 로직에 대한 처리를 너무 자세하게 알고 있지는 않을까요?
행과, 열에 해당하는 위치를 만드는 것은 Position 객체가 해야할 책임으로 볼 수 있지 않을까요?
논리적인 오류가 아니라면 null을 반환하도록 만들어 볼 수 있겠습니다.
https://medium.com/@galcyurio/kotlin%EC%97%90%EC%84%9C%EC%9D%98-%EC%98%88%EC%99%B8-%EC%B2%98%EB%A6%AC-%EB%B0%A9%EB%B2%95-48a5cd94a4e6