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



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/lib/game_states/build_state.rb', line 59

def draw
  # Combine parts according to if there already is some project set
  unit_text = "Built so far in " + @unit.to_s + ":"
  if @unit.project
    project_text = "
      #{@unit.parts_built} " +
      "part#{ 's' unless @unit.parts_built == 1 } of " +
      @unit.project.name + " (" + @unit.build_info + ")"
  else
    project_text = "
      no project selected"
  end

  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 – none
      Esc – cancel project #{ @unit.project ? 'change' : 'setup'}"

  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

#reset_function!Object

If “none” project was selected reset also the function



53
54
55
56
57
# File 'lib/lib/game_states/build_state.rb', line 53

def reset_function!()
  puts PROMPT + @unit.to_s + ": no project selected, resetting function"
  @unit.set_function!(FUNCNONE)
  GameState.switch!(PlayState.instance)
end

#update(button) ⇒ Object

Process given button to cursor



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
50
# File 'lib/lib/game_states/build_state.rb', line 25

def update(button)
  project = nil

  case(button)
  when Gosu::KbEscape then
    # If there was no project selected before then behave same as "none" option
    unless @unit.project
      reset_function!()
    else
      puts PROMPT + @unit.to_s + ": cancelling, nothing changed"
      GameState.switch!(PlayState.instance)
    end
  when Gosu::Kb0, Gosu::KbN then
    reset_function!()
  when Gosu::Kb1, Gosu::KbA then
    project = Army
  when Gosu::Kb2, Gosu::KbS then
    project = Ship
  end

  # Did we get any proper answer?
  if project
    @unit.set_project!(project)
    GameState.switch!(PlayState.instance)
  end
end