Class: Life::CLI::Base
- Inherits:
-
Thor
- Object
- Thor
- Life::CLI::Base
- 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 |
#new ⇒ Object
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 [:width], [:height], seed (1..[:generations]).each do |gen| puts "== Generation #{gen} ==" draw(world) puts "" world.tick end end |