class GameOfLifeGto::Life
Public Class Methods
start()
click to toggle source
# File lib/game_of_life_gto.rb, line 142 def self.start puts 'Conway\'s Game of Life - JJaimelr version' puts 'WELCOME' puts 'Please choose an option to watch the game in action' puts '[1] random' puts '[2] pattern' option = gets.chomp.to_s case option when 'random', '1' puts 'Enter the loop size' loop_size = gets.chomp.to_i board = Board.new(40, 40) blinkerBoard = Board.new(5, 5) board.display game = Game.new(board) game.play loop_size when 'pattern', '2' self.watch_pattern else puts '*Confused* Do you enter the number (or name) of the option? If so, could you please try again?' end end
watch_pattern()
click to toggle source
# File lib/game_of_life_gto.rb, line 165 def self.watch_pattern puts 'Enter the name or the number of the pattern' puts '[1] blinker' puts '[2] beacon' puts '[3] block' puts '[4] pulsar' puts '[5] glider' pattern = gets.chomp puts 'Enter the loop size' loop_size = gets.chomp.to_i case pattern when 'blinker', '1' board = Board.new(5, 5) board.reset board.array[2][1] = Cell.new(1) board.array[2][2] = Cell.new(1) board.array[2][3] = Cell.new(1) when 'beacon', '2' board = Board.new(6, 6) board.reset board.array[1][1] = Cell.new(1) board.array[1][2] = Cell.new(1) board.array[2][1] = Cell.new(1) board.array[4][3] = Cell.new(1) board.array[4][4] = Cell.new(1) board.array[3][4] = Cell.new(1) when 'block', '3' board = Board.new(4, 4) board.reset board.array[1][1] = Cell.new(1) board.array[1][2] = Cell.new(1) board.array[2][1] = Cell.new(1) board.array[2][2] = Cell.new(1) when 'pulsar', '4' board = Board.new(6, 6) board.reset board.array[2][2] = Cell.new(1) board.array[2][3] = Cell.new(1) board.array[2][4] = Cell.new(1) board.array[3][1] = Cell.new(1) board.array[3][2] = Cell.new(1) board.array[3][3] = Cell.new(1) when 'glider', '5' board = Board.new(20, 20) board.reset board.array[1][2] = Cell.new(1) board.array[2][3] = Cell.new(1) board.array[3][1] = Cell.new(1) board.array[3][2] = Cell.new(1) board.array[3][3] = Cell.new(1) board.display else puts 'Pattern not found' end game = Game.new(board) board.display game.play loop_size end