-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: Cards 의 중복 제거 / 블랙잭 로직 뎁스 1로 수정 * [refactor] 상속 의도를 명확하게 나타내기 위해 player와 user 네이밍 상호 변경 * [feat] 배팅 금액을 관리하는 객체 구현 * feat: 수익을 계산하는 클래스 구현 및 테스트 코드 추가 * [feat] WinningResult 수익을 담는 필드 추가 * feat: 컨트롤러와 뷰 수정 * refactor: 사용하지 않는 생성자, 메서드 제거 / PlayerFactory -> UserFactory 로 클래스 명 변경 * refactor: 테스트 코드 리팩토링 * refactor: 플레이어와 딜러의 카드 추가 지급 기준을 선택하는 메서드를 유저에 추상 메서드로 구현 / 중복 코드, 클래스 제거 * refactor: 플레이어의 이름과 배팅 금액을 받는 DTO 를 분리해서 설계 / 사용하지 않는 상수 제거 * refactor: 딜러의 카드 합에 따라 받은 카드의 개수 출력 * refactor: playerNameDTO, playerBettingMoneyDTO -> playerDTO 로 통합 * refactor: 현재 플레이어가 소유한 카드가 블랙잭인지 검사하는 로직을 BlackJackRule 로 이동 * refactor: CardCalculator 의 메서드명을 기능에 맞게 수정, 상수 이름 수정 * refactor: 딜러의 추가 지급 카드 수를 세는 불필요한 변수 제거 * refactor: 수익 계산을 인터페이스로 도출 * refactor: 게임 로직 버그 수정 * refactor: ProfitStrategy 의 구현체들에 각 조건을 메서드로 만들어서 ProfitFactory 에서 if 절 제거 * refactor: 딜러의 수익 계산 결과를 WinningResult 가 담당하도록 변경 * refactor: 딜러의 추가 지급 카드 수 계산의 책임을 딜러로 이동 Co-authored-by: Eun Seok <jeseok95@gmail.com>
- Loading branch information
Showing
48 changed files
with
949 additions
and
683 deletions.
There are no files selected for viewing
This file contains 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 contains 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 contains 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 contains 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 domain; | ||
|
||
public class BettingMoney { | ||
private static final int MIN_BETTING_MONEY = 1; | ||
|
||
private int bettingMoney; | ||
|
||
public BettingMoney(int bettingMoney) { | ||
if (bettingMoney < MIN_BETTING_MONEY) { | ||
throw new IllegalArgumentException("배팅 금액은 1원 이상 가능합니다."); | ||
} | ||
|
||
this.bettingMoney = bettingMoney; | ||
} | ||
|
||
public int getBettingMoney() { | ||
return bettingMoney; | ||
} | ||
} |
This file contains 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,32 +1,18 @@ | ||
package domain; | ||
|
||
import domain.card.Card; | ||
import domain.player.Player; | ||
import domain.player.User; | ||
|
||
public class BlackJackRule { | ||
private static final int BLACK_JACK = 21; | ||
|
||
public boolean isUserCardSumOverBlackJack(User user) { | ||
public boolean isHit(User user) { | ||
if (user == null) { | ||
throw new NullPointerException("유저를 입력하지 않았습니다."); | ||
} | ||
|
||
return user.sumCardNumber() >= BLACK_JACK; | ||
} | ||
|
||
public boolean isHit(User user, Answer answer) { | ||
if (user == null || answer == null) { | ||
throw new NullPointerException("유저 또는 카드 선택 여부를 입력하지 않았습니다."); | ||
throw new NullPointerException("플레이어를 입력하지 않았습니다."); | ||
} | ||
|
||
if (isUserCardSumOverBlackJack(user)) { | ||
return false; | ||
} | ||
return answer.isYes(); | ||
return !user.isBlackJack() && user.isHit(); | ||
} | ||
|
||
public void hit(Player player, Card card) { | ||
player.hitCard(card); | ||
public void hit(User user, Card card) { | ||
user.hitCard(card); | ||
} | ||
} |
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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,30 @@ | ||
package domain; | ||
|
||
import domain.card.CardDeck; | ||
import domain.player.Dealer; | ||
import domain.player.Player; | ||
import domain.player.User; | ||
import domain.player.Users; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class UserFactory { | ||
private UserFactory() { | ||
} | ||
|
||
public static Users create(CardDeck cardDeck, Map<String, Integer> playerInformation) { | ||
if (cardDeck == null || playerInformation == null) { | ||
throw new IllegalArgumentException("플레이어를 생성할 수 없습니다."); | ||
} | ||
|
||
List<User> users = new ArrayList<>(); | ||
users.add(new Dealer(cardDeck.initialDraw())); | ||
users.addAll(playerInformation.entrySet().stream() | ||
.map(entry -> new Player(entry.getKey(), cardDeck.initialDraw(), entry.getValue())) | ||
.collect(Collectors.toList())); | ||
return new Users(users); | ||
} | ||
} |
Oops, something went wrong.