class LemonadeStand::Game

Public Class Methods

new(number_of_players) click to toggle source
# File lib/lemonade_stand/game.rb, line 5
def initialize number_of_players
  @number_of_players = number_of_players
end

Public Instance Methods

days() click to toggle source
# File lib/lemonade_stand/game.rb, line 17
def days
  @days ||= []
end
make_choice(choice, options) click to toggle source
# File lib/lemonade_stand/game.rb, line 9
def make_choice choice, options
  player  = options[:player]
  day     = options[:day] || days.last
  results = day.sales_for choice 
  player.assets += results.profit
  store_sales_results_for results, player, day
end
players() click to toggle source
# File lib/lemonade_stand/game.rb, line 41
def players
  @players ||= (0...@number_of_players).map do |i|
                 p = LemonadeStand::Player.new
                 p.index = i
                 p.game = self
                 p
               end
end
sales_results_for(player, day) click to toggle source
# File lib/lemonade_stand/game.rb, line 34
def sales_results_for player, day
  @sales_results ||= []
  @sales_results.select do |record|
    return record[:results] if record[:player].object_id == player.object_id && record[:day].object_id == day.object_id
  end
end
start_a_new_day() click to toggle source
# File lib/lemonade_stand/game.rb, line 21
def start_a_new_day
  @days ||= []
  day = LemonadeStand::Day.new
  @days << day
  day.number = @days.count
  day
end
store_sales_results_for(results, player, day) click to toggle source
# File lib/lemonade_stand/game.rb, line 29
def store_sales_results_for results, player, day
  @sales_results ||= []
  @sales_results << { player: player, day: day, results: results }
end