def main():
    set_up_logging()
    # handles initialize, quit, and ticks
    main_event_manager = eventmanager.EventManager()
    # allows controller to post events to the model
    input_event_manager = eventmanager.EventManager()
    # create model, view, and controller
    game_model = model.Model(main_event_manager, input_event_manager)
    keyboard = controller.Controller(main_event_manager,
                                     input_event_manager,
                                     game_model)
    graphics = view.GraphicalView(main_event_manager, game_model)
    # create the soundboard
    sound_board = soundboard.SoundBoard(main_event_manager)
    # start the game
    game_model.run()
def test_unregister_stops_notification():
    event_manager = eventmanager.EventManager()
    spy = ListenerSpy()
    event_manager.register_listener(spy)
    event_manager.unregister_listener(spy)
    event_manager.post(events.QuitEvent())
    assert spy.notify.call_count == 0
def test_post_calls_notify_once():
    event_manager = eventmanager.EventManager()
    spy = ListenerSpy()
    event_manager.register_listener(spy)
    assert spy.notify.call_count == 0
    event_manager.post(events.Event())
    assert spy.notify.call_count == 1
def test_post_notifies_with_proper_event():
    event_manager = eventmanager.EventManager()
    spy = ListenerSpy()
    event_manager.register_listener(spy)
    event_manager.post(events.TickEvent())
    args, kwargs = spy.notify.call_args
    assert len(args) == 1
    assert isinstance(args[0], events.TickEvent)
def test_multiple_listeners_all_get_notified():
    event_manager = eventmanager.EventManager()
    spies = [ListenerSpy() for i in range(100)]
    for spy in spies:
        event_manager.register_listener(spy)
    event_manager.post(events.QuitEvent())
    for spy in spies:
        assert spy.notify.call_count == 1
        args, kwargs = spy.notify.call_args
        assert isinstance(args[0], events.QuitEvent)
예제 #6
0
def test_model_four_ticks_before_quit():
    event_manager = eventmanager.EventManager()
    game_state = model.Model(event_manager)
    quitter = QuitsAfterFourTicks(event_manager)
    game_state.run()
    # if we get here, that means that the game has stopped too, which is good
    tick_events = [
        event for event in event_manager.events
        if isinstance(event, events.TickEvent)
    ]
    assert len(tick_events) == 4
    assert len(event_manager.events) == 6