def test_bust(self): """バーストする場合""" deck = Deck() player = Player() player.stock = [Card(10, "10", "ダイヤ"), Card(9, "9", "ダイヤ"), Card(3, "3", "ダイヤ")] deck.is_bust(player=player) self.assertTrue(deck.is_bust(player=player))
def test_judge_player_win(self): """プレイヤーがかつパターン""" deck = Deck() player = Player() dealer = Dealer() player.stock = [Card(2, "2", "ダイヤ"), Card(9, "9", "ダイヤ"), Card(10, "J", "ダイヤ")] dealer.stock = [Card(10, "J", "スペード"), Card(5, "5", "スペード")] deck.add_player(player=player, dealer=dealer) self.assertEqual("player win", deck.final_judge())
def test_bust_both(self): """両方バーストすると、ディーラーが勝つ""" deck = Deck() player = Player() dealer = Dealer() player.stock = [Card(10, "Q", "ダイヤ"), Card(8, "8", "ダイヤ"), Card(10, "J", "ダイヤ")] dealer.stock = [Card(10, "Q", "クラブ"), Card(8, "8", "クラブ"), Card(10, "J", "クラブ")] deck.add_player(player=player, dealer=dealer) self.assertEqual("player lose", deck.final_judge())
def test_judge_player_push(self): """引き分けの場合""" deck = Deck() player = Player() dealer = Dealer() player.stock = [Card(2, "2", "ダイヤ"), Card(8, "8", "ダイヤ"), Card(10, "J", "ダイヤ")] dealer.stock = [Card(2, "2", "ダイヤ"), Card(8, "8", "ダイヤ"), Card(10, "J", "ダイヤ")] deck.add_player(player=player, dealer=dealer) self.assertEqual("player push", deck.final_judge())
class Game: def __init__(self): self.player = Player() self.dealer = Dealer() self.deck = Deck() self.deck.add_player(player=self.player, dealer=self.dealer) def start(self): print("---------ゲーム開始---------") # 初期はまず2枚ずつ引く for i in range(2): self.player.draw_card(self.deck) self.dealer.draw_card(self.deck) print(self.deck.display_deck()) self.play() def play(self): while True: draw = input("追加でカードを引きますか? yes/no: ") if "n" in draw: break self.player.draw_card(self.deck) if self.deck.is_bust(self.player): print("\n") print("player bust!!") break else: print("\n") print("---------デッキ状況---------") print(self.deck.display_deck()) self.final_judge() def final_judge(self): self.dealer.draw_card_by_17(self.deck) msg = self.deck.final_judge() self.end(msg) def end(self, msg): print("=========ゲーム結果=========") print("###", msg, "###") print(self.deck.display_deck(final_judge=True))
def __init__(self): self.player = Player() self.dealer = Dealer() self.deck = Deck() self.deck.add_player(player=self.player, dealer=self.dealer)