-
Notifications
You must be signed in to change notification settings - Fork 60
[BCSD Lab] 임아리 4차시 미션 제출합니다. #75
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
Changes from 11 commits
7b1a3c7
418e4f6
38f0433
a206dfd
bae2eca
c74c95e
354f100
d67337f
2c31d32
10d8e7a
964b120
f1a4916
5c7da67
a317f47
ec039b5
2d68f6c
6d01fb9
a2a2f88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,9 @@ | ||
| import java.util.List; | ||
|
|
||
| import view.InputView; | ||
| import controller.LadderGameController; | ||
| import controller.LadderController; | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args) { | ||
| List<String> names = InputView.getPlayerNames(); | ||
| List<String> results = InputView.getResults(); | ||
| int height = InputView.getLadderHeight(); | ||
|
|
||
| LadderGameController game = new LadderGameController(names, results, height); | ||
| game.play(); | ||
| LadderController ladderGameController = new LadderController(); | ||
| ladderGameController.start(); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package controller; | ||
|
|
||
| import java.util.*; | ||
| import model.*; | ||
| import view.*; | ||
|
|
||
| public class LadderController { | ||
| private List<Player> players; | ||
|
||
| private List<String> results; | ||
| private Ladder ladder; | ||
| private LadderResult ladderResult; | ||
|
|
||
| public void start() { | ||
| List<String> names = InputView.getPlayerNames(); | ||
| List<String> results = InputView.getResults(); | ||
| int height = InputView.getLadderHeight(); | ||
|
|
||
| this.players = createPlayers(names); | ||
| this.results = results; | ||
| this.ladder = new Ladder(players.size(), height); | ||
|
||
|
|
||
| play(); | ||
| } | ||
|
|
||
| private List<Player> createPlayers(List<String> names) { | ||
| List<Player> players = new ArrayList<>(); | ||
| for (String name : names) { | ||
| players.add(new Player(name)); | ||
| } | ||
| return players; | ||
| } | ||
|
|
||
| public void play() { | ||
| ResultView.printLadder(players, ladder.getLines(), results); | ||
|
|
||
| this.ladderResult = ladder.run(players, results); | ||
|
|
||
| showResults(); | ||
| } | ||
|
|
||
| private void showResults() { | ||
| while (true) { | ||
| String query = InputView.getQuery(); | ||
|
|
||
| if (query.equals("all")) { | ||
| ResultView.printAllResults(ladderResult.getAllResults()); | ||
| break; | ||
| } | ||
|
|
||
| if (ladderResult.getAllResults().containsKey(query)) { | ||
| ResultView.printResult(query, ladderResult.getResult(query)); | ||
| } | ||
|
Comment on lines
+48
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기처럼 다른 코드도 if문 사이에 줄바꿈이 들어오면 더 가독성이 좋아질 것 같아요.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그것도 좋은 방법입니다! 사람마다 취향이 다른데 저 같은 경우는 이런식으로 if를 걸어서 하는 것을 더 선호합니다! 다른 의견 주셔서 감사합니다! |
||
| else { | ||
| System.out.println("존재하지 않는 이름입니다. 다시 입력해주세요."); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저는 존재하지 않는 이름을 입력하면 예외를 발생하도록 만들었는데 이렇게 무한 루프로 정상적인 값을 입력받을 때까지 돌아가도록 할 수도 있군요!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵! 저는 이번 미션이 all입력을 제외한 입력들은 정상 값이 들어오기 전까지 계속해서 입력을 받을 필요가 있다고 해석하여 이런식으로 작성하였습니다! |
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,4 +16,4 @@ public String getResult(String name) { | |
| public Map<String, String> getAllResults() { | ||
| return results; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,4 +33,3 @@ public List<Boolean> getPoints() { | |
| return points; | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,4 +13,4 @@ public Player(String name) { | |
| public String getName() { | ||
| return name; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package view; | ||
|
|
||
| import model.Line; | ||
| import model.Player; | ||
|
|
||
| import java.util.*; | ||
|
|
||
| public class ResultView { | ||
| public static void printLadder(List<Player> players, List<Line> lines, List<String> results) { | ||
| for (Player player : players) { | ||
| System.out.printf("%6s", player.getName()); | ||
| } | ||
| System.out.println(); | ||
|
|
||
| for (Line line : lines) { | ||
| printLine(line); | ||
| } | ||
|
|
||
| for (String result : results) { | ||
| System.out.printf("%6s", result); | ||
| } | ||
| System.out.println(); | ||
| } | ||
|
|
||
| private static void printLine(Line line) { | ||
| System.out.print(" "); | ||
| for (boolean point : line.getPoints()) { | ||
| System.out.print(point ? " |-----" : " | "); | ||
| } | ||
| System.out.println(" |"); | ||
| } | ||
|
|
||
| public static void printResult(String name, String result) { | ||
| System.out.println("실행 결과"); | ||
| System.out.println(name + " : " + result); | ||
| } | ||
|
|
||
| public static void printAllResults(Map<String, String> results) { | ||
| System.out.println("실행 결과"); | ||
| results.forEach((name, result) -> System.out.println(name + " : " + result)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package model; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| class LadderResultTest { | ||
|
|
||
| @Test | ||
| void 특정_플레이어_결과_조회() { | ||
| Map<String, String> results = Map.of("Neo", "꽝", "Tommy", "5000", "Brie", "꽝"); | ||
| LadderResult ladderResult = new LadderResult(results); | ||
|
|
||
| assertEquals("5000", ladderResult.getResult("Tommy")); | ||
| assertEquals("꽝", ladderResult.getResult("Neo")); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package model; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
|
|
||
| class LadderTest { | ||
|
|
||
| @Test | ||
| void 사다리_게임_결과_확인() { | ||
| List<Player> players = List.of(new Player("Neo"), new Player("Tommy"), new Player("Brie")); | ||
| List<String> results = List.of("1000", "꽝", "3000"); | ||
|
|
||
| Ladder ladder = new Ladder(players.size(), 5); | ||
| LadderResult ladderResult = ladder.run(players, results); | ||
|
|
||
| Map<String, String> resultMap = ladderResult.getAllResults(); | ||
|
|
||
| assertEquals(3, resultMap.size()); | ||
| assertTrue(resultMap.containsKey("Neo")); | ||
| assertTrue(resultMap.containsKey("Tommy")); | ||
| assertTrue(resultMap.containsKey("Brie")); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package model; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| class LineTest { | ||
|
|
||
| @Test | ||
| void 사다리_이동() { | ||
| Line line = new Line(3); | ||
| int newPosition = line.move(1); | ||
|
|
||
| assertTrue(newPosition >= 0 && newPosition < 3); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package model; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| class PlayerTest { | ||
|
|
||
| @Test | ||
| void 이름이_5자를_초과하면_예외() { | ||
| assertThrows(IllegalArgumentException.class, () -> new Player("abcdef")); | ||
|
||
| } | ||
|
|
||
| @Test | ||
| void 이름이_5자_이하면_통과() { | ||
| Player player = new Player("Neo"); | ||
| assertEquals("Neo", player.getName()); | ||
| } | ||
| } | ||
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.
지난번에 비해서 간결해졌네요 👍