[자동차 경주] 정지원 미션 제출합니다. #187
Open
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.
1.
Car.js자동차 객체를 나타내는 클래스
속성
name: 자동차의 이름position: 자동차의 현재 위치 (전진한 횟수)메소드
move()MissionUtils.Random.pickNumberInRange()를 사용하여 0에서 9 사이의 무작위 숫자를 생성합니다.MOVE_THRESHOLD(4) 이상일 경우position을 1 증가시킵니다.getStateString()car1 : ---)2.
Constants.js애플리케이션 전반에서 사용되는 상수 값을 정의
상수
MOVE_THRESHOLD: 자동차가 전진하기 위한 최소 무작위 값 (4)RANDOM_MIN: 무작위 숫자의 최소값 (0)RANDOM_MAX: 무작위 숫자의 최대값 (9)3.
InputView.js사용자 입력을 처리하는 static 메소드를 제공
Static 메소드
readCarNames()MissionUtils.Console.readLineAsync()를 사용하여 "경주할 자동차 이름을 입력하세요."라는 메시지를 출력하고 사용자로부터 자동차 이름을 입력받습니다.readGameRounds()MissionUtils.Console.readLineAsync()를 사용하여 "시도할 횟수는 몇 회인가요?"라는 메시지를 출력하고 사용자로부터 게임 라운드 수를 입력받습니다.4.
OutputView.js게임 결과를 콘솔에 출력하는 static 메소드를 제공
Static 메소드
printWinner(winner)printGameResult(result)printError(message)5.
RacingGame.js자동차 경주 게임의 핵심 로직을 관리하는 클래스
속성
cars:Car객체의 배열생성자
constructor(carNames)Car인스턴스를 생성하고cars배열에 저장합니다.메소드
runRound()cars배열의 모든 자동차에 대해move()메소드를 호출하여 한 라운드를 진행합니다.getRoundResult()getWinners()6.
Validator.js사용자 입력의 유효성을 검사하는 static 메소드를 제공
Static 메소드
validateCarNames(names)null또는undefined인지 확인합니다.validateRounds(rounds)null,undefined, 비어 있는지, 또는 숫자가 아닌지 확인합니다.