Class: BuildState

Inherits:
GameState show all
Includes:
Singleton
Defined in:
lib/lib/game_states/build_state.rb

Overview

Game state of closing the game window

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from GameState

#after_start, #before_end, switch!

Instance Attribute Details

#unitObject

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

#drawObject



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 + ")"
  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) ⇒ Object

Process given button to cursor



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(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