Exemple #1
0
def it_builds_a_game_with_bottomless_pits_in_random_positions():
    game = a_game().with_table(200, 200).with_bottomless_pits(quantity=30).build()
    positions = _bottomless_pits_in_game(game)

    other_game = a_game().with_table(200, 200).with_bottomless_pits(quantity=30).build()
    other_positions = _bottomless_pits_in_game(other_game)

    assert positions != other_positions
Exemple #2
0
def it_moves_the_player_forward_one_position():
    game = a_game().with_hunter(position=Vector2D(0, 0),
                                direction=Direction.NORTH).build()

    game_service.move(game)

    assert game.player.position == Vector2D(0, 1)
Exemple #3
0
def it_does_not_move_the_player_when_it_reaches_a_wall():
    game = a_game().with_hunter(position=Vector2D(0, 0),
                                direction=Direction.SOUTH).build()

    game_service.move(game)

    assert game.player.position == Vector2D(0, 0)
Exemple #4
0
def it_takes_the_gold_if_player_is_in_the_same_position():
    game = a_game().with_hunter(position=Vector2D(0, 0)).build()
    game.gold.position = Vector2D(0, 0)

    game_service.take_gold(game)

    assert game.player_has_gold
Exemple #5
0
def it_does_not_take_the_gold_if_player_is_in_different_position():
    game = a_game().with_hunter(position=Vector2D(0, 0)).build()
    game.gold.position = Vector2D(0, 1)

    game_service.take_gold(game)

    assert game.player_has_gold is False
Exemple #6
0
def it_builds_a_game_with_not_overlapped_entities():
    game = a_game() \
        .with_table(4, 5) \
        .with_hunter(arrows=1) \
        .with_bottomless_pits(quantity=15) \
        .build()

    assert number_of_overlapped_entities_in_game(game) == 0
def it_returns_a_human_readable_string_when_player_has_been_killed_by_wumpus():
    game = a_game().with_hunter().build()
    game.gold.position = Vector2D(3, 3)
    game.wumpus.position = Vector2D(0, 0)

    human_readable_string = string_game_renderer.render(game)

    assert human_readable_string == string_game_renderer.KILLED_BY_WUMPUS
Exemple #8
0
def it_builds_a_game_with_gold_in_random_position():
    gold_positions = []

    for i in range(100):
        game = a_game().with_table(4000, 4000).build()
        gold_positions.append(game.gold.position)

    assert not all(position == gold_positions[0] for position in gold_positions)
Exemple #9
0
def it_builds_a_game_with_wumpus_in_random_position():
    wumpus_position = []

    for i in range(100):
        game = a_game().with_table(4000, 4000).build()
        wumpus_position.append(game.wumpus.position)

    assert not all(position == wumpus_position[0] for position in wumpus_position)
Exemple #10
0
def it_builds_a_game_with_4x5_table_2_bottomless_pits_and_1_arrow():
    game = a_game()\
        .with_table(4, 5)\
        .with_hunter(arrows=1)\
        .with_bottomless_pits(quantity=2)\
        .build()

    expect_quantity_of_bottomless_pits_in_game(2, game)
def it_returns_a_human_readable_string_when_player_leaves_successfully_the_dungeon_with_the_gold_and_the_wumpus_alive(
):
    game = a_game().with_hunter().build()
    game.player.has_gold = True
    game.status = GameStatus.WIN

    human_readable_string = string_game_renderer.render(game)

    assert human_readable_string == string_game_renderer.WIN_WITHOUT_KILL_WUMPUS
Exemple #12
0
def it_leaves_dungeon_if_player_is_in_the_same_position_as_the_exit_and_carries_the_gold(
):
    game = a_game().with_hunter(position=Vector2D(0, 0)).build()
    game.player.has_gold = True

    game_service.leave_dungeon(game)

    assert game.player_has_gold
    assert game.status == GameStatus.WIN
Exemple #13
0
def it_kills_the_wumpus_when_player_fires_an_arrow_in_its_direction():
    game = a_game().with_hunter(position=Vector2D(0, 0),
                                direction=Direction.NORTH).build()
    game.wumpus.position = Vector2D(0, 3)

    fire_hit = game_service.fire(game)

    assert game.is_wumpus_alive is False
    assert fire_hit
Exemple #14
0
def it_stops_hitting_the_wumpus_on_fire_arrow_when_is_already_dead():
    game = a_game().with_hunter(position=Vector2D(0, 0),
                                direction=Direction.NORTH).build()
    game.wumpus.position = Vector2D(0, 3)
    game.wumpus.is_alive = False

    fire_hit = game_service.fire(game)

    assert game.is_wumpus_alive is False
    assert fire_hit is False
Exemple #15
0
def it_kills_player_when_it_moves_to_the_wumpus_and_it_is_alive():
    game = a_game().with_hunter(position=Vector2D(0, 0),
                                direction=Direction.NORTH).build()
    game.wumpus.position = Vector2D(0, 1)

    game_service.move(game)

    assert game.player.position == Vector2D(0, 1)
    assert game.is_player_over_wumpus
    assert game.status == GameStatus.LOSS
Exemple #16
0
def it_kills_player_when_it_moves_to_the_bottomless_pit():
    game = a_game().with_hunter(position=Vector2D(0, 0),
                                direction=Direction.NORTH).build()
    game.add_bottomless_pit(BottomlessPit(Vector2D(0, 1)))

    game_service.move(game)

    assert game.player.position == Vector2D(0, 1)
    assert game.is_player_over_bottomless_pit
    assert game.status == GameStatus.LOSS
Exemple #17
0
def it_does_not_leave_the_dungeon_if_player_is_in_different_position_as_the_exit(
):
    game = a_game().with_hunter(position=Vector2D(0, 0)).build()
    game.player.has_gold = True
    game.exit = Vector2D(2, 0)

    game_service.leave_dungeon(game)

    assert game.player_has_gold
    assert game.status == GameStatus.PLAYING
def it_returns_a_human_readable_string_when_player_has_fallen_in_the_bottomless_pit(
):
    game = a_game().with_hunter().build()
    game.gold.position = Vector2D(3, 3)
    game.wumpus.position = Vector2D(3, 3)
    game.add_bottomless_pit(BottomlessPit(Vector2D(0, 0)))

    human_readable_string = string_game_renderer.render(game)

    assert human_readable_string == string_game_renderer.DEAD_BY_PIT
Exemple #19
0
def it_does_not_fire_an_arrow_when_no_arrows_left():
    game = a_game().with_hunter(arrows=0,
                                position=Vector2D(0, 0),
                                direction=Direction.NORTH).build()
    game.wumpus.position = Vector2D(0, 3)

    fire_hit = game_service.fire(game)

    assert game.wumpus.is_alive
    assert fire_hit is False
Exemple #20
0
def it_changes_player_direction_anticlockwise():
    game = a_game().with_hunter(position=Vector2D(0, 0),
                                direction=Direction.NORTH).build()

    game_service.turn(TurnDirection.ANTICLOCKWISE, game)
    assert game.player.direction == Direction.WEST

    game_service.turn(TurnDirection.ANTICLOCKWISE, game)
    assert game.player.direction == Direction.SOUTH

    game_service.turn(TurnDirection.ANTICLOCKWISE, game)
    assert game.player.direction == Direction.EAST

    game_service.turn(TurnDirection.ANTICLOCKWISE, game)
    assert game.player.direction == Direction.NORTH
def it_returns_a_human_readable_string_without_presences():
    game = a_game().with_hunter().build()
    game.gold.position = Vector2D(3, 3)
    game.wumpus.position = Vector2D(3, 2)
    game.exit = Vector2D(3, 1)

    human_readable_string = string_game_renderer.render(game)

    assert human_readable_string == ('---------------------\n'
                                     'Position:    [0, 0]\n'
                                     'Direction    NORTH\n'
                                     'Golds:       0\n'
                                     'Arrows left: 10\n'
                                     '---------------------\n'
                                     'Presences: \n')
def it_returns_a_human_readable_string_telling_the_current_game_situation():
    game = a_game().with_hunter().build()
    game.gold.position = Vector2D(3, 3)
    game.wumpus.position = Vector2D(3, 2)

    human_readable_string = string_game_renderer.render(game)

    assert human_readable_string == ('---------------------\n'
                                     'Position:    [0, 0]\n'
                                     'Direction    NORTH\n'
                                     'Golds:       0\n'
                                     'Arrows left: 10\n'
                                     '---------------------\n'
                                     'Presences: \n'
                                     ' * You are in the exit position\n')
def it_returns_a_human_readable_string_when_player_is_in_front_of_a_wall():
    game = a_game().with_hunter(direction=Direction.SOUTH).build()
    game.exit = Vector2D(3, 3)
    game.wumpus.position = Vector2D(3, 3)

    human_readable_string = string_game_renderer.render(game)

    assert human_readable_string == (
        '---------------------\n'
        'Position:    [0, 0]\n'
        'Direction    SOUTH\n'
        'Golds:       0\n'
        'Arrows left: 10\n'
        '---------------------\n'
        'Presences: \n'
        ' * It feels too strong to pass through... could it be a wall?\n')
def it_returns_a_human_readable_string_with_3_arrows_left():
    game = a_game().with_hunter().build()
    game.gold.position = Vector2D(3, 3)
    game.wumpus.position = Vector2D(3, 2)
    game.player.arrows_left = 3

    human_readable_string = string_game_renderer.render(game)

    assert human_readable_string == ('---------------------\n'
                                     'Position:    [0, 0]\n'
                                     'Direction    NORTH\n'
                                     'Golds:       0\n'
                                     'Arrows left: 3\n'
                                     '---------------------\n'
                                     'Presences: \n'
                                     ' * You are in the exit position\n')
def it_returns_a_human_readable_string_when_player_has_gold():
    game = a_game().with_hunter().build()
    game.player.has_gold = True
    game.gold = None
    game.status = GameStatus.PLAYING
    game.wumpus.position = Vector2D(3, 3)
    game.exit = Vector2D(3, 3)

    human_readable_string = string_game_renderer.render(game)

    assert human_readable_string == ('---------------------\n'
                                     'Position:    [0, 0]\n'
                                     'Direction    NORTH\n'
                                     'Golds:       1\n'
                                     'Arrows left: 10\n'
                                     '---------------------\n'
                                     'Presences: \n')
def it_returns_a_human_readable_string_when_player_is_over_a_dead_wumpus():
    game = a_game().with_hunter().build()
    game.wumpus.is_alive = False
    game.wumpus.position = game.player.position
    game.exit = Vector2D(3, 3)

    human_readable_string = string_game_renderer.render(game)

    assert human_readable_string == (
        '---------------------\n'
        'Position:    [0, 0]\n'
        'Direction    NORTH\n'
        'Golds:       0\n'
        'Arrows left: 10\n'
        '---------------------\n'
        'Presences: \n'
        ' * You feel that Cupid is near after watch that arrow in the Wumpus heart\n'
    )
def it_returns_a_human_readable_string_with_bottomless_pit_presence():
    game = a_game().with_hunter().build()
    game.gold.position = Vector2D(3, 3)
    game.wumpus.position = Vector2D(3, 3)
    game.add_bottomless_pit(BottomlessPit(Vector2D(1, 0)))
    game.exit = Vector2D(3, 3)

    human_readable_string = string_game_renderer.render(game)

    assert human_readable_string == (
        '---------------------\n'
        'Position:    [0, 0]\n'
        'Direction    NORTH\n'
        'Golds:       0\n'
        'Arrows left: 10\n'
        '---------------------\n'
        'Presences: \n'
        ' * A fresh breeze fills you with determination\n')
def it_returns_many_overlapped_presences():
    game = a_game().with_hunter(direction=Direction.SOUTH).build()
    game.wumpus.is_alive = False
    game.gold.position = game.player.position
    game.wumpus.position = game.player.position
    game.add_bottomless_pit(BottomlessPit(Vector2D(1, 0)))

    human_readable_string = string_game_renderer.render(game)

    assert human_readable_string == (
        '---------------------\n'
        'Position:    [0, 0]\n'
        'Direction    SOUTH\n'
        'Golds:       0\n'
        'Arrows left: 10\n'
        '---------------------\n'
        'Presences: \n'
        ' * You are in the exit position\n'
        ' * A fresh breeze fills you with determination\n'
        ' * You feel that Cupid is near after watch that arrow in the Wumpus heart\n'
        ' * It feels too strong to pass through... could it be a wall?\n'
        ' * The gold is here!\n')
Exemple #29
0
def it_builds_a_game_with_4x4_table():
    game = a_game().with_table(4, 4).build()

    assert game.status == GameStatus.PLAYING
    assert game.size == [4, 4]
Exemple #30
0
def it_fails_building_a_game_with_not_overlapped_entities_when_there_is_not_space_left_in_the_table():
    with raises(GameBuilderError):
        a_game().with_table(1, 1).with_bottomless_pits(quantity=15).build()