From 54fe76a7ff4b7857b2cd8668622e16949abcb161 Mon Sep 17 00:00:00 2001 From: Joel Quenneville Date: Thu, 20 Sep 2012 15:08:20 -0500 Subject: [PATCH] split display logic into separate function --- lib/life/cli.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/life/cli.rb b/lib/life/cli.rb index 7afab94..aa92dc2 100644 --- a/lib/life/cli.rb +++ b/lib/life/cli.rb @@ -17,13 +17,8 @@ class Base < Thor def new seed = build_seed(options[:seed]) max_gen = options[:generations] - world = World.new(options[:height], options[:width] seed) - - (1..max_gen).each do |gen| - print world.to_s("@", "_") + eol(options[:height], gen, max_gen) - sleep(1) - world.tick - end + world = World.new(options[:height], options[:width], seed) + display_simulation max_gen, options[:height], world end no_tasks do @@ -34,6 +29,14 @@ def eol(height, curr_gen, max_gen) def build_seed(pattern) pattern.map {|pair| pair.split(":").map { |coord| coord.to_i - 1 } } end + + def display_simulation(max_gen, height, world) + (1..max_gen).each do |gen| + print world.to_s("@", "_") + eol(height, gen, max_gen) + sleep(1) + world.tick + end + end end end