-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLifeGame_view.rb
More file actions
39 lines (32 loc) · 1.25 KB
/
LifeGame_view.rb
File metadata and controls
39 lines (32 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'gosu'
require_relative 'cell.rb'
require_relative 'game.rb'
require_relative 'world.rb'
class GameWindow < Gosu::Window
def initialize(height, width, acolor, dcolor, cell_height, cell_width, game)
@height = height
@width = width
@alive_color = acolor
@dead_color = dcolor
@cell_height = cell_height
@cell_width = cell_width
@game = game
super @height, @width
self.caption = "Life Game"
end
def draw
@game.world.cells.each do |cell|
if cell.alive?
draw_quad(cell.x * @cell_width, cell.y * @cell_height, @alive_color,
cell.x * @cell_width + @cell_width, cell.y * @cell_height, @alive_color,
cell.x * @cell_width + @cell_width, cell.y * @cell_height + @cell_height, @alive_color,
cell.x * @cell_width, cell.y * @cell_height + @cell_height, @alive_color)
else
draw_quad(cell.x * @cell_width, cell.y * @cell_height, @dead_color,
cell.x * @cell_width + @cell_width, cell.y * @cell_height, @dead_color,
cell.x * @cell_width + @cell_width, cell.y * @cell_height + @cell_height, @dead_color,
cell.x * @cell_width, cell.y * @cell_height + @cell_height, @dead_color)
end
end
end
end