Skip to content

Instantly share code, notes, and snippets.

@brkane
Created October 16, 2012 18:33
Show Gist options
  • Save brkane/3901109 to your computer and use it in GitHub Desktop.
Save brkane/3901109 to your computer and use it in GitHub Desktop.
SimpleDelegator space_merchant?
#!/usr/bin/env ruby
#
# space_merchant
$LOAD_PATH << File.expand_path(File.dirname(__FILE__) + '/../lib')
require 'space_merchant'
include SpaceMerchant
player = SpaceMerchant::Player.instance
puts
puts "Welcome to Space Merchant #{SpaceMerchant::VERSION}, " +
"the Ruby Quiz game!"
puts
print "What would you like to be called, pilot? "
loop do
name = gets.chomp
if name =~ /\S/
player[:name] = name
puts "#{player[:name]} it is."
puts
puts "May you find fame and fortune here in the Ruby Galaxy..."
puts
break
else
print "Please enter a name: "
end
end
player[:credits] = 1000
# we initialize player[:location], it should be changed to move the player
player[:location] = SpaceMerchant::Galaxy.instance.starting_location
catch(:quit) do
# primary event loop
loop { player[:location].handle_event(player) }
end
#!/usr/bin/env ruby
#
# space_merchant.rb
require 'singleton'
require 'delegate'
module SpaceMerchant
VERSION = "1.0"
# We will use a basic Hash, but feel free to add methods to it
class Player
include Singleton
def initialize
@game_data = SimpleDelegator.new({})
end
end
end
require 'space_merchant/galaxy'
require 'space_merchant/sector'
require 'space_merchant/station'
require 'space_merchant/planet'
@cupakromer
Copy link

Try

class Player < SimpleDelegator
  def initialize
    super({})
  end
end

@cupakromer
Copy link

But add include Singleton

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment