Class: PlayState

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

Overview

Game state of main gameplay

Instance Method Summary collapse

Methods inherited from GameState

switch!

Instance Method Details

#after_startObject

Load new scenario or resume game



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/lib/game_states/play_state.rb', line 30

def after_start
  unless @infopane and @map and @cursor # is everything set up yet?
    @infopane = Infopane.new
    @map = Map.new(@infopane)
    @cursor = Cursor.new(0, 0, @map, @infopane)
    help # show help after loading of map
    new_turn
  else
    @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_endObject

What to do just before state gets deactivated



51
52
53
# File 'lib/lib/game_states/play_state.rb', line 51

def before_end
  @cursor.info_stopped = true
end

#drawObject

Draw all parts of main window



70
71
72
73
74
# File 'lib/lib/game_states/play_state.rb', line 70

def draw
  @map.draw_tiles
  @cursor.draw
  @infopane.draw
end

#helpObject

Printout the controls



93
94
95
96
97
98
99
# File 'lib/lib/game_states/play_state.rb', line 93

def help
  puts "-----------\n" \
       "h: help, Esc: end game, Enter: info, j: switch freeroam\n" \
       "QWEADZXC or arrow keys: movement, .: end turn\n" \
       "functions: s sentry, b build, n none\n" \
       "-----------\n"
end

#new_turnObject

End current turn and start the next one



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/lib/game_states/play_state.rb', line 77

def new_turn
  puts "=============\n" \
       "End of turn\n" \
       "=============\n"

  functionable_units = @map.all_units.select { |uu| uu.function != FUNCNONE}
  functionable_units.each { |uu| uu.function! }

  @map.all_units.each { |uu| uu.reset_moves!}
  @infopane.next_turn

  @cursor.freeroam = true
  @cursor.switch_freeroam! # so freeroam = false, with messages
end

#update(button) ⇒ Object

Process given button or send it to cursor



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/lib/game_states/play_state.rb', line 56

def update(button)
  case(button)
  when Gosu::KbEscape then
    GameState.switch!(EscapeState.instance)
  when Gosu::KbPeriod then
    new_turn
  when Gosu::KbH then
    help
  else
    @cursor.update(button)
  end
end