main
1class Game
2 def initialize(printer)
3 @printer = printer
4 end
5
6 def play(max_x, max_y)
7 World.new(create_cells(max_x, max_y)).tap do |world|
8 until world.empty? do
9 @printer.display(world)
10 world.next_generation!
11 end
12 end
13 end
14
15 def create_cells(max_x, max_y)
16 items = []
17 (1..max_x).each do |x|
18 (1..max_y).each do |y|
19 items.push(Cell.new(x: x, y: y, alive: random_life))
20 end
21 end
22 items
23 end
24
25 private
26
27 def random_life
28 rand(100).even?
29 end
30end