-
Notifications
You must be signed in to change notification settings - Fork 3
kmj - 사다리 게임 #3
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
jyami-kim
wants to merge
19
commits into
Java-Bom:kmj
Choose a base branch
from
jyami-kim:kmj
base: kmj
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
kmj - 사다리 게임 #3
Changes from 9 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
022c735
init
jyami-kim b8d5042
setting initial design
jyami-kim 7d62768
ladder game first
jyami-kim 407d2bc
get pillar's bridge location list
jyami-kim 71416cd
create all bridges of pillars
jyami-kim 7247e95
create ladder
jyami-kim 99f90d1
ladder Game
jyami-kim 2f3982b
ladder game complete
jyami-kim 4231c63
after advise
jyami-kim af5586c
constructor edit
jyami-kim c91e1f0
constructor refactoring
jyami-kim 1313b1f
ladder output domain
jyami-kim 0f55070
ladder game complete
jyami-kim a41a8ee
Merge branch 'kmj' into master
jyami-kim 81cf9b4
Merge pull request #8 from mjung1798/master
jyami-kim 90def81
merging
jyami-kim bb6f1f0
[ 수정완료 ]
jyami-kim 09018bf
Merge branch 'master' of https://github.com/mjung1798/ladder-game
jyami-kim 6e2073f
Merge branch 'master' into kmj
jyami-kim 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 was deleted.
Oops, something went wrong.
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,4 +1,18 @@ | ||
| import data.InputData; | ||
| import domain.ladder.Ladder; | ||
| import domain.user.UserManage; | ||
| import view.InputView; | ||
| import view.OutputView; | ||
|
|
||
| public class LadderGame { | ||
|
|
||
| public static void main(String args[]) { | ||
| InputView inputView = new InputView(System.in); | ||
| InputData inputData = new InputData(inputView.participants(), inputView.ladderHeight()); | ||
| Ladder ladder = new Ladder(inputData); | ||
| UserManage userManage = new UserManage(inputData); | ||
| OutputView outputView = new OutputView(userManage, ladder); | ||
| outputView.printLadder(); | ||
| } | ||
|
|
||
| } | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,28 @@ | ||
| package domain.ladder; | ||
|
|
||
| public class Bridge { | ||
| private Integer location; | ||
| private LinkedType linkPillarDirection; | ||
|
|
||
| public Bridge(Integer location, LinkedType linkPillarDirection) { | ||
| this.location = location; | ||
| this.linkPillarDirection = linkPillarDirection; | ||
| } | ||
|
|
||
| public Integer getLocation() { | ||
| return location; | ||
| } | ||
|
|
||
| public LinkedType getLinkPillarDirection() { | ||
| return linkPillarDirection; | ||
| } | ||
|
|
||
| public static Bridge createOneRightBridge(Integer location) { | ||
| return (new Bridge(location, LinkedType.RIGHT)); | ||
| } | ||
|
|
||
| public static Bridge createOneLeftBridge(Integer location) { | ||
| return (new Bridge(location, LinkedType.LEFT)); | ||
| } | ||
|
|
||
| } |
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,51 @@ | ||
| package domain.ladder; | ||
|
|
||
| import dto.GameStartOption; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class Ladder { | ||
|
|
||
| private List<Pillar> pillars; | ||
| private Integer width; | ||
| private Integer height; | ||
|
|
||
| public Ladder(GameStartOption gameStartOption) { | ||
| this.width = gameStartOption.getLadderWidth(); | ||
| this.height = gameStartOption.getLadderHeight(); | ||
| this.pillars = createLadder(gameStartOption); | ||
| } | ||
|
|
||
| private List<Pillar> createLadder(GameStartOption gameStartOption) { | ||
| List<Pillar> pillars = new ArrayList<>(); | ||
| Pillar previous = new Pillar(gameStartOption, null); //팩토리 메소드 패턴 or construction 1개 | ||
| pillars.add(previous); | ||
| for (int i = 1; i < width; i++) { | ||
| Pillar now = new Pillar(gameStartOption, previous); | ||
| pillars.add(now); | ||
| previous = now; | ||
| } | ||
| return pillars; | ||
| } | ||
|
|
||
| public Pillar getPillarByNum(Integer pillarNum) { | ||
| return pillars.stream() | ||
| .filter(p -> p.getPillarNum() == pillarNum) | ||
| .findFirst() | ||
| .orElseThrow(IllegalArgumentException :: new); // optional orElse에 null 던지지 말기 throw Exception | ||
| } | ||
|
|
||
| public List<Pillar> getPillars() { | ||
| return pillars; | ||
| } | ||
|
|
||
| public Integer getWidth() { | ||
| return width; | ||
| } | ||
|
|
||
| public Integer getHeight() { | ||
| return height; | ||
| } | ||
|
|
||
| } |
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,5 @@ | ||
| package domain.ladder; | ||
|
|
||
| public enum LinkedType { | ||
| RIGHT, LEFT | ||
| } |
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,92 @@ | ||
| package domain.ladder; | ||
|
|
||
|
|
||
| import dto.GameStartOption; | ||
|
|
||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static util.RandomIntegerMaker.createRandomIntegers; | ||
| import static util.RandomIntegerMaker.createRandomIntegersWithRestriction; | ||
|
|
||
|
|
||
| public class Pillar { | ||
|
jyami-kim marked this conversation as resolved.
|
||
| public static final int MINIMUM_PILLAR_NUM = 0; | ||
| private List<Bridge> bridges; | ||
| private Integer pillarNum; | ||
|
|
||
| public Pillar(GameStartOption gameStartOption, Pillar previousPillar) { //자동으로 다리생성 | ||
| pillarNum = nowPillarNum(previousPillar); | ||
| bridges = createBridges(gameStartOption, previousPillar); | ||
| } | ||
|
|
||
| public Integer getPillarNum() { | ||
| return pillarNum; | ||
| } | ||
|
|
||
| public List<Bridge> getBridges() { | ||
| return bridges; | ||
| } | ||
|
|
||
| private Integer nowPillarNum(Pillar previousPillar) { | ||
| if (previousPillar == null) | ||
| return MINIMUM_PILLAR_NUM; | ||
| return previousPillar.getPillarNum() + 1; | ||
| } | ||
|
|
||
| public List<Integer> getBridgesLocations() { | ||
| return bridges.stream() | ||
| .map(b -> b.getLocation()) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public List<Integer> getBridgesDirectionLocation(LinkedType linkedType) { | ||
| return bridges.stream() | ||
| .filter(b -> b.getLinkPillarDirection() == linkedType) | ||
| .map(bridge -> bridge.getLocation()) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| private List<Bridge> createBridges(GameStartOption gameStartOption, Pillar previousPillar) { | ||
| if (isFirstPillar(previousPillar)) | ||
| return createRightBridges(createRandomIntegers(gameStartOption.getLadderHeight())); | ||
| if (isLastPillar(gameStartOption, previousPillar)) | ||
| return createLeftBridges(previousPillar); | ||
| return createLeftRightBridges(previousPillar, gameStartOption.getLadderHeight()); | ||
| } | ||
|
|
||
|
|
||
| private boolean isLastPillar(GameStartOption gameStartOption, Pillar previousPillar) { | ||
|
jyami-kim marked this conversation as resolved.
Outdated
|
||
| if (gameStartOption.getLadderWidth() - previousPillar.getPillarNum() == 2) | ||
| return true; | ||
| return false; | ||
| } | ||
|
|
||
| private boolean isFirstPillar(Pillar previousPillar) { | ||
|
jyami-kim marked this conversation as resolved.
Outdated
|
||
| if (previousPillar == null) | ||
| return true; | ||
| return false; | ||
| } | ||
|
|
||
| private List<Bridge> createLeftRightBridges(Pillar previous, Integer height) { | ||
|
jyami-kim marked this conversation as resolved.
Outdated
|
||
| List<Integer> previousLocations = previous.getBridgesDirectionLocation(LinkedType.RIGHT); | ||
|
jyami-kim marked this conversation as resolved.
Outdated
|
||
| List<Bridge> nowPillarsBridges = createLeftBridges(previous); | ||
| List<Integer> rightBridgeNumbers = createRandomIntegersWithRestriction(height, previousLocations); | ||
| nowPillarsBridges.addAll(createRightBridges(rightBridgeNumbers)); | ||
| return nowPillarsBridges; | ||
| } | ||
|
|
||
| private List<Bridge> createRightBridges(List<Integer> locationsOfBridge) { | ||
| return locationsOfBridge.stream() | ||
| .map(b -> Bridge.createOneRightBridge(b)) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
|
|
||
| private List<Bridge> createLeftBridges(Pillar previous) { | ||
| List<Integer> locationsOfBridge = previous.getBridgesDirectionLocation(LinkedType.RIGHT); | ||
| return locationsOfBridge.stream() | ||
| .map(b -> Bridge.createOneLeftBridge(b)) | ||
| .collect(Collectors.toList()); | ||
| } | ||
| } | ||
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 domain.user; | ||
|
|
||
| import dto.GameStartOption; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static util.RandomIntegerMaker.separateUserName; | ||
|
|
||
| public class ParticipantUsers { | ||
| private List<User> users; | ||
|
|
||
| public ParticipantUsers(GameStartOption gameStartOption) { | ||
| this.users = createUser(gameStartOption.getParticipants()); | ||
| } | ||
|
|
||
| public List<User> getUsers() { | ||
| return users; | ||
| } | ||
|
|
||
| private List<User> createUser(String users) { | ||
| return separateUserName(users).stream() | ||
| .map(u -> new User(u)) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public int getUserCharMaxNum() { | ||
| List<Integer> lengths = users.stream() | ||
| .map(u -> u.getName().length()) | ||
| .collect(Collectors.toList()); | ||
| return Collections.max(lengths); | ||
| } | ||
|
|
||
|
|
||
| } |
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,18 @@ | ||
| package domain.user; | ||
|
|
||
| public class User { | ||
|
|
||
| //user's PillarNum 갖고있게 하기, | ||
| //결과 반환하는것 만들기 | ||
|
|
||
| private String name; | ||
|
|
||
| public User(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| } |
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 dto; | ||
|
|
||
| public class GameStartOption { | ||
|
|
||
| public static final String DELIMETER = ","; | ||
|
|
||
| private int ladderWidth; | ||
| private int ladderHeight; | ||
| private String participants; | ||
|
|
||
| public GameStartOption(String participants, int ladderHeight) { | ||
| this.ladderWidth = ladderWidth(participants); | ||
| this.ladderHeight = ladderHeight; | ||
| this.participants = participants; | ||
| } | ||
|
|
||
| private int ladderWidth(String participants) { | ||
| String[] parts = participants.split(DELIMETER); | ||
| return parts.length; | ||
| } | ||
|
|
||
| public String getParticipants() { | ||
| return participants; | ||
| } | ||
|
|
||
| public int getLadderWidth() { | ||
| return ladderWidth; | ||
| } | ||
|
|
||
| public int getLadderHeight() { | ||
| return ladderHeight; | ||
| } | ||
| } |
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,45 @@ | ||
| package util; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.IntStream; | ||
|
|
||
| import static dto.GameStartOption.DELIMETER; | ||
|
|
||
| public class RandomIntegerMaker { | ||
|
|
||
| private RandomIntegerMaker() { | ||
|
|
||
| } | ||
|
|
||
| public static final int MIN_HEIGHT_INDEX = 0; | ||
|
|
||
| public static List<Integer> createRandomIntegers(Integer heights) { | ||
| List<Integer> randoms = IntStream.range(MIN_HEIGHT_INDEX, heights) | ||
| .mapToObj(Integer::new) | ||
| .collect(Collectors.toList()); | ||
| Collections.shuffle(randoms); | ||
|
|
||
| return randoms.stream() | ||
| .limit(randInt(heights)) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public static List<Integer> createRandomIntegersWithRestriction(Integer heights, List<Integer> restrictions) { | ||
| List<Integer> randoms = createRandomIntegers(heights); | ||
| return randoms.stream() | ||
| .filter(i -> !restrictions.contains(i)) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public static List<String> separateUserName(String participants) { | ||
| String[] users = participants.split(DELIMETER); | ||
| return Arrays.asList(users); | ||
| } | ||
|
|
||
| public static Integer randInt(int bound) { | ||
| return (int) (Math.random() * bound + 1); | ||
| } | ||
| } |
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.