forked from woowacourse/kotlin-racingcar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RaceGame.kt
32 lines (27 loc) · 912 Bytes
/
RaceGame.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package controller
import model.Cars
import util.CarsHelper
import view.InputView
import view.OutputView
class RaceGame(private val outputView: OutputView, private val inputView: InputView) {
fun run() {
outputView.outputCarNames()
val cars = executeInputCarNames()
outputView.outputTryNumber()
val tryNumber = executeInputTryNumber()
outputView.outputResults()
repeat(tryNumber) {
tryMove(cars)
}
outputView.outputWinners(CarsHelper.findWinners(cars))
}
private fun tryMove(cars: Cars) {
repeat(cars.getCarSize()) {
cars.move(it)
outputView.outputResult(cars.getCar(it))
}
outputView.outputNextLine()
}
private fun executeInputTryNumber(): Int = inputView.inputTryNumber().toInt()
private fun executeInputCarNames(): Cars = Cars(inputView.inputCarNames())
}