samples/99_genre_rpg_roguelike/02_roguelike_line_of_sight/app/main.rb
# Updates the line of sight by calling the thick_line_of_sight method and
# adding dungeon cells to the newly_visible collection
Updates the line of sight by calling the thick_line_of_sight method and
adding dungeon cells to the newly_visible collection
Updates the line of sight by calling the thick_line_of_sight method and adding dungeon cells to the newly_visible collection
def update_line_of_sight
    variations = [-1, 0, 1]
    newly_visible = variations.product(variations).flat_map do |rise, run| 
      thick_line_of_sight state.x, state.y, rise, run, 15, 
                          lambda { |x, y| dungeon_cell_exists? x, y } 
    end.uniq
    state.dungeon.each do |d| 
      d.is_visible = newly_visible.find { |v| v.x == d.x && v.y == d.y } 
    end
  end
def update_line_of_sight variations = [ - 1 , 0 , 1 ] newly_visible = variations . product ( variations ) . flat_map do | rise , run | thick_line_of_sight state . x , state . y , rise , run , 15 , lambda { | x , y | dungeon_cell_exists? x , y } end . uniq state . dungeon . each do | d | d . is_visible = newly_visible . find { | v | v . x == d . x && v . y == d . y } end end
Updates the line of sight by calling the thick_line_of_sight method and
adding dungeon cells to the newly_visible collection
Updates the line of sight by calling the thick_line_of_sight method and adding dungeon cells to the newly_visible collection
# creates collection of newly visible dungeon cells # combo of all elements # calls thick_line_of_sight method # checks whether or not cell exists # removes duplicates # perform action on each element of dungeons collection # finds match inside newly_visible collection