Class: PlayState
- Includes:
- Singleton
- Defined in:
- lib/lib/game_states/play_state.rb
Overview
Game state of main gameplay
Instance Attribute Summary collapse
-
#desired_new_map ⇒ Object
writeonly
Sets the attribute desired_new_map.
-
#map ⇒ Object
readonly
Returns the value of attribute map.
Instance Method Summary collapse
-
#after_start ⇒ Object
Load new scenario or resume game.
-
#before_end ⇒ Object
What to do just before state gets deactivated.
-
#draw ⇒ Object
Draw all parts of main window.
-
#help ⇒ Object
Printout the controls.
-
#load_new_map! ⇒ Object
Load the desired map.
-
#next_faction_turn! ⇒ Object
End turn of the active faction.
-
#update(button) ⇒ Object
Process given button or send it to cursor.
Methods inherited from GameState
Instance Attribute Details
#desired_new_map=(value) ⇒ Object (writeonly)
Sets the attribute desired_new_map
30 31 32 |
# File 'lib/lib/game_states/play_state.rb', line 30 def desired_new_map=(value) @desired_new_map = value end |
#map ⇒ Object (readonly)
Returns the value of attribute map.
29 30 31 |
# File 'lib/lib/game_states/play_state.rb', line 29 def map @map end |
Instance Method Details
#after_start ⇒ Object
Load new scenario or resume game
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/lib/game_states/play_state.rb', line 33 def after_start if @desired_new_map load_new_map! help # show help after each loading of a new map @desired_new_map = nil next_faction_turn! # so FAC1 will be the first active faction, with announcement else # Make sure everything is set up unless @infopane and @map and @cursor abort("PlayState.after_start(): Map parts are not properly loaded (#{@infopane}, #{@map}, #{@cursor})") end @cursor.info_stopped = false # Remind player the current status if @cursor.freeroam @infopane.text = 'freeroam is enabled' puts 'freeroam is enabled' else @cursor.info end end end |
#before_end ⇒ Object
What to do just before state gets deactivated
60 61 62 |
# File 'lib/lib/game_states/play_state.rb', line 60 def before_end @cursor.info_stopped = true end |
#draw ⇒ Object
Draw all parts of main window
79 80 81 82 83 |
# File 'lib/lib/game_states/play_state.rb', line 79 def draw @map.draw_tiles @cursor.draw @infopane.draw end |
#help ⇒ Object
Printout the controls
128 129 130 131 132 133 134 |
# File 'lib/lib/game_states/play_state.rb', line 128 def help puts "-----------\n" \ "h: help, Esc: menu, Enter: info, j: switch freeroam\n" \ "QWEADZXC or arrow keys: movement, .: end your turn\n" \ "functions: s sentry, b build, n none\n" \ "-----------\n" end |
#load_new_map! ⇒ Object
Load the desired map
86 87 88 89 90 91 92 93 |
# File 'lib/lib/game_states/play_state.rb', line 86 def load_new_map! puts("=============\n" \ "=============\n" \ "Loading save: #{@desired_new_map}") @infopane = Infopane.new @map = Map.new(@desired_new_map, @infopane) @cursor = Cursor.new(0, 0, @map, @infopane) end |
#next_faction_turn! ⇒ Object
End turn of the active faction
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/lib/game_states/play_state.rb', line 96 def next_faction_turn! @infopane.next_faction! # Have all factions played this turn so we are now back at the first one? if @infopane.faction == 1 puts "=============\n" \ "End of turn\n" \ "=============\n" @infopane.next_turn! end # Announce game state at the start of turn of the next faction # TODO add change-of-active-faction screen puts "-----------\n" + @infopane.turnscore # Activate functions and reset moves for units of the next faction functionable_faction_units = @map.all_units.select { |uu| uu.faction == @infopane.faction and uu.function != FUNCNONE } functionable_faction_units.each { |uu| uu.function! } all_faction_units = @map.all_units.select { |uu| uu.faction == @infopane.faction } all_faction_units.each { |uu| uu.reset_moves!} # Lock the cursor to the first waiting unit @cursor.reset! end |
#update(button) ⇒ Object
Process given button or send it to cursor
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/lib/game_states/play_state.rb', line 65 def update() case() when Gosu::KbEscape then GameState.switch!(WelcomeState.instance) when Gosu::KbPeriod then next_faction_turn! when Gosu::KbH then help else @cursor.update() end end |