Class: SlackGame::Game::Lifegame

Inherits:
Object
  • Object
show all
Defined in:
lib/slack_game/game/lifegame.rb,
lib/slack_game/game/lifegame/canvas.rb

Defined Under Namespace

Classes: Canvas, Cell, Field

Instance Method Summary collapse

Constructor Details

#initialize(channel, size = 10) ⇒ Lifegame

Returns a new instance of Lifegame.



6
7
8
9
10
11
# File 'lib/slack_game/game/lifegame.rb', line 6

def initialize(channel, size = 10)
  @canvas = Canvas.new(channel, size, size)
  @field = Field.new(size)
  @canvas.matrix = @field.to_display
  @canvas.draw
end

Instance Method Details

#main_loopObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/slack_game/game/lifegame.rb', line 13

def main_loop
  loop{
    begin
      update
    rescue => e
      puts "GAME OVER #{e.message}"
      break
    end
  }
end

#updateObject



24
25
26
27
# File 'lib/slack_game/game/lifegame.rb', line 24

def update
  @canvas.matrix = @field.next.to_display
  @canvas.draw
end