Skip to content
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

[둘리] 2단계 자동차 경주 제출합니다. #68

Merged
merged 12 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(Cars,RaceGame): 랜덤값 생성 로직을 RaceGame으로 이동
  • Loading branch information
hyemdooly committed Feb 13, 2023
commit b6834c8622c8a859b0f4f1f9380d280a96e15ba9
3 changes: 2 additions & 1 deletion src/main/kotlin/controller/RaceGame.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package controller

import generator.RandomGenerator
import model.Cars
import util.CarsHelper
import view.InputView
Expand All @@ -21,7 +22,7 @@ class RaceGame(private val outputView: OutputView, private val inputView: InputV

private fun tryMove(cars: Cars) {
repeat(cars.getCarSize()) {
cars.move(it)
cars.move(it, RandomGenerator().getRandomNumber())
outputView.outputResult(cars.getCar(it))
}
outputView.outputNextLine()
Expand Down
6 changes: 2 additions & 4 deletions src/main/kotlin/model/Cars.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package model

import generator.RandomGenerator

class Cars(cars: List<Car>) {
private val _cars: List<Car> = cars
val cars: List<Car> get() = _cars
Expand All @@ -10,7 +8,7 @@ class Cars(cars: List<Car>) {

fun getCar(index: Int): Car = _cars[index]
fun getCarSize(): Int = _cars.size
fun move(index: Int) {
_cars[index].move(RandomGenerator().getRandomNumber())
fun move(index: Int, condition: Int) {
_cars[index].move(condition)
}
}