forked from next-step/java-ladder
-
Notifications
You must be signed in to change notification settings - Fork 0
#step2 PR #5
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
Open
impactrudia
wants to merge
26
commits into
rudiamoon_study
Choose a base branch
from
rudiamoon_step2
base: rudiamoon_study
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
#step2 PR #5
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
50533b8
Initial 해야할 일 작성
impactrudia c2427fc
Add 프로젝트 구조 생성
impactrudia 3eabb9e
Test 플레이어_이름이_5글자_넘는_경우
impactrudia acd2e92
Test 라인겹치는 경우와 안 겹치는 경우
impactrudia 5a1f9c9
Test 사다리 한줄 생성
impactrudia b0eef9b
Test 문자열을_쉽표로_구분할때_사람_명수
impactrudia 62c9f54
사다리 인원 출력
impactrudia ed1f7b4
Add 사다리 출력
impactrudia 0b54be4
Refactor StringUtils함수사용, 공백제거
impactrudia a920066
Add 입력하는것 결과 텍스트
impactrudia 6092c51
Update 당첨결과
impactrudia b3e6bc1
step2 중간 구현
47776fc
# add : 결과확인 기능 구현중
willing1026 113231c
Update 라인진행중
impactrudia e80745c
step2 결과 구하기
2ffd68d
# add : 결과확인 기능 구현중
willing1026 3e3740e
Update 일단 완성 리팩토링 필요
impactrudia 2d1c563
Update 리팩토링 구조 변경
impactrudia 928efca
Update results List<String>형태로 변환
impactrudia 4cec062
Create LadderGameMapper
impactrudia 560ebfb
Modify : 결과Mapper 구현중
willing1026 ee14b60
중간구현
7bda094
Update 실행결과 all
impactrudia 7c044ee
Modify : 결과공백문제 해결
willing1026 a459186
결과값 반복 구현
301eb83
Udpate pushtest
impactrudia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,5 +1,6 @@ | ||
| #Fri Jul 05 20:59:43 KST 2019 | ||
| distributionBase=GRADLE_USER_HOME | ||
| distributionPath=wrapper/dists | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip | ||
| zipStoreBase=GRADLE_USER_HOME | ||
| zipStorePath=wrapper/dists | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip |
This file contains hidden or 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,39 @@ | ||
| package nextstep.main; | ||
|
|
||
| import nextstep.main.utils.CommonUtils; | ||
| import nextstep.main.view.InputView; | ||
| import nextstep.main.view.ResultView; | ||
| import nextstep.main.vo.Ladder; | ||
| import nextstep.main.vo.LadderGameMapper; | ||
| import nextstep.main.vo.Persons; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static nextstep.main.utils.Consts.ALL_PERSON; | ||
|
|
||
| public class ConsoleMain { | ||
| public static void main(String[] args) { | ||
| String playersName = InputView.playerNames(); | ||
| String playerResults = InputView.ladderResultPreDiction(); | ||
|
|
||
| int ladderHeight = InputView.maxLadderHeight(); | ||
|
|
||
| Persons persons = Persons.generate(playersName); | ||
| List<String> results = CommonUtils.generates(playerResults); | ||
|
|
||
| Ladder ladder = new Ladder(); | ||
| ladder.generateLadder(ladderHeight, persons.getPersonCount()); | ||
|
|
||
| ResultView.executeNames(persons); | ||
| ResultView.drawLadder(ladder); | ||
| ResultView.executeResults(results); | ||
|
|
||
| LadderGameMapper ladderGameMapper = persons.settingResult(ladder, results); | ||
| String personName = ""; | ||
| while (!ALL_PERSON.equals(personName)) { | ||
| personName = InputView.personResult(); | ||
| String result = ladderGameMapper.getResult(personName, persons); | ||
| ResultView.textResultPerson(result); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,25 @@ | ||
| package nextstep.main.utils; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.IntStream; | ||
|
|
||
| public class CommonUtils {//push test | ||
| public static String[] split(String value) { | ||
| return value.split(Consts.NAME_SEPARATOR); | ||
| } | ||
|
|
||
| public static List<String> generates(String names) { | ||
| return Arrays.stream(split(names)) | ||
| .map(String::new) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public static String arrangeName(String value) { | ||
| String str = IntStream.range(0, Consts.MAX_NAME_COUNT - value.length()) | ||
| .mapToObj(i -> " ") | ||
| .collect(Collectors.joining("", value, " ")); | ||
| return str; | ||
| } | ||
| } |
This file contains hidden or 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,7 @@ | ||
| package nextstep.main.utils; | ||
|
|
||
| public class Consts { | ||
| public static final String NAME_SEPARATOR = ","; | ||
| public static final String ALL_PERSON = "getResult"; | ||
| public static final int MAX_NAME_COUNT = 5; | ||
| } |
This file contains hidden or 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,29 @@ | ||
| package nextstep.main.view; | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| public class InputView { | ||
| public static String playerNames() { | ||
| System.out.println("참여할 사람 이름을 입력하세요. (이름은 쉼표(,)로 구분하세요)"); | ||
| Scanner scanner = new Scanner(System.in); | ||
| return scanner.nextLine(); | ||
| } | ||
|
|
||
| public static String ladderResultPreDiction() { | ||
| System.out.println("실행 결과를 입력하세요. (결과는 쉼표(,)로 구분하세요)"); | ||
| Scanner scanner = new Scanner(System.in); | ||
| return scanner.nextLine(); | ||
| } | ||
|
|
||
| public static int maxLadderHeight() { | ||
| System.out.println("최대 사다리 높이는 몇 개인가요?"); | ||
| Scanner scanner = new Scanner(System.in); | ||
| return scanner.nextInt(); | ||
| } | ||
|
|
||
| public static String personResult() { | ||
| System.out.println("결과를 보고 싶은 사람은?"); | ||
| Scanner scanner = new Scanner(System.in); | ||
| return scanner.nextLine(); | ||
| } | ||
| } |
This file contains hidden or 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,33 @@ | ||
| package nextstep.main.view; | ||
|
|
||
| import nextstep.main.utils.CommonUtils; | ||
| import nextstep.main.vo.Ladder; | ||
| import nextstep.main.vo.Persons; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class ResultView { | ||
| public static void executeNames(Persons persons) { | ||
| System.out.println("사다리 결과"); | ||
|
|
||
| persons.getPersons() | ||
| .forEach(System.out::print); | ||
|
|
||
| System.out.println(); | ||
| } | ||
|
|
||
| public static void drawLadder(Ladder ladder) { | ||
| ladder.getLines() | ||
| .forEach(System.out::println); | ||
| } | ||
|
|
||
| public static void executeResults(List<String> results) { | ||
| results.forEach(name -> System.out.print(CommonUtils.arrangeName(name))); | ||
| System.out.println(); | ||
| } | ||
|
|
||
| public static void textResultPerson(String result) { | ||
| System.out.println("실행 결과"); | ||
| System.out.println(result); | ||
| } | ||
| } |
This file contains hidden or 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,35 @@ | ||
| package nextstep.main.vo; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.stream.IntStream; | ||
|
|
||
| public class Ladder { | ||
| private List<Line> lines; | ||
|
|
||
| public Ladder() { | ||
| this.lines = new ArrayList<>(); | ||
| } | ||
|
|
||
| public int generateLadder(int ladderHeight, int playerCount) { | ||
| IntStream.range(0, ladderHeight) | ||
| .mapToObj(item -> new Line(playerCount)) | ||
| .forEach(line -> this.lines.add(line)); | ||
|
|
||
| return this.lines.size(); | ||
| } | ||
|
|
||
| public List<Line> getLines() { | ||
| return this.lines; | ||
| } | ||
|
|
||
| public int getResult(int position) { | ||
| int currentPosition = position; | ||
|
|
||
| for (int i = 0; i < lines.size(); i++) { | ||
| currentPosition = lines.get(i).getPlusMinusPosition(currentPosition); | ||
| } | ||
|
|
||
| return currentPosition; | ||
| } | ||
| } |
This file contains hidden or 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,36 @@ | ||
| package nextstep.main.vo; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| import static nextstep.main.utils.Consts.ALL_PERSON; | ||
|
|
||
| public class LadderGameMapper { | ||
| private List<String> results; | ||
|
|
||
| public LadderGameMapper(List<String> results) { | ||
| this.results = results; | ||
| } | ||
|
|
||
| public static LadderGameMapper generate(List<String> userResults) { | ||
| return new LadderGameMapper(userResults); | ||
| } | ||
|
|
||
| public String findResult(int index) { | ||
| return Optional.ofNullable(results.get(index)) | ||
| .orElse("참여자 이름이 잘못됐습니다."); | ||
| } | ||
|
|
||
| public String getResult(String personName, Persons persons) { | ||
| if (ALL_PERSON.equals(personName)) { | ||
| List<Person> person = persons.getPersons(); | ||
| StringBuilder sb = new StringBuilder(); | ||
| for (int i = 0; i < person.size(); i++) { | ||
| sb.append(person.get(i).toString().trim() + " : " + results.get(i)); | ||
| sb.append("\n"); | ||
| } | ||
| return sb.toString(); | ||
| } | ||
| return findResult(persons.findIndexByName(personName)); | ||
| } | ||
| } |
This file contains hidden or 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,94 @@ | ||
| package nextstep.main.vo; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Random; | ||
| import java.util.stream.IntStream; | ||
|
|
||
| public class Line { | ||
| private static final int START_POINT = 0; | ||
| public static final String VERTICAL = "|"; | ||
| public static final int HORIZONTAL_SIZE = 5; | ||
| public static final String DASH = "-"; | ||
| public static final String EMPTY = " "; | ||
|
|
||
| private List<Boolean> points; | ||
|
|
||
| Line(int countOfPerson) { | ||
| generateLine(countOfPerson); | ||
| } | ||
|
|
||
| private int generateLine(int countOfPerson) { | ||
| points = new ArrayList<>(); | ||
|
|
||
| IntStream.range(0, numberOfPoints(countOfPerson)) | ||
| .forEach(i -> points.add(generateCurrentPoint(i))); | ||
|
|
||
| return points.size(); | ||
| } | ||
|
|
||
| private static int numberOfPoints(int countOfPerson) { | ||
| return countOfPerson - 1; | ||
| } | ||
|
|
||
| private boolean generateCurrentPoint(int newPosition) { | ||
| boolean point = new Random().nextBoolean(); | ||
|
|
||
| if (isOverLapped(newPosition, point)) { | ||
| point = !point; | ||
| } | ||
|
|
||
| return point; | ||
| } | ||
|
|
||
| private boolean isOverLapped(int currPosition, boolean newPoint) { | ||
| if (currPosition == START_POINT) | ||
| return false; | ||
|
|
||
| return isEqual(points.get(currPosition - 1), newPoint); | ||
| } | ||
|
|
||
| static boolean isEqual(boolean prevPoint, boolean newPoint) { | ||
| return prevPoint == newPoint; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| final StringBuilder str = new StringBuilder(" |"); | ||
|
|
||
| points.forEach(isLine -> str.append(pointToString(isLine))); | ||
|
|
||
| return str.toString(); | ||
| } | ||
|
|
||
| private String pointToString(boolean isLine) { | ||
| if (isLine) { | ||
| return StringUtils.leftPad(VERTICAL, HORIZONTAL_SIZE, DASH); | ||
| } | ||
|
|
||
| return StringUtils.leftPad(VERTICAL, HORIZONTAL_SIZE, EMPTY); | ||
| } | ||
|
|
||
| public int getPlusMinusPosition(int currentPosition) { | ||
| if (currentPosition == 0) { | ||
| return points.get(0) ? currentPosition + 1 : currentPosition; | ||
| } | ||
|
|
||
| if (currentPosition == points.size()) { | ||
| return points.get(currentPosition - 1) ? currentPosition - 1 : currentPosition; | ||
| } | ||
|
|
||
| if (points.get(currentPosition)) { | ||
| return currentPosition + 1; | ||
| } | ||
|
|
||
|
|
||
| if (points.get(currentPosition - 1)) { | ||
| return currentPosition - 1; | ||
| } | ||
|
|
||
| return currentPosition; | ||
| } | ||
| } | ||
This file contains hidden or 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,24 @@ | ||
| package nextstep.main.vo; | ||
|
|
||
| import nextstep.main.utils.CommonUtils; | ||
| import nextstep.main.utils.Consts; | ||
|
|
||
| public class Person { | ||
| private String name; | ||
|
|
||
| public Person(String name) { | ||
| if (name.length() > Consts.MAX_NAME_COUNT) | ||
| throw new IllegalArgumentException(); | ||
|
|
||
| this.name = name; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return CommonUtils.arrangeName(this.name); | ||
| } | ||
|
|
||
| public boolean isMatch(String personName) { | ||
| return name.equals(personName); | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.