-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
38 additions
and
9 deletions.
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
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 |
---|---|---|
@@ -1,12 +1,15 @@ | ||
package racingcar | ||
|
||
class InputView { | ||
fun view(): Pair<Int, Int> { | ||
println("자동차 대수는 몇 대인가요?") | ||
val numberOfCars = readLine()!!.toInt() | ||
println("시도할 횟수는 몇 회인가요?") | ||
val count = readLine()!!.toInt() | ||
companion object { | ||
fun view(): Pair<Int, Int> { | ||
println("자동차 대수는 몇 대인가요?") | ||
val numberOfCars = readLine()!!.toInt() | ||
println("시도할 횟수는 몇 회인가요?") | ||
val count = readLine()!!.toInt() | ||
println("실행 결과") | ||
|
||
return numberOfCars to count | ||
return numberOfCars to count | ||
} | ||
} | ||
} |
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 racingcar | ||
|
||
fun main() { | ||
val racingGame = RacingGame() | ||
|
||
val (numberOfCars, count) = InputView.view() | ||
racingGame.set(numberOfCars, count) | ||
|
||
for (i in 1..count) { | ||
racingGame.run() | ||
ResultView.view(racingGame.carList) | ||
} | ||
} |
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 racingcar | ||
|
||
class ResultView { | ||
companion object { | ||
fun view(cars: List<Car>) { | ||
for (car in cars) { | ||
if (car.position == 0) println("x") | ||
else println("-".repeat(car.position)) | ||
} | ||
println() | ||
} | ||
} | ||
} |