class BuildState

Game state of selection of the build project

Attributes

unit[RW]

Public Instance Methods

draw() click to toggle source
# 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 + ")"
  options_text = "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" + options_text, 20)
  build_project.draw((2*TILESIZE) + XTEXT, (2*TILESIZE) + YTEXT, ZTEXT)
end
update(button) click to toggle source

Process given button

# File lib/lib/game_states/build_state.rb, line 24
def update(button)
  newly_selected = nil

  case(button)
  # 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