Skip to content

Instantly share code, notes, and snippets.

@jonsmock
Created May 3, 2012 20:06
Show Gist options
  • Select an option

  • Save jonsmock/2588878 to your computer and use it in GitHub Desktop.

Select an option

Save jonsmock/2588878 to your computer and use it in GitHub Desktop.

Revisions

  1. jonsmock created this gist May 3, 2012.
    16 changes: 16 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    # in board initialize
    lookup = PlaceLookup.new
    lookup.add Buildable.new, Coord.new(3, 4) # coords would be calculated from land hexes

    # later
    player = Player.new
    PlaceLookup.build_at player, Coord.new(3, 4)
    PlaceLookup.at Coord.new(3, 4) # => Settlement.new

    The PlaceLookup mutates behind the scenes. So potential impl of #build_at is
    class PlaceLookup
    def build_at player, coord
    # when you call build on a Buildable object you get a Settlement.new back
    @places[coord] = @places[coord].build player
    end
    end