-
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 all 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 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 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,28 @@ | ||
| import domain.ladder.Ladder; | ||
| import domain.ladderCalculator.LadderIO; | ||
| import dto.GameStartOption; | ||
| import view.InputView; | ||
| import view.OutputLadder; | ||
|
|
||
| public class LadderGame { | ||
|
|
||
| public static void main(String args[]) { | ||
|
|
||
| InputView inputView = InputView.of(System.in); | ||
| GameStartOption gameStartOption = inputView.initGameStartOption(); | ||
| Ladder ladder = Ladder.of(gameStartOption); | ||
| LadderIO ladderIO = LadderIO.of(gameStartOption); | ||
| OutputLadder ladderPrint = OutputLadder.of(ladderIO, ladder); | ||
|
|
||
| ladderPrint.drawUserNames(); | ||
| ladderPrint.drawOutput(); | ||
| ladderPrint.drawResults(); | ||
|
|
||
| while (true) { | ||
| String ask = inputView.showResultUser(); | ||
| ladderPrint.showLadderResult(ask); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } |
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,26 @@ | ||
| package domain.converter; | ||
|
|
||
| import domain.ladder.Ladder; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class OutputConverter { | ||
| private List<Row> rows = new ArrayList<>(); | ||
|
|
||
| private OutputConverter(Ladder ladder) { | ||
| for (int location = 0; location < ladder.getHeight(); location++) { | ||
| rows.add(Row.of(location, ladder)); | ||
| } | ||
| } | ||
|
|
||
| public static OutputConverter of(Ladder ladder) { | ||
| return new OutputConverter(ladder); | ||
| } | ||
|
|
||
| public List<Row> getRows() { | ||
| return new ArrayList<>(rows); | ||
| } | ||
|
|
||
|
|
||
| } |
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,47 @@ | ||
| package domain.converter; | ||
|
|
||
| import domain.ladder.Bridge; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public class Point implements Comparable<Point> { | ||
| private Integer pillarNum; | ||
| private Bridge bridge; | ||
|
|
||
| private Point(Integer pillarNum, Bridge bridge) { | ||
| this.pillarNum = pillarNum; | ||
| this.bridge = bridge; | ||
| } | ||
|
|
||
| private Point(Integer pillarNum) { | ||
| this.pillarNum = pillarNum; | ||
| } | ||
|
|
||
| public static Point of(Integer pillarNum, Optional<Bridge> bridge) { | ||
| if (bridge.isPresent()) | ||
| return new Point(pillarNum, bridge.get()); | ||
| return new Point(pillarNum); | ||
| } | ||
|
|
||
| public boolean isBlankPoint() { | ||
| return bridge == null; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "pillarNum:" + pillarNum + "/" + "bridge:" + bridge.getLocation(); | ||
| } | ||
|
|
||
| public Integer getPillarNum() { | ||
| return pillarNum; | ||
| } | ||
|
|
||
| public Bridge getBridge() { | ||
| return bridge; | ||
| } | ||
|
|
||
| @Override | ||
| public int compareTo(Point o) { | ||
| return pillarNum.compareTo(o.pillarNum); | ||
| } | ||
| } |
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 domain.converter; | ||
|
|
||
| import domain.ladder.Ladder; | ||
|
|
||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class Row implements Comparable<Row> { | ||
| private Integer location; | ||
| private List<Point> points; | ||
|
|
||
| private Row(Integer location, Ladder ladder) { | ||
| this.location = location; | ||
| this.points = findLocationBridge(ladder); | ||
| } | ||
|
|
||
| public static Row of(Integer location, Ladder ladder) { | ||
| return new Row(location, ladder); | ||
| } | ||
|
|
||
| private List<Point> findLocationBridge(Ladder ladder) { | ||
| return ladder.getPillars().stream() | ||
| .map(pillar -> Point.of(pillar.getPillarNum(), pillar.getLevelBridges(location))) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public Integer getLocation() { | ||
| return location; | ||
| } | ||
|
|
||
| public List<Point> getPoints() { | ||
| return points; | ||
| } | ||
|
|
||
| @Override | ||
| public int compareTo(Row o) { | ||
| return location.compareTo(o.location); | ||
| } | ||
| } |
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 domain.factory; | ||
|
|
||
| import domain.ladder.Bridge; | ||
| import domain.ladder.Pillar; | ||
| import domain.maker.PillarMaker; | ||
| import dto.GameStartOption; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class PillarFactory { | ||
|
|
||
| public static final int MINIMUM_PILLAR_NUM = 0; | ||
|
|
||
| public Pillar createFirstPillar(GameStartOption gameStartOption) { | ||
|
|
||
| List<Bridge> bridges = PillarMaker.of().createBridgesInThisPillar(gameStartOption); | ||
| Integer pillarNum = MINIMUM_PILLAR_NUM; | ||
|
|
||
| return Pillar.of(bridges, pillarNum); | ||
| } | ||
|
|
||
| public Pillar createNotFirstPillar(GameStartOption gameStartOption, Pillar previousPillar) { | ||
|
|
||
| List<Bridge> bridges = PillarMaker.of().createBridgesInThisPillar(gameStartOption, previousPillar); | ||
| Integer pillarNum = nowPillarNum(previousPillar); | ||
|
|
||
| return Pillar.of(bridges, pillarNum); | ||
|
|
||
| } | ||
|
|
||
| private Integer nowPillarNum(Pillar previousPillar) { | ||
| return previousPillar.getPillarNum() + 1; | ||
| } | ||
|
|
||
| } |
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 domain.ladder; | ||
|
|
||
| public class Bridge { | ||
| private Integer location; | ||
| private LinkedType linkPillarDirection; | ||
|
|
||
|
|
||
| private Bridge(Integer location, LinkedType linkPillarDirection) { | ||
| this.location = location; | ||
| this.linkPillarDirection = linkPillarDirection; | ||
| } | ||
|
|
||
| public static Bridge of(Integer location , LinkedType linkPillarDirection){ | ||
| return new Bridge(location, 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,53 @@ | ||
| package domain.ladder; | ||
|
|
||
| import domain.maker.LadderMaker; | ||
| import dto.GameStartOption; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| public class Ladder { | ||
|
|
||
| private List<Pillar> pillars; | ||
| private Integer width; | ||
| private Integer height; | ||
|
|
||
| private Ladder(GameStartOption gameStartOption) { | ||
| this.width = gameStartOption.getLadderWidth(); | ||
| this.height = gameStartOption.getLadderHeight(); | ||
| this.pillars = LadderMaker.of().createLadder(gameStartOption); | ||
| } | ||
|
|
||
| public static Ladder of(GameStartOption gameStartOption) { | ||
| return new Ladder(gameStartOption); | ||
| } | ||
|
|
||
| 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; | ||
| } | ||
|
|
||
| public Pillar getNextPillar(Pillar nowPillar, Integer nowLocation) { | ||
| Optional<Bridge> linkBridge = nowPillar.getLevelBridges(nowLocation); | ||
| if (!linkBridge.isPresent()) | ||
| return nowPillar; | ||
| return linkBridge.get().getLinkPillarDirection() == LinkedType.RIGHT ? | ||
| getPillarByNum(nowPillar.getPillarNum() + 1) : | ||
| getPillarByNum(nowPillar.getPillarNum() - 1); | ||
| } | ||
|
|
||
| } |
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,49 @@ | ||
| package domain.ladder; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class Pillar { | ||
|
|
||
| private List<Bridge> bridges; | ||
| private Integer pillarNum; | ||
|
|
||
| private Pillar(List<Bridge> bridges, Integer pillarNum) { | ||
| this.bridges = bridges; | ||
| this.pillarNum = pillarNum; | ||
| } | ||
|
|
||
| public static Pillar of(List<Bridge> bridges, Integer pillarNum) { | ||
| return new Pillar(bridges, pillarNum); | ||
| } | ||
|
|
||
| public Integer getPillarNum() { | ||
| return pillarNum; | ||
| } | ||
|
|
||
| public List<Bridge> getBridges() { | ||
| return bridges; | ||
| } | ||
|
|
||
|
|
||
| public Optional<Bridge> getLevelBridges(Integer level) { | ||
| return bridges.stream() | ||
| .filter(bridge -> bridge.getLocation().equals(level)) | ||
| .findFirst(); | ||
| } | ||
|
|
||
| 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()); | ||
| } | ||
|
|
||
| } | ||
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.