-
Notifications
You must be signed in to change notification settings - Fork 13
[BE] λμμ° πμ λ€μ΄ #1
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
ay-eonii
wants to merge
26
commits into
Leets-Official:ay-eonii
Choose a base branch
from
ay-eonii:main
base: ay-eonii
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
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
955e49d
docs(README): κΈ°λ₯ μꡬμ¬ν μμ±
ay-eonii f56e7e1
feat(GuessNumber): μΆμΈ‘κ° λλ©μΈ
ay-eonii 95beeea
feat(AnswerNumber): μΆμΈ‘κ°κ³Ό μ λ΅μ λΉκ΅νλ λ©μλ
ay-eonii 8fa5b88
feat(Status): μΆμΈ‘κ°μ κΈ°μ€μΌλ‘ κ°μ§λ μν λλ©μΈ μμ±
ay-eonii 26c9ac8
refactor(GuessStatus): ν¨ν€μ§ μ΄λ
ay-eonii fbb3e37
feat(Status): μ’
λ£ μ¬λΆ λ©μλ
ay-eonii 19f2b1a
feat(RandomNumberGenerator): λλ€ μ μμ±
ay-eonii 3a75db9
feat(InputView): μΆμΈ‘κ° μ
λ ₯λ°κΈ°
ay-eonii 032f9e9
feat(GameMachine): κ²μ μ€ν
ay-eonii 919196c
feat(GuessRange): μΆμΈ‘κ° λ²μ λλ©μΈ
ay-eonii 193e48c
feat(OutputView): μΆμΈ‘κ° νμ κ²°κ³Ό μΆλ ₯
ay-eonii 101d5ae
refactor(Status): λ²μ κ²μ¬ λ° λ²μ μ¬μ μ μν Statusμ μμ
ay-eonii e66ff5f
fix(GameMachine): λ²μ λ³κ²½λλλ‘ μμ
ay-eonii 45eed1f
refactor(GameMachine): λ°λ³΅ μ¬κ·λ‘ νΈμΆ
ay-eonii de95d7b
fix(InputView): μλͺ»λ μ
λ ₯ μμΈ μ²λ¦¬
ay-eonii 4aeee30
feat(UpDownGame): λλ©μΈ λΆλ¦¬
ay-eonii 2ae19ba
fix(UpDownGame): λΆνμν μ½λ μμ
ay-eonii 5925870
docs(README): κΈ°λ₯ μꡬ μ¬ν μλ£ μ²΄ν¬
ay-eonii 25502f8
refactor(GuessRange): λ©μλ μμ λ³κ²½
ay-eonii 0a0cc73
feat(UpDownGame): UpDownGame μΈν°νμ΄μ€ ꡬνν AlphabetUpDownGame μμ±
ay-eonii 9fb43f2
feat(GuessValue): GuessValue μΈν°νμ΄μ€ ꡬνν GuessAlphabet μΆκ°
ay-eonii 148ae53
refactor(All): κ²μκ³Ό μΆμΈ‘μΌλ‘ ν¨ν€μ§ λΆλ¦¬
ay-eonii 65da7d3
refactor(AlphabetGameMachine): μμ΄ κ²μ λΆλ¦¬
ay-eonii 82eaf45
feat(GameLoader): κ²μ λ²μ μ ν
ay-eonii 2799a40
refactor(RandomAlphabetGenerator): μλ¬Έμ λ³ν api μ¬μ©
ay-eonii ffb1a7e
refactor(AlphabetGameMachine): GuessValue λμ GuessAlphabet μ¬μ©
ay-eonii 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| ## κΈ°λ₯ μꡬ μ¬ν | ||
|
|
||
| **λ²μ ** | ||
|
|
||
| - [ ] μ«μ λ²μ μ 1λ²μ΄λ€. | ||
| - [ ] μμ΄ λ²μ μ 2λ²μ΄λ€. | ||
|
|
||
| **λμ** | ||
|
|
||
| - [x] μ«μ λ²μ μ 1 ~ 100 μ¬μ΄μ μ λ΅μ κ°μ§λ€. | ||
| - [ ] μμ΄ λ²μ μ A ~ z μ¬μ΄μ μ λ΅μ κ°μ§λ€. | ||
|
|
||
| **μ λ΅** | ||
|
|
||
| - [x] μΆμΈ‘κ°κ³Ό μ λ΅μ λΉκ΅νλ€. | ||
| - [x] κ²μ μνλ₯Ό λ°ννλ€. | ||
|
|
||
| **κ²μ μν** | ||
|
|
||
| - [x] μΆμΈ‘κ°μ΄ μ λ΅λ³΄λ€ μμ κ²½μ° UP μνμ΄λ€. | ||
| - [x] μΆμΈ‘κ°μ΄ μ λ΅λ³΄λ€ ν° κ²½μ° DOWN μνμ΄λ€. | ||
| - [x] μΆμΈ‘κ°μ΄ μ λ΅κ³Ό μΌμΉνλ κ²½μ° CORRECT μνμ΄λ€. | ||
|
|
||
| **μλ νμ** | ||
|
|
||
| - [ ] μ¬μ©μκ° μ λ΅μ λ§μΆ λκΉμ§ μλν νμλ₯Ό μΆλ ₯νλ€ | ||
| - μλͺ»λ κ° μ λ ₯ μμ μλν νμμ ν¬ν¨ λμ΄μΌ νλ€. | ||
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,8 +1,11 @@ | ||
| package leets.land; | ||
|
|
||
| import leets.land.controller.GameLoader; | ||
|
|
||
| public class UpdownApplication { | ||
|
|
||
| public static void main(String[] args) { | ||
| System.out.print("hihi :D"); | ||
| } | ||
| public static void main(String[] args) { | ||
| GameLoader gameLoader = new GameLoader(); | ||
| gameLoader.load(); | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
src/main/java/leets/land/controller/AlphabetGameMachine.java
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,41 @@ | ||
| package leets.land.controller; | ||
|
|
||
| import leets.land.domain.guess.GuessAlphabet; | ||
| import leets.land.domain.guess.GuessRange; | ||
| import leets.land.domain.status.GuessStatus; | ||
| import leets.land.domain.updowngame.AlphabetUpDownGame; | ||
| import leets.land.domain.updowngame.UpDownGame; | ||
| import leets.land.view.InputView; | ||
| import leets.land.view.OutputView; | ||
|
|
||
| public class AlphabetGameMachine implements GameMachine { | ||
|
|
||
| private final InputView inputView = new InputView(); | ||
| private final OutputView outputView = new OutputView(); | ||
|
|
||
| @Override | ||
| public void run() { | ||
| UpDownGame upDownGame = new AlphabetUpDownGame(); | ||
| play(upDownGame); | ||
| } | ||
|
|
||
| private void play(UpDownGame upDownGame) { | ||
| GuessAlphabet guessAlphabet = readGuessAlphabetInRange(upDownGame.guessRange()); | ||
| GuessStatus guessStatus = upDownGame.play(guessAlphabet); | ||
| outputView.printGuessStatus(guessStatus); | ||
| if (guessStatus.isContinue()) { | ||
| play(upDownGame); | ||
| } | ||
| } | ||
|
|
||
| private GuessAlphabet readGuessAlphabetInRange(GuessRange guessRange) { | ||
| try { | ||
| int guessValue = inputView.readGuessAlphabetInRange(guessRange.min(), guessRange.max()); | ||
| guessRange.checkRange(guessValue); | ||
| return new GuessAlphabet(guessValue); | ||
| } catch (IllegalArgumentException e) { | ||
| System.out.println(e.getMessage()); | ||
| return readGuessAlphabetInRange(guessRange); | ||
| } | ||
| } | ||
| } |
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,19 @@ | ||
| package leets.land.controller; | ||
|
|
||
| import leets.land.domain.GameVersion; | ||
| import leets.land.view.InputView; | ||
|
|
||
| public class GameLoader { | ||
|
|
||
| private final InputView inputView = new InputView(); | ||
|
|
||
| public void load() { | ||
| GameVersion gameVersion = readGameVersion(); | ||
| gameVersion.start(); | ||
| } | ||
|
|
||
| private GameVersion readGameVersion() { | ||
| int gameVersion = inputView.readGameVersion(); | ||
| return GameVersion.match(gameVersion); | ||
| } | ||
| } |
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,6 @@ | ||
| package leets.land.controller; | ||
|
|
||
| public interface GameMachine { | ||
|
|
||
| void run(); | ||
| } |
41 changes: 41 additions & 0 deletions
41
src/main/java/leets/land/controller/NumberGameMachine.java
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,41 @@ | ||
| package leets.land.controller; | ||
|
|
||
| import leets.land.domain.guess.GuessNumber; | ||
| import leets.land.domain.guess.GuessRange; | ||
| import leets.land.domain.status.GuessStatus; | ||
| import leets.land.domain.updowngame.NumberUpDownGame; | ||
| import leets.land.domain.updowngame.UpDownGame; | ||
| import leets.land.view.InputView; | ||
| import leets.land.view.OutputView; | ||
|
|
||
| public class NumberGameMachine implements GameMachine { | ||
|
|
||
| private final InputView inputView = new InputView(); | ||
| private final OutputView outputView = new OutputView(); | ||
|
|
||
| @Override | ||
| public void run() { | ||
| UpDownGame upDownGame = new NumberUpDownGame(); | ||
| play(upDownGame); | ||
| } | ||
|
|
||
| private void play(UpDownGame upDownGame) { | ||
| GuessNumber guessNumber = readGuessNumberInRange(upDownGame.guessRange()); | ||
| GuessStatus guessStatus = upDownGame.play(guessNumber); | ||
| outputView.printGuessStatus(guessStatus); | ||
| if (guessStatus.isContinue()) { | ||
| play(upDownGame); | ||
| } | ||
| } | ||
|
|
||
| private GuessNumber readGuessNumberInRange(GuessRange guessRange) { | ||
| try { | ||
| int guessNumber = inputView.readGuessNumberInRange(guessRange.min(), guessRange.max()); | ||
| guessRange.checkRange(guessNumber); | ||
| return new GuessNumber(guessNumber); | ||
| } catch (IllegalArgumentException e) { | ||
| System.out.println(e.getMessage()); | ||
| return readGuessNumberInRange(guessRange); | ||
| } | ||
| } | ||
| } |
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 leets.land.domain; | ||
|
|
||
| import leets.land.domain.guess.GuessValue; | ||
| import leets.land.domain.status.GuessStatus; | ||
|
|
||
| public class AnswerNumber { | ||
|
|
||
| private final int value; | ||
|
|
||
| public AnswerNumber(int value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| public GuessStatus compare(GuessValue guessValue) { | ||
| int compared = guessValue.compare(value); | ||
| return GuessStatus.match(compared); | ||
| } | ||
| } |
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,32 @@ | ||
| package leets.land.domain; | ||
|
|
||
| import leets.land.controller.AlphabetGameMachine; | ||
| import leets.land.controller.GameMachine; | ||
| import leets.land.controller.NumberGameMachine; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| public enum GameVersion { | ||
|
|
||
| NUMBER(1, new NumberGameMachine()), | ||
| ALPHABET(2, new AlphabetGameMachine()); | ||
|
|
||
| private final int version; | ||
| private final GameMachine gameMachine; | ||
|
|
||
| GameVersion(int version, GameMachine gameMachine) { | ||
| this.version = version; | ||
| this.gameMachine = gameMachine; | ||
| } | ||
|
|
||
| public static GameVersion match(int version) { | ||
| return Arrays.stream(values()) | ||
| .filter(gameVersion -> gameVersion.version == version) | ||
| .findFirst() | ||
| .orElseThrow(() -> new IllegalArgumentException("[ERROR] μ‘΄μ¬νμ§ μλ λ²μ μ λλ€.")); | ||
| } | ||
|
|
||
| public void start() { | ||
| gameMachine.run(); | ||
| } | ||
| } |
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,44 @@ | ||
| package leets.land.domain.guess; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| public class GuessAlphabet implements GuessValue { | ||
|
|
||
| private static final int MIN_RANGE = 'A'; | ||
| private static final int MAX_RANGE = 'z'; | ||
| private static final String ERROR_FORMAT = "[ERROR] %s"; | ||
|
|
||
| private final int value; | ||
|
|
||
| public GuessAlphabet(int value) { | ||
| validate(value); | ||
| this.value = value; | ||
| } | ||
|
|
||
| private void validate(int value) { | ||
| if (value < MIN_RANGE || value > MAX_RANGE) { | ||
| throw new IllegalArgumentException(String.format(ERROR_FORMAT, "μΆμΈ‘κ°μ λ²μλ A μ΄μ z μ΄νμ λλ€")); | ||
| } | ||
| } | ||
|
|
||
| public int compare(int other) { | ||
| return other - value; | ||
| } | ||
|
|
||
| public int value() { | ||
| return value; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| GuessAlphabet that = (GuessAlphabet) o; | ||
| return value == that.value; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(value); | ||
| } | ||
| } |
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,44 @@ | ||
| package leets.land.domain.guess; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| public class GuessNumber implements GuessValue { | ||
|
|
||
| private static final int MIN_RANGE = 1; | ||
| private static final int MAX_RANGE = 100; | ||
| private static final String ERROR_FORMAT = "[ERROR] %s"; | ||
|
|
||
| private final int value; | ||
|
|
||
| public GuessNumber(int value) { | ||
| validate(value); | ||
| this.value = value; | ||
| } | ||
|
|
||
| private void validate(int value) { | ||
| if (value < MIN_RANGE || value > MAX_RANGE) { | ||
| throw new IllegalArgumentException(String.format(ERROR_FORMAT, "μΆμΈ‘κ°μ λ²μλ 1 μ΄μ 100 μ΄νμ λλ€")); | ||
| } | ||
| } | ||
|
|
||
| public int compare(int other) { | ||
| return other - value; | ||
| } | ||
|
|
||
| public int value() { | ||
| return value; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| GuessNumber that = (GuessNumber) o; | ||
| return value == that.value; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(value); | ||
| } | ||
| } |
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 leets.land.domain.guess; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| public class GuessRange { | ||
|
|
||
| private static final String ERROR_FORMAT = "[ERROR] %s"; | ||
|
|
||
| private final GuessValue min; | ||
| private final GuessValue max; | ||
|
|
||
| public GuessRange(GuessValue min, GuessValue max) { | ||
| this.min = min; | ||
| this.max = max; | ||
| } | ||
|
|
||
| public GuessRange downMax(GuessValue max) { | ||
| return new GuessRange(min, max); | ||
| } | ||
|
|
||
| public GuessRange upMin(GuessValue min) { | ||
| return new GuessRange(min, max); | ||
| } | ||
|
|
||
| public void checkRange(int guessValue) { | ||
| if (guessValue < min() || guessValue > max()) { | ||
| throw new IllegalArgumentException(String.format(ERROR_FORMAT, "λ²μλ₯Ό λ²μ΄λ©λλ€.")); | ||
| } | ||
| } | ||
|
|
||
| public int min() { | ||
| return min.value(); | ||
| } | ||
|
|
||
| public int max() { | ||
| return max.value(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| GuessRange that = (GuessRange) o; | ||
| return Objects.equals(min, that.min) && Objects.equals(max, that.max); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(min, max); | ||
| } | ||
| } |
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,8 @@ | ||
| package leets.land.domain.guess; | ||
|
|
||
| public interface GuessValue { | ||
|
|
||
| int compare(int other); | ||
|
|
||
| int value(); | ||
| } |
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,23 @@ | ||
| package leets.land.domain.status; | ||
|
|
||
| import leets.land.domain.guess.GuessRange; | ||
| import leets.land.domain.guess.GuessValue; | ||
|
|
||
| public class Correct implements Status { | ||
|
|
||
| @Override | ||
| public GuessRange narrowRange(GuessRange guessRange, GuessValue guessValue) { | ||
| GuessRange downMaxed = guessRange.downMax(guessValue); | ||
| return downMaxed.upMin(guessValue); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isValid(int gap) { | ||
| return gap == 0; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isContinue() { | ||
| return false; | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λ€λ₯Έ λΆλ€ νμ κ±° 보λκΉ μΆμΈ‘ κ°μ΄ μ λ΅λ³΄λ€ ν¬κ±°λ μμ κ²½μ° κ·Έ κ°μ μ μΈν λ²μλ‘ μ§μ νλκ² λ§λ€κ³ μκ°νμ΄μ
μλ₯Όλ€μ΄ λ§μ½ μ¬μ©μκ° aλ₯Ό μ λ ₯νλλ UPμ΄λ©΄ λ²μκ° b~zλ‘ μ§μ λ μ μλλ‘ λ§μ΄μμ..!
κ·Έλ μ§ μμΌλ©΄ μλμ μΌλ‘ 무νν κ²μμ μ§νν μλ μμκ±°κ³ , μ λ€μ΄ κ²μ κΈ°λ³Έ μμΉμ΄ μ λ ₯ κ°μ μ μΈν λ²μ μ€μμ μ ννλκ±°λΌκ³ μκ°ν©λλ€
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ’μ μ§μ μ΄μμ! μ¬μ€ ꡬννλ€ λμΉ λΆλΆμ λλ€γ γ γ π₯²
κ°μ¬ν΄μβΊοΈ