Class: TerminalGameEngine::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/terminal_game_engine/engine.rb

Constant Summary collapse

DEFAULT_TICK_SLEEP =
0.1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tick_sleep: DEFAULT_TICK_SLEEP, &block) ⇒ Engine

Returns a new instance of Engine.



11
12
13
14
15
# File 'lib/terminal_game_engine/engine.rb', line 11

def initialize(tick_sleep: DEFAULT_TICK_SLEEP, &block)
  @tick = 0
  @block = block
  @tick_sleep = tick_sleep
end

Instance Attribute Details

#tickObject

Returns the value of attribute tick.



5
6
7
# File 'lib/terminal_game_engine/engine.rb', line 5

def tick
  @tick
end

#tick_sleepObject

Returns the value of attribute tick_sleep.



5
6
7
# File 'lib/terminal_game_engine/engine.rb', line 5

def tick_sleep
  @tick_sleep
end

Class Method Details

.tick(*args, &block) ⇒ Object



7
8
9
# File 'lib/terminal_game_engine/engine.rb', line 7

def self.tick(*args, &block)
  self.new(*args, &block).tap(&:call)
end

Instance Method Details

#callObject



17
18
19
20
21
22
23
# File 'lib/terminal_game_engine/engine.rb', line 17

def call
  loop do
    @block.call @tick
    @tick += 1
    sleep tick_sleep
  end
end