I am creating a Game of Life in Ruby using Gosu. My code is below. Right now, when I run "ruby gosu.rb", it opens a window with the correct dimensions and a pre-populated world, as it should be.
But as soon as I uncomment "@ game.tick!" in action updating the gosu file when I run "ruby gosu.rb" I get a black screen without a pre-populated world that I cannot close. Why is this and how to fix it?
Here you can find the github repository with the rest of the code. Any help is awesome.
Here is my game_of_life.rb
class Game attr_accessor :world def initialize(world=World.new, seeds=[]) @world = world seeds.each do |seed| world.cell_board[seed[0]][seed[1]].alive = true end end def tick! next_round_live_cells = [] next_round_dead_cells = [] world.cells.each do |cell|
Here is my gosu code
require 'gosu' require_relative 'gol.rb' class GameOfLifeWindow < Gosu::Window def initialize(height=800, width=600) # Basics @height = height @width = width super height, width, false, 500 self.caption = 'My Game of Life' # Colors @white = Gosu::Color.new(0xffededed) @black = Gosu::Color.new(0xff121212) # Game world @rows = height/10 @cols = width/10 world = World.new(@cols, @rows) @game = Game.new(world) @row_height = height/@rows @col_width = width/@cols @game.world.randomly_populate @generation = 0 end def update # unless @game.world.live_cells.count == 0 # @game.tick! @generation += 1 # end end def draw @game.world.cells.each do |cell| if cell.alive? draw_quad(cell.x * @col_width, cell.y * @row_height, @black, cell.x * @col_width + @col_width, cell.y * @row_height, @black, cell.x * @col_width + @col_width, cell.y * @row_height + @row_height, @black, cell.x * @col_width, cell.y * @row_height + @row_height, @black) end end end def button_down(id) case id when Gosu::KbSpace @game.world.randomly_populate when Gosu::KbEscape close end end def draw_background draw_quad(0, 0, @white, width, 0, @white, width, height, @white, 0, height, @white) end end window = GameOfLifeWindow.new window.show