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
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)
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
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)
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
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
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
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
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
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_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
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
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_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_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
def turn(turn_direction, game): turn_in_radians = _turn_in_radians(turn_direction) turn_cos = math.cos(turn_in_radians) turn_sin = math.sin(turn_in_radians) game.player.direction = Vector2D( round(game.player.direction.x * turn_cos - game.player.direction.y * turn_sin), round(game.player.direction.x * turn_sin - game.player.direction.y * turn_cos) )
def _random_empty_table_position(self): if self._is_maximum_number_of_entities_reached(): raise GameBuilderError( 'Unable to allocate random empty table position') x = random.randint(0, self.game.size[0] - 1) y = random.randint(0, self.game.size[1] - 1) position = Vector2D(x, y) if self._is_position_already_taken(position): return self._random_empty_table_position() return position
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_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_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')
class Direction: NORTH = Vector2D(0, 1) EAST = Vector2D(1, 0) WEST = Vector2D(-1, 0) SOUTH = Vector2D(0, -1)
def it_builds_a_game_with_hunter_at_position_2x3_and_facing_south(): game = a_game()\ .with_hunter(position=Vector2D(2, 3), direction=Direction.SOUTH)\ .build() expect_quantity_of_arrows_left_for_player_in_game(10, game)
def with_hunter(self, position=Vector2D(0, 0), direction=Direction.NORTH, arrows=10): self.game.set_hunter(Hunter(position, direction, arrows)) return self