Class: Conway::Driver::Ascii

Inherits:
Object
  • Object
show all
Defined in:
lib/conway/driver/ascii.rb

Instance Method Summary collapse

Constructor Details

#initialize(size, starting_cells, options = {}) ⇒ Ascii

Returns a new instance of Ascii.



6
7
8
9
10
# File 'lib/conway/driver/ascii.rb', line 6

def initialize(size, starting_cells, options={})
  self.max_x          = self.max_y = size
  self.starting_cells = starting_cells
  self.options        = {:loop_interval => 0.25}.merge(options)
end

Instance Method Details

#loopObject



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
# File 'lib/conway/driver/ascii.rb', line 12

def loop
  generation = Generation.new(starting_cells)
  start      = Time.now

  puts "They live!!\n\n"

  begin
    lookup = generation.location_lookup

    grid =  generate_grid(lookup)

    if options[:display_stats]
      grid << current_stats(lookup)
      grid << elapsed_time_since(start)
    end

    yield grid if block_given?

    if lookup.empty?
      puts "\nThey have all perished! D-:"
      break
    end

    sleep(options[:loop_interval])
  end while(generation = generation.next)
end