Exemplo n.º 1
0
def test_draw():

    scene1_name = "scene1"

    scene1 = Scene(scene1_name, "welcome", [])
    scene2 = Scene("scene2", "also welcome", [])

    nextscene1 = NextScene(scene1, success_rate=1.0)
    nextscene2 = NextScene(scene2, success_rate=0)

    option1 = Option("option no. 1",
                     user_inputs=["n"],
                     next_scenes=[nextscene1, nextscene2])

    option2 = Option("option no. 2", user_inputs=["m"], next_scenes=nextscene1)

    example_scene = Scene("exapmle scene",
                          desc="this is an example scene",
                          options=[option1, option2])

    result = example_scene.next_scene_draw("n")  # when next_scene is a list
    assert result.get_scene_name() == scene1_name

    result = example_scene.next_scene_draw("m")  # when next_scene is'nt a list
    assert result.get_scene_name() == scene1_name
Exemplo n.º 2
0
def test_run_scene(monkeypatch):
    scene1_name = "scene1"

    scene1 = Scene(scene1_name, "welcome", [])
    scene2 = Scene("scene2", "also welcome", [])

    nextscene1 = NextScene(scene1, success_rate=1.0)
    nextscene2 = NextScene(scene2, success_rate=0)

    option1 = Option("go left",
                     user_inputs=["l, left"],
                     next_scenes=[nextscene1, nextscene2])

    option2 = Option("go right",
                     user_inputs=["r, right"],
                     next_scenes=nextscene1)

    example_scene = Scene("example scene",
                          desc="this is an example scene",
                          options=[option1, option2])

    gm = GameManager(example_scene)

    path = 'gamebook.game_manager.GameManager.run_scene'
    monkeypatch.setattr(path, lambda self, options: "right")

    assert gm.run_scene() == scene1_name
Exemplo n.º 3
0
def test_get_scene_name():

    dead_scene = Scene("death_scene", "game over", [])

    scene1 = Scene("scene1", "At last your two-day hike is over.", [
        Option('Go left',
               user_inputs=['l', 'left'],
               next_scenes=[NextScene(dead_scene)]),
        Option('Go right',
               user_inputs=['r', 'right'],
               next_scenes=[NextScene(dead_scene)])
    ])

    nextscene1 = NextScene(scene1, 1.0)

    assert nextscene1.get_scene_name() == "scene1"
Exemplo n.º 4
0
def test_draw_when_option_doesnt_have_next_scene():

    example_option = Option("option no. 1", user_inputs=["n"], next_scenes=[])

    example_scene = Scene("exapmle scene",
                          desc="this is an example scene",
                          options=[example_option])

    with pytest.raises(ValueError) as error_text:
        assert example_scene.next_scene_draw("n")
    assert str(error_text.value) == "this option has no next_scene"
Exemplo n.º 5
0
def test_show_options():

    dead_scene = Scene("death scene", "game over", [])

    scene1 = Scene("scene1", "At last your two-day hike is over.", [
        Option('Go left',
               user_inputs=['l', 'left'],
               next_scenes=[NextScene(dead_scene)]),
        Option('Go right',
               user_inputs=['r', 'right'],
               next_scenes=[NextScene(dead_scene)])
    ])

    # the string is very long so i cut it to multiple sections

    result = """available options:
Go left , available user_inputs: l, left , next scenes:death scene, 1.0

Go right , available user_inputs: r, right , next scenes:death scene, 1.0

"""

    assert scene1.show_options() == result
            options=[]
        )

dead_scene = Scene(
            name="death scene",
            desc='game over - you died',
            options=[]
        )

next_scene2 = Scene(
            name="scene2",
            desc='Hello from the next scene 2',
            options=[
                Option('Fight', user_inputs=['fight'],
                       next_scenes=[
                            NextScene(lucky_scene, success_rate=0.5),
                            NextScene(dead_scene, success_rate=0.5)
                        ]),
                Option('Flee', user_inputs=['flee'],
                       next_scenes=[
                        NextScene(flee_scene, success_rate=0.5),
                        NextScene(dead_scene, success_rate=0.5)
                    ])
            ]
        )

next_scene1 = Scene(
            name="scene1",
            desc='Hello from the next scene 1',
            options=[
                Option('Fight', user_inputs=['fight'],
Exemplo n.º 7
0
    options=[])

dead_scene = Scene(name="death scene",
                   desc='the imp defeated you.\ngame over - you died',
                   options=[])

left_at_fork = Scene(
    name="left at fork",
    desc='''you keep walking the dark path, watching your steps.
then suddenly you witness a little spot of light. you walk towards it and
it grows as you get nearer it. it is an exit! you exit the maze and witness
your sought after treasure - the fountain of youth...
do you enter the water?''',
    options=[
        Option('enter the fountain',
               user_inputs=['enter'],
               next_scenes="fountain scene")
    ])

after_fight_scene = Scene(name="after fight with imp",
                          desc='''congratulations, you defeated the imp.
you stare at the imp's corpse then at the wall infront of you.
you understand that you need to go back to the junction and take the other way''',
                          options=[
                              Option('go back and continue',
                                     user_inputs=['go back'],
                                     next_scenes="left path")
                          ])

imp_fight_scene = FightScene(
    name="fight scene",