Navigation Menu

Skip to content

Commit

Permalink
split display logic into separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Quenneville committed Sep 20, 2012
1 parent 904adc4 commit 54fe76a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/life/cli.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 54fe76a

Please sign in to comment.