class PirateGame::Stage
Constants
- DURATION
- FAILURE
- IN_PROGRESS
- ITEMS_PER_BRIDGE
- SUCCESS
Attributes
actions_completed[RW]
all_items[RW]
begin_time[RW]
level[RW]
player_stats[RW]
players[RW]
Public Class Methods
new(level, players)
click to toggle source
# File lib/pirate_game/stage.rb, line 19 def initialize(level, players) @level = level @players = players @actions_completed = 0 @player_stats = {} generate_all_items @begin_time = Time.now end
Public Instance Methods
bridge_for_player()
click to toggle source
# File lib/pirate_game/stage.rb, line 67 def bridge_for_player @boards.shift end
complete(action, from)
click to toggle source
# File lib/pirate_game/stage.rb, line 71 def complete action, from @actions_completed += 1 @player_stats[from] ||= [] @player_stats[from] << action end
failure?()
click to toggle source
# File lib/pirate_game/stage.rb, line 53 def failure? status == FAILURE end
generate_all_items()
click to toggle source
# File lib/pirate_game/stage.rb, line 57 def generate_all_items @all_items = [] while @all_items.length < @players*ITEMS_PER_BRIDGE thing = PirateCommand.thing @all_items << thing unless @all_items.include?(thing) end @boards = @all_items.each_slice(ITEMS_PER_BRIDGE).to_a end
in_progress?()
click to toggle source
# File lib/pirate_game/stage.rb, line 45 def in_progress? status == IN_PROGRESS end
increment()
click to toggle source
# File lib/pirate_game/stage.rb, line 29 def increment PirateGame::Stage.new self.level + 1, self.players end
passed?()
click to toggle source
# File lib/pirate_game/stage.rb, line 81 def passed? @actions_completed >= required_actions end
required_actions()
click to toggle source
# File lib/pirate_game/stage.rb, line 77 def required_actions @level * 2 + 1 end
rundown()
click to toggle source
# File lib/pirate_game/stage.rb, line 85 def rundown return if status == IN_PROGRESS rundown = {stage: @level, total_actions: @actions_completed} rundown[:player_breakdown] = {} @player_stats.each {|p,v| rundown[:player_breakdown][p] = v.size} rundown end
status()
click to toggle source
# File lib/pirate_game/stage.rb, line 37 def status if time_left > 0 IN_PROGRESS else passed? ? SUCCESS : FAILURE end end
success?()
click to toggle source
# File lib/pirate_game/stage.rb, line 49 def success? status == SUCCESS end
time_left()
click to toggle source
# File lib/pirate_game/stage.rb, line 33 def time_left [0, (begin_time + DURATION) - Time.now].max end