Class: Conwaymp::Game
- Inherits:
-
Object
- Object
- Conwaymp::Game
- Defined in:
- lib/conwaymp/game.rb
Instance Attribute Summary collapse
-
#board ⇒ Object
Returns the value of attribute board.
Class Method Summary collapse
Instance Method Summary collapse
- #display_errors(errors) ⇒ Object
-
#initialize ⇒ Game
constructor
A new instance of Game.
- #parse_options ⇒ Object
- #play ⇒ Object
Constructor Details
Instance Attribute Details
#board ⇒ Object
Returns the value of attribute board.
5 6 7 |
# File 'lib/conwaymp/game.rb', line 5 def board @board end |
Class Method Details
.available_seeds ⇒ Object
57 58 59 60 61 |
# File 'lib/conwaymp/game.rb', line 57 def self.available_seeds Dir.glob(File.('../../../seeds/*', __FILE__)).map do |f| File.basename(f) end end |
Instance Method Details
#display_errors(errors) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/conwaymp/game.rb', line 48 def display_errors errors errors = errors.map do |k,e| "#{k}: #{e.join(',')}".colorize(:red) end puts errors puts exit end |
#parse_options ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/conwaymp/game.rb', line 26 def @options = Slop.parse suppress_errors: true do |o| o.integer '-r', '--rows', 'Rows. Default: 20', default: 20 o.integer '-c', '--cols', 'Columns. Default: 20', default: 20 o.string '-l', '--load', 'Path to board state to load' o.string '-s', '--seed', 'Load a seed' o.on '-ls', '--seeds', 'List available seeds' do puts 'Available Seeds:' puts Conwaymp::Game.available_seeds exit end o.on '--version', 'print the version' do puts Conwaymp::VERSION exit end o.on '--help' do puts o exit end end end |
#play ⇒ Object
19 20 21 22 23 24 |
# File 'lib/conwaymp/game.rb', line 19 def play loop do @board.display @board.tick end end |