Class: Conway::Driver::Ascii
- Inherits:
-
Object
- Object
- Conway::Driver::Ascii
- Defined in:
- lib/conway/driver/ascii.rb
Instance Method Summary collapse
-
#initialize(size, starting_cells, options = {}) ⇒ Ascii
constructor
A new instance of Ascii.
- #loop ⇒ Object
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, ={}) self.max_x = self.max_y = size self.starting_cells = starting_cells self. = {:loop_interval => 0.25}.merge() end |
Instance Method Details
#loop ⇒ Object
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 [: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([:loop_interval]) end while(generation = generation.next) end |