|
| 1 | +package lottoGame.controller; |
| 2 | + |
| 3 | +import static lottoGame.view.Casher.askBeforeWinNums; |
| 4 | +import static lottoGame.view.Casher.askBuyPrice; |
| 5 | +import static lottoGame.view.Casher.informBuyCount; |
| 6 | +import static lottoGame.view.Casher.informPublishedLottos; |
| 7 | +import static lottoGame.view.Casher.informWinningLottoNums; |
| 8 | + |
| 9 | +import lottoGame.model.lotto.LottoMachine; |
| 10 | +import lottoGame.model.lotto.Lottos; |
| 11 | +import lottoGame.model.price.BuyPrice; |
| 12 | +import lottoGame.model.winner.BeforeWinNums; |
| 13 | +import lottoGame.model.winner.WinnerResult; |
| 14 | +import lottoGame.view.WinResultDto; |
| 15 | + |
| 16 | +public class LottoStore { |
| 17 | + public static final int PER_LOTTO_PRICE = 1000; |
| 18 | + |
| 19 | + public void start() { |
| 20 | + BuyPrice buyPrice = getBuyPrice(); |
| 21 | + |
| 22 | + Lottos lottos = buyLottos(buyPrice); |
| 23 | + |
| 24 | + totalWinResult( |
| 25 | + new BeforeWinNums(askBeforeWinNums()), |
| 26 | + lottos, |
| 27 | + buyPrice.price() |
| 28 | + ); |
| 29 | + } |
| 30 | + |
| 31 | + private Lottos buyLottos(BuyPrice buyPrice) { |
| 32 | + Lottos lottos = publishLottos(buyPrice); |
| 33 | + informPublishedLottos(lottos.convertRawString()); |
| 34 | + return lottos; |
| 35 | + } |
| 36 | + |
| 37 | + private BuyPrice getBuyPrice() { |
| 38 | + BuyPrice buyPrice = new BuyPrice(askBuyPrice()); |
| 39 | + informBuyCount(buyPrice.calculateLottoCount(PER_LOTTO_PRICE)); |
| 40 | + |
| 41 | + return buyPrice; |
| 42 | + } |
| 43 | + |
| 44 | + private Lottos publishLottos(BuyPrice buyPrice) { |
| 45 | + LottoMachine lottoMachine = new LottoMachine(PER_LOTTO_PRICE); |
| 46 | + |
| 47 | + return lottoMachine.publish(buyPrice); |
| 48 | + } |
| 49 | + |
| 50 | + private void totalWinResult(BeforeWinNums beforeWinNums, Lottos lottos, int price) { |
| 51 | + WinnerResult winnerResult = lottos.compareAndElectWinResult(beforeWinNums); |
| 52 | + |
| 53 | + informWinningLottoNums( |
| 54 | + new WinResultDto( |
| 55 | + winnerResult, |
| 56 | + price |
| 57 | + ) |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | +} |
0 commit comments