Created
May 3, 2012 20:06
-
-
Save jonsmock/2588878 to your computer and use it in GitHub Desktop.
Possible solution for place mutation (somewhat functional approach)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment