You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

26 lines
681 B

class Player < ApplicationRecord
attribute :progress, :json, default: {}
attribute :current_stage, :integer, default: 1
attribute :score, :integer, default: 0
# stage_index: 1, 2, 3...
# outcome: 'chance' or 'choice'
def record_flip(stage_index, outcome)
self.progress[stage_index.to_s] ||= {}
self.progress[stage_index.to_s]["flip"] = outcome
save
end
# stage_index: 1, 2, 3...
# option_index: 1, 2, or 3
def record_option(stage_index, option_index)
self.progress[stage_index.to_s] ||= {}
self.progress[stage_index.to_s]["option"] = option_index
save
end
def advance_to_next_stage!
self.current_stage += 1
save
end
end