示例#1
0
 def test_switch_scene(self):
     '''Create Game() with several Scene() objects and switch them'''
     game = retro.Game(retro.Scene(INITIAL_SCENE))
     game.add_scene(retro.Scene(OTHER_SCENE))
     assert game.current_scene.name == INITIAL_SCENE
     game.switch_scene(OTHER_SCENE)
     assert game.current_scene.name == OTHER_SCENE
示例#2
0
 def test_remove_game_object(self):
     '''Test remove GameObject() from a scene'''
     scene = retro.Scene('test_scene')
     game_object = retro.GameObject()
     scene.add_game_object(game_object)
     scene.remove_game_object(game_object)
     assert len(scene.game_objects) == 0
示例#3
0
 def test_creation(self):
     '''Create new Game() and check its initial state'''
     game = retro.Game(retro.Scene(INITIAL_SCENE))
     assert isinstance(game, retro.Game)
     assert not game.running
     assert game.current_scene.name == INITIAL_SCENE
     assert game.current_scene.game is game
示例#4
0
 def test_add_game_object(self):
     '''Add GameObject() to a scene'''
     scene = retro.Scene('test_scene')
     game_object = retro.GameObject()
     scene.add_game_object(game_object)
     assert len(scene.game_objects) == 1
     assert game_object is scene.game_object(game_object.id)
     assert game_object.scene is scene
示例#5
0
 def test_garbage_collector(self):
     '''Test if Scene() removes dead GameObject() objects'''
     scene = retro.Scene('test_scene')
     game_object = retro.GameObject()
     scene.add_game_object(game_object)
     assert game_object in scene.game_objects
     game_object.kill()
     scene.update()
     assert game_object not in scene.game_objects
示例#6
0
 def test_running(self):
     '''Create new Game() and start it'''
     game = retro.Game(retro.Scene(INITIAL_SCENE))
     game.start()
     assert game.running
     tick1 = game.ticks
     time.sleep(1.0)
     tick2 = game.ticks
     game.quit()
     assert not game.running
     assert tick2 > tick1
示例#7
0
 def test_search_game_object_by_tags(self):
     '''Search game objects by tags'''
     scene = retro.Scene('test_scene')
     game_object1 = retro.GameObject()
     game_object2 = retro.GameObject(tags=[TAG1])
     game_object3 = retro.GameObject(tags=[TAG1, TAG2])
     scene.add_game_object(game_object1)
     scene.add_game_object(game_object2)
     scene.add_game_object(game_object3)
     assert game_object1 not in scene.game_objects_tagged_as(TAG1)
     assert game_object1 not in scene.game_objects_tagged_as(TAG2)
     assert game_object2 in scene.game_objects_tagged_as(TAG1)
     assert game_object2 not in scene.game_objects_tagged_as(TAG2)
     assert game_object3 in scene.game_objects_tagged_as(TAG1)
     assert game_object3 in scene.game_objects_tagged_as(TAG2)
示例#8
0
    def test_update_function(self):
        '''Test if update() is called on every GameObject() objects'''
        class MyGameObject(retro.GameObject):
            def __init__(self):
                super(MyGameObject, self).__init__()
                self.update_called = False

            def update(self):
                self.update_called = True

        scene = retro.Scene('test_scene')
        game_object1 = MyGameObject()
        game_object2 = MyGameObject()
        scene.add_game_object(game_object1)
        assert not game_object1.update_called
        assert not game_object2.update_called
        scene.update()
        assert game_object1.update_called
        assert not game_object2.update_called
示例#9
0
    def test_start_function(self):
        '''Test if start() calls every GameObject().start() method'''
        class MyGameObject(retro.GameObject):
            def __init__(self):
                super(MyGameObject, self).__init__()
                self.start_called = False

            def on_start(self):
                self.start_called = True

        scene = retro.Scene('test_scene')
        game_object1 = MyGameObject()
        game_object2 = MyGameObject()
        scene.add_game_object(game_object1)
        scene.add_game_object(game_object2)
        assert not game_object1.start_called
        assert not game_object2.start_called
        scene.start()
        assert game_object1.start_called
        assert game_object2.start_called
示例#10
0
 def test_switch_unknown_scene(self):
     '''Create Game() and switch to a unknown scene'''
     game = retro.Game(retro.Scene(INITIAL_SCENE))
     with pytest.raises(KeyError):
         game.switch_scene(OTHER_SCENE)
示例#11
0
 def test_add_scene(self):
     '''Create Game() and add several Scene() objects'''
     game = retro.Game(retro.Scene(INITIAL_SCENE))
     game.add_scene(retro.Scene(OTHER_SCENE))
     assert set([INITIAL_SCENE, OTHER_SCENE]) == set(game.scenes)
示例#12
0
 def test_remove_unknown_game_object(self):
     '''Remove GameObject() not added to a scene'''
     scene = retro.Scene('test_scene')
     game_object = retro.GameObject()
     with pytest.raises(KeyError):
         scene.remove_game_object(game_object)
示例#13
0
 def test_creation(self):
     '''Create new Scene() and check its initial state'''
     scene = retro.Scene('test_scene')
     assert isinstance(scene, retro.Scene)
     assert scene.game is None
     assert len(scene.game_objects) == 0