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.
 
 
 
 
 

45 lines
1.0 KiB

class Player < ApplicationRecord
attribute :current_stage, :integer, default: 1
attribute :bonus_points, :integer, default: 0
attribute :progress, :json, default: {}
attribute :is_done, :boolean, default: false
scope :playing, -> { where(is_done: false) }
scope :done, -> { where(is_done: true) }
def is_playing?
!self.is_done?
end
def reset_when_game_over
self.progress = {}
self.current_stage = 1
self.save
end
# 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...
# result: 'good', 'bad', 'game_over'
def record_pick_result(stage_index, result)
self.progress[stage_index.to_s] ||= {}
self.progress[stage_index.to_s]["result"] = result
save
end
def record_bonus_pick_result(stage_index, result)
self.progress[stage_index.to_s] ||= {}
self.progress[stage_index.to_s]["bonus_result"] = result
save
end
end