Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/main/java/Main.java
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();
Comment on lines +6 to +7

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지난번에 비해서 간결해졌네요 👍

}
}
}
58 changes: 58 additions & 0 deletions src/main/java/controller/LadderController.java
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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

일급 컬렉션 으로 관리를 해도 괜찮을 것 같아요

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

조언 감사합니다!

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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this는 제거해도 괜찮을 것 같아요

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵!!


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
Copy link

@dh2906 dh2906 Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기처럼 다른 코드도 if문 사이에 줄바꿈이 들어오면 더 가독성이 좋아질 것 같아요.

  • 입력받은 값이 all 이면 if문에서 break하도록 설계하셨는데, 해당 조건이 while문에 들어가도 되지 않을까요?
    만약 제가 말한 방식처럼 하실거면 while 보다는 do-while이 더 적합할 것 같아요!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그것도 좋은 방법입니다! 사람마다 취향이 다른데 저 같은 경우는 이런식으로 if를 걸어서 하는 것을 더 선호합니다! 다른 의견 주셔서 감사합니다!

else {
System.out.println("존재하지 않는 이름입니다. 다시 입력해주세요.");
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 존재하지 않는 이름을 입력하면 예외를 발생하도록 만들었는데 이렇게 무한 루프로 정상적인 값을 입력받을 때까지 돌아가도록 할 수도 있군요!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵! 저는 이번 미션이 all입력을 제외한 입력들은 정상 값이 들어오기 전까지 계속해서 입력을 받을 필요가 있다고 해석하여 이런식으로 작성하였습니다!

}
}
}
2 changes: 1 addition & 1 deletion src/main/java/model/LadderResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ public String getResult(String name) {
public Map<String, String> getAllResults() {
return results;
}
}
}
1 change: 0 additions & 1 deletion src/main/java/model/Line.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ public List<Boolean> getPoints() {
return points;
}
}

2 changes: 1 addition & 1 deletion src/main/java/model/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ public Player(String name) {
public String getName() {
return name;
}
}
}
42 changes: 42 additions & 0 deletions src/main/java/view/ResultView.java
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));
}
}
19 changes: 19 additions & 0 deletions src/test/java/model/LadderResultTest.java
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"));
}
}
29 changes: 29 additions & 0 deletions src/test/java/model/LadderTest.java
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"));
}
}
16 changes: 16 additions & 0 deletions src/test/java/model/LineTest.java
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);
}
}
20 changes: 20 additions & 0 deletions src/test/java/model/PlayerTest.java
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"));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

예외가 발생하면서 나오는 메시지에 대해서도 테스트해보시면 더 좋을 것 같아요!

}

@Test
void 이름이_5자_이하면_통과() {
Player player = new Player("Neo");
assertEquals("Neo", player.getName());
}
}