Class: BuildState
- Includes:
- Singleton
- Defined in:
- lib/lib/game_states/build_state.rb
Overview
Game state of selection of the build project
Instance Attribute Summary collapse
-
#unit ⇒ Object
Returns the value of attribute unit.
Instance Method Summary collapse
- #draw ⇒ Object
-
#update(button) ⇒ Object
Process given button.
Methods inherited from GameState
#after_start, #before_end, switch!
Instance Attribute Details
#unit ⇒ Object
Returns the value of attribute unit.
13 14 15 |
# File 'lib/lib/game_states/build_state.rb', line 13 def unit @unit end |
Instance Method Details
#draw ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/lib/game_states/build_state.rb', line 51 def draw # Combine parts according to if there already is some project set unit_text = "Built so far in " + @unit.to_s + ":" project_text = " #{@unit.parts_built} " + "part#{ 's' unless @unit.parts_built == 1 } of " + @unit.project.name + " (" + @unit.build_info + ")" = "Select the project:\n 1, A – Army (#{ @unit.price_list[Army] } turns) 2, S – Ship (#{ @unit.price_list[Ship] } turns)\n 0, N – pause production Esc – cancel change of project" build_project = Gosu::Image.from_text( unit_text + "\n" + project_text + "\n\n" + , 20) build_project.draw((2*TILESIZE) + XTEXT, (2*TILESIZE) + YTEXT, ZTEXT) end |
#update(button) ⇒ Object
Process given button
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/lib/game_states/build_state.rb', line 24 def update() newly_selected = nil case() # Cancelled change of project = return when Gosu::KbEscape then puts PROMPT + @unit.to_s + ": cancelling, nothing changed" GameState.switch!(PlayState.instance) # Paused production = reset function and return when Gosu::Kb0, Gosu::KbN then puts PROMPT + @unit.to_s + ": production paused, resetting function" @unit.set_function!(FUNCNONE, @unit.faction) GameState.switch!(PlayState.instance) # Selected new project = set it and return when Gosu::Kb1, Gosu::KbA then newly_selected = Army when Gosu::Kb2, Gosu::KbS then newly_selected = Ship end # Did we get any proper answer? if newly_selected @unit.set_project!(newly_selected) GameState.switch!(PlayState.instance) end end |