Class: GameWindow

Inherits:
Gosu::Window
  • Object
show all
Defined in:
lib/lib/user_interface/game_window.rb

Overview

Main window

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version, width = WINDOW_WIDTH, height = WINDOW_HEIGHT, fullscreen = false) ⇒ GameWindow



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/lib/user_interface/game_window.rb', line 26

def initialize(version,
               width = WINDOW_WIDTH, \
               height = WINDOW_HEIGHT, \
               fullscreen = false)
  super(width, height, fullscreen)

  # Set version name
  self.caption = "Crane Construction #{version}"
  $debug = false # debug messages turned off by default
  reset!

  @background = Background.new()
  @infopane = Infopane.new(self)

  @brickyard = Brickyard.new()
  @crane = Crane.new()
  @hook = Hook.new(self, @brickyard, @crane)

  @brickyard.produce!
end

Instance Attribute Details

#winObject (readonly)

Returns the value of attribute win.



24
25
26
# File 'lib/lib/user_interface/game_window.rb', line 24

def win
  @win
end

Instance Method Details

#button_up(key) ⇒ Object

Start processing the pushed button



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/lib/user_interface/game_window.rb', line 48

def button_up(key)
  case key
  when Gosu::KB_ESCAPE then
    self.close
  when Gosu::KB_BACKSPACE then
    reset
  when Gosu::KB_TAB then
    switch_debug!
  else
    @button = key
  end
end

#check_winObject

Check whether player has won yet



76
77
78
# File 'lib/lib/user_interface/game_window.rb', line 76

def check_win
  false # TODO
end

#drawObject

Draw scene



81
82
83
84
85
86
87
88
# File 'lib/lib/user_interface/game_window.rb', line 81

def draw
  @background.draw
  @infopane.draw

  @brickyard.draw
  @crane.draw
  @hook.draw
end

#resetObject

Reset scene



91
92
93
94
95
96
# File 'lib/lib/user_interface/game_window.rb', line 91

def reset
  reset!
  @infopane.reset!
  @brickyard.reset!
  @hook.reset!
end

#reset!Object

Load default setup



99
100
101
# File 'lib/lib/user_interface/game_window.rb', line 99

def reset!
  @won = false
end

#switch_debug!Object

Switch debug flag



104
105
106
# File 'lib/lib/user_interface/game_window.rb', line 104

def switch_debug!
  $debug = !$debug
end

#updateObject

Process given button



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/lib/user_interface/game_window.rb', line 62

def update
  @infopane.update

  unless @won
    @brickyard.update(@button)
    @hook.update(@button)
    check_win
  end

  # Stop procsesing this button
  @button = nil
end