Class: Life::CLI::Base

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/life/cli.rb

Instance Method Summary collapse

Instance Method Details

#draw(world) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/life/cli.rb', line 34

def draw(world)
  world.current.each do |row|
    processed_row = row.map { |cell| cell.live? ? "@" : "_"}
    print "["
    print processed_row.join(' ')
    puts "]"
  end
end

#newObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/life/cli.rb', line 16

def new
  seed = []
  while yes? "Would you like to add a live cell to the grid? [Y/n]"
    x = ask "Please enter x coordinate"
    y = ask "Please enter y coordinate"
    seed << [(x.to_i) - 1, (y.to_i) -1]
  end

  world = World.new options[:width], options[:height], seed

  (1..options[:generations]).each do |gen|
    puts "== Generation #{gen} =="
    draw(world)
    puts ""
    world.tick
  end
end