-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: GameResult 설계 개선 * refactor: 전체적인 변수명과 기타 수정 * refactor: Result enum 클래스 변경 * refactor: User 테스트 방식 수정 및 테스트 용 생성자 구현 * refactor: Result 테스트 구현 * feat: Bet관련 테스트와 클래스 구현 * feat: Bet 입력 구현 * feat: Bet 입력 구현2 * refactor: GameResult 설계 수정 * feat: 수익 계산 구현 * refactor: user의 draw 구현 * refactor: User 생성 방식 변경 * refactor: 컨벤션에 맞게 리팩토링 * refactor: 컨벤션에 맞게 리팩토링 * refactor: bet 생성시 검증 추가 * refactor: 메소드 네이밍 컨벤션에 맞게 refactor * refactor: Result 람다식으로 수정, Bet 생성자 삭제 * refactor: 안쓰는 메서드 삭제, 컨벤션 리팩터
- Loading branch information
Showing
31 changed files
with
595 additions
and
313 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package exception; | ||
|
||
public class BetFormatException extends RuntimeException { | ||
public BetFormatException(String message) { | ||
super(message); | ||
} | ||
} |
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,7 @@ | ||
package exception; | ||
|
||
public class BetRangeException extends RuntimeException { | ||
public BetRangeException(String message) { | ||
super(message); | ||
} | ||
} |
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,7 @@ | ||
package exception; | ||
|
||
public class IllegalDrawException extends RuntimeException { | ||
public IllegalDrawException(String message) { | ||
super(message); | ||
} | ||
} |
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,55 @@ | ||
package model; | ||
|
||
import exception.BetFormatException; | ||
import exception.BetRangeException; | ||
import utils.StringUtils; | ||
|
||
import java.util.Objects; | ||
|
||
public class Bet { | ||
public static final double LOWER_BET_BOUND = 100; | ||
|
||
private final double bet; | ||
|
||
public Bet(String input) { | ||
validate(input); | ||
this.bet = Double.parseDouble(input); | ||
} | ||
|
||
private void validate(String input) { | ||
StringUtils.validateString(input); | ||
validateFormat(input); | ||
validateRange(input); | ||
} | ||
|
||
private void validateFormat(String input) { | ||
try { | ||
Double.parseDouble(input); | ||
} catch (NumberFormatException e) { | ||
throw new BetFormatException("베팅금액은 실수만 입력 가능합니다."); | ||
} | ||
} | ||
|
||
private void validateRange(String input) { | ||
if (Double.parseDouble(input) < LOWER_BET_BOUND) { | ||
throw new BetRangeException("베팅금액은 100원 이상부터 입력 가능합니다."); | ||
} | ||
} | ||
|
||
public double multiplyBet(double ratio) { | ||
return bet * ratio; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Bet bet1 = (Bet) o; | ||
return Double.compare(bet1.bet, bet) == 0; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(bet); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,20 +1,22 @@ | ||
package model; | ||
|
||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class CardFactory { | ||
|
||
public static List<Card> createCardList() { | ||
List<Card> cards = new ArrayList<>(); | ||
for (Symbol symbol : Symbol.values()) { | ||
createByType(cards, symbol); | ||
} | ||
List<Card> cards = Arrays | ||
.stream(Type.values()) | ||
.flatMap(CardFactory::mapToCard) | ||
.collect(Collectors.toList()); | ||
return Collections.unmodifiableList(cards); | ||
} | ||
|
||
private static void createByType(List<Card> cards, Symbol symbol) { | ||
for (Type type : Type.values()) { | ||
cards.add(new Card(symbol, type)); | ||
} | ||
private static Stream<Card> mapToCard(Type type) { | ||
return Arrays | ||
.stream(Symbol.values()) | ||
.map(symbol -> new Card(symbol, type)); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,20 +1,27 @@ | ||
package model; | ||
|
||
import static controller.BlackJackGame.HIT_BOUNDARY; | ||
import java.util.List; | ||
|
||
import static controller.BlackJackGame.DEALER_HIT_BOUNDARY; | ||
|
||
public class Dealer extends User { | ||
public static final int ZERO = 0; | ||
private static final int FIRST = 0; | ||
public static final String DEALER_NAME = "딜러"; | ||
|
||
public Dealer(Deck deck, int initialDrawCount) { | ||
super(DEALER_NAME, deck, initialDrawCount); | ||
public Dealer(Deck deck) { | ||
super(DEALER_NAME, deck); | ||
} | ||
|
||
public Dealer(List<Card> cards) { | ||
super(DEALER_NAME, cards); | ||
} | ||
|
||
public String toStringCardHandFirst() { | ||
return cardHand.getCards().get(ZERO).toString(); | ||
return cardHand.getCards().get(FIRST).toString(); | ||
} | ||
|
||
@Override | ||
public boolean isHitBound() { | ||
return getScore() <= HIT_BOUNDARY; | ||
return getScore() <= DEALER_HIT_BOUNDARY; | ||
} | ||
} |
Oops, something went wrong.