Beispiel #1
0
class GameStore:
    """Gameを制御する."""

    def __init__(self):
        self._game = Game()
        self._dispatcher = dispatcher
        self._dispatcher.on(act.BEGIN_GAME, self._begin_game)
        self._dispatcher.on(act.TURN_DEALER, self._turn_dealer)
        self._dispatcher.on(act.HIT_OR_STAND, self._hit_or_stand)

    def get_state(self):
        return self._game
    
    def _begin_game(self):
        self._game.begin()
        self._dispatcher.dispatch(act.CHANGE_STATE, state=self.get_state())
    
    #TODO: BEGIN_TURNで決定してTURN_PLAYERで変更してもいいかも
    def _hit_or_stand(self, player=None, decision=None):
        player.decide(decision)
        player.run()
        self._dispatcher.dispatch(act.CHANGE_STATE, state=self.get_state())
    
    #TODO: 決定する処理はdealerに持たせる?
    def _turn_dealer(self):
        if self._game.dealer.point < 17:
            self._game.dealer.hit()
        else:
            self._game.dealer.stand()
        self._dispatcher.dispatch(act.CHANGE_STATE, state=self.get_state())
Beispiel #2
0
def test_beginning_of_the_game():
    game = Game()
    deck_before_shuffle = game.deck[:]
    game.begin()
    assert game.deck != deck_before_shuffle
    assert len(game.dealer.hand) == 2
    assert len(game.player.hand) == 2
Beispiel #3
0
def run():
    game = Game()
    game.begin()
    while not game.game_is_over:
        show_state(game, hole=True)
        turn_player(game)
        if game.turn_is_over:
            break
        turn_dealer(game)
    show_state(game, hole=False)
    show_result(game)
Beispiel #4
0
def test_game_after_blackjack():
    game = Game()
    game.player.hand = [Card(Heart, 1), Card(Heart, 13)]
    assert game.game_result == WIN
    assert game.game_is_over
    assert game.turn_is_over
    game.player.hand.append(Card(Heart, 1))
    assert game.game_result == LOSE
    assert game.game_is_over
    assert game.turn_is_over
Beispiel #5
0
 def __init__(self):
     self._game = Game()
     self._dispatcher = dispatcher
     self._dispatcher.on(act.BEGIN_GAME, self._begin_game)
     self._dispatcher.on(act.TURN_DEALER, self._turn_dealer)
     self._dispatcher.on(act.HIT_OR_STAND, self._hit_or_stand)
Beispiel #6
0
def test_initial_game_properties():
    game = Game()
    assert game.game_result is None
    assert not game.game_is_over
    assert not game.turn_is_over
Beispiel #7
0
def test_game_after_player_standing():
    game = Game()
    game.player.stand()
    assert game.game_result is not None
    assert game.game_is_over
    assert not game.turn_is_over