Class: TerminalGameEngine::Engine
- Inherits:
-
Object
- Object
- TerminalGameEngine::Engine
- Defined in:
- lib/terminal_game_engine/engine.rb
Constant Summary collapse
- DEFAULT_TICK_SLEEP =
0.1
Instance Attribute Summary collapse
-
#tick ⇒ Object
Returns the value of attribute tick.
-
#tick_sleep ⇒ Object
Returns the value of attribute tick_sleep.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(tick_sleep: DEFAULT_TICK_SLEEP, &block) ⇒ Engine
constructor
A new instance of Engine.
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
#tick ⇒ Object
Returns the value of attribute tick.
5 6 7 |
# File 'lib/terminal_game_engine/engine.rb', line 5 def tick @tick end |
#tick_sleep ⇒ Object
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
#call ⇒ Object
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 |