From 1d421b9221001f17771efe9dc5f52f4cda94781a Mon Sep 17 00:00:00 2001 From: mediumorange Date: Wed, 1 Nov 2023 22:46:59 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=EA=B2=8C=EC=9E=84=20=EC=A2=85=EB=A3=8C?= =?UTF-8?q?=20=ED=9B=84=20=EC=9A=B0=EC=8A=B9=EC=9E=90=20=EC=B6=9C=EB=A0=A5?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/racingcar/controller/GameController.kt | 5 +++++ src/main/kotlin/racingcar/global/InformationMessage.kt | 3 ++- src/main/kotlin/racingcar/service/CarService.kt | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/racingcar/controller/GameController.kt b/src/main/kotlin/racingcar/controller/GameController.kt index 5be310c30..e114c605f 100644 --- a/src/main/kotlin/racingcar/controller/GameController.kt +++ b/src/main/kotlin/racingcar/controller/GameController.kt @@ -14,6 +14,7 @@ class GameController { createRaceNumber() println() playRace() + gameResult() } fun createCarList() { @@ -32,4 +33,8 @@ class GameController { println(InformationMessage.EXECUTION_RESULT.message) raceService.playRace() } + fun gameResult() { + val winner = carService.getWinner() + println(InformationMessage.FINAL_WINNER.message + winner) + } } \ No newline at end of file diff --git a/src/main/kotlin/racingcar/global/InformationMessage.kt b/src/main/kotlin/racingcar/global/InformationMessage.kt index 88e5cfcd2..141724ae1 100644 --- a/src/main/kotlin/racingcar/global/InformationMessage.kt +++ b/src/main/kotlin/racingcar/global/InformationMessage.kt @@ -3,5 +3,6 @@ package racingcar.global enum class InformationMessage(val message: String) { INPUT_CARS_NAME("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)"), ATTEMPT_NUMBER("시도할 횟수는 몇 회인가요?"), - EXECUTION_RESULT("실행 결과") + EXECUTION_RESULT("실행 결과"), + FINAL_WINNER("최종 우승자 : ") } \ No newline at end of file diff --git a/src/main/kotlin/racingcar/service/CarService.kt b/src/main/kotlin/racingcar/service/CarService.kt index 4795ed802..6fe941e1a 100644 --- a/src/main/kotlin/racingcar/service/CarService.kt +++ b/src/main/kotlin/racingcar/service/CarService.kt @@ -24,4 +24,10 @@ class CarService { if(random >= 4) car.move() } } + + fun getWinner(): String { + val largestNumber = Companion.cars.maxOf(Car::location) + return Companion.cars.filter { it.location == largestNumber } + .joinToString(separator = ", ") { car -> car.name } + } } \ No newline at end of file