Class: PirateGame::Stage
- Inherits:
-
Object
- Object
- PirateGame::Stage
- Defined in:
- lib/pirate_game/stage.rb
Constant Summary collapse
- ITEMS_PER_BRIDGE =
6
- DURATION =
PirateGame::Boot.config["stage_duration"]
- IN_PROGRESS =
'In Progress'
- SUCCESS =
'Success'
- FAILURE =
'Failure'
Instance Attribute Summary collapse
-
#actions_completed ⇒ Object
Returns the value of attribute actions_completed.
-
#all_items ⇒ Object
Returns the value of attribute all_items.
-
#begin_time ⇒ Object
Returns the value of attribute begin_time.
-
#level ⇒ Object
Returns the value of attribute level.
-
#player_stats ⇒ Object
Returns the value of attribute player_stats.
-
#players ⇒ Object
Returns the value of attribute players.
Instance Method Summary collapse
- #bridge_for_player ⇒ Object
- #complete(action, from) ⇒ Object
- #failure? ⇒ Boolean
- #generate_all_items ⇒ Object
- #in_progress? ⇒ Boolean
- #increment ⇒ Object
-
#initialize(level, players) ⇒ Stage
constructor
A new instance of Stage.
- #passed? ⇒ Boolean
- #required_actions ⇒ Object
- #rundown ⇒ Object
- #status ⇒ Object
- #success? ⇒ Boolean
- #time_left ⇒ Object
Constructor Details
#initialize(level, players) ⇒ Stage
Returns a new instance of Stage.
19 20 21 22 23 24 25 26 27 |
# 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 |
Instance Attribute Details
#actions_completed ⇒ Object
Returns the value of attribute actions_completed.
5 6 7 |
# File 'lib/pirate_game/stage.rb', line 5 def actions_completed @actions_completed end |
#all_items ⇒ Object
Returns the value of attribute all_items.
7 8 9 |
# File 'lib/pirate_game/stage.rb', line 7 def all_items @all_items end |
#begin_time ⇒ Object
Returns the value of attribute begin_time.
8 9 10 |
# File 'lib/pirate_game/stage.rb', line 8 def begin_time @begin_time end |
#level ⇒ Object
Returns the value of attribute level.
9 10 11 |
# File 'lib/pirate_game/stage.rb', line 9 def level @level end |
#player_stats ⇒ Object
Returns the value of attribute player_stats.
6 7 8 |
# File 'lib/pirate_game/stage.rb', line 6 def player_stats @player_stats end |
#players ⇒ Object
Returns the value of attribute players.
10 11 12 |
# File 'lib/pirate_game/stage.rb', line 10 def players @players end |
Instance Method Details
#bridge_for_player ⇒ Object
67 68 69 |
# File 'lib/pirate_game/stage.rb', line 67 def bridge_for_player @boards.shift end |
#complete(action, from) ⇒ Object
71 72 73 74 75 |
# File 'lib/pirate_game/stage.rb', line 71 def complete action, from @actions_completed += 1 @player_stats[from] ||= [] @player_stats[from] << action end |
#failure? ⇒ Boolean
53 54 55 |
# File 'lib/pirate_game/stage.rb', line 53 def failure? status == FAILURE end |
#generate_all_items ⇒ Object
57 58 59 60 61 62 63 64 65 |
# 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? ⇒ Boolean
45 46 47 |
# File 'lib/pirate_game/stage.rb', line 45 def in_progress? status == IN_PROGRESS end |
#increment ⇒ Object
29 30 31 |
# File 'lib/pirate_game/stage.rb', line 29 def increment PirateGame::Stage.new self.level + 1, self.players end |
#passed? ⇒ Boolean
81 82 83 |
# File 'lib/pirate_game/stage.rb', line 81 def passed? @actions_completed >= required_actions end |
#required_actions ⇒ Object
77 78 79 |
# File 'lib/pirate_game/stage.rb', line 77 def required_actions @level * 2 + 1 end |
#rundown ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# 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 ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/pirate_game/stage.rb', line 37 def status if time_left > 0 IN_PROGRESS else passed? ? SUCCESS : FAILURE end end |
#success? ⇒ Boolean
49 50 51 |
# File 'lib/pirate_game/stage.rb', line 49 def success? status == SUCCESS end |
#time_left ⇒ Object
33 34 35 |
# File 'lib/pirate_game/stage.rb', line 33 def time_left [0, (begin_time + DURATION) - Time.now].max end |