terminal_game_engine 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +25 -0
- data/examples/counter.rb +28 -27
- data/lib/terminal_game_engine.rb +5 -0
- data/lib/terminal_game_engine/engine_proxy.rb +21 -0
- data/lib/terminal_game_engine/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d5e89be3b16dac322f0d73efaca372e026d0d5e
|
4
|
+
data.tar.gz: 81e5e68033fb0d9f567bc980fc609acd7027eaff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cf2c7b404b247dd2b3a72fdfb47079056ea58f93171eb4c9347e4b6775f5af1b484bb8f1cd6fdb3d782a078e0411a79053da934b0834fe9fbdf8b3e9440ce1d
|
7
|
+
data.tar.gz: 4961ccefbaff0971b9439375aba1d743ab67256ae959a73fb67f83ad0a49df9697a2188b674a7ed742662d359381819d87262356fd44f5ebf0ddb71716829c0e
|
data/README.markdown
CHANGED
@@ -16,6 +16,31 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install terminal_game_engine
|
18
18
|
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
``` ruby
|
22
|
+
require 'terminal_game_engine'
|
23
|
+
|
24
|
+
TerminalGameEngine.run do
|
25
|
+
on_tick do |tick|
|
26
|
+
width = tick.to_s.length
|
27
|
+
height = 1
|
28
|
+
frame = TerminalGameEngine::Frame.new width, height
|
29
|
+
|
30
|
+
frame.draw 0, 0, tick.to_s
|
31
|
+
|
32
|
+
on_input do |key_code|
|
33
|
+
case key_code
|
34
|
+
when TerminalGameEngine::Input::Keys::CTRL_C
|
35
|
+
exit
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
frame.render
|
40
|
+
end
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
19
44
|
## License
|
20
45
|
|
21
46
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/examples/counter.rb
CHANGED
@@ -1,32 +1,33 @@
|
|
1
1
|
require_relative '../lib/terminal_game_engine'
|
2
2
|
|
3
|
-
TerminalGameEngine
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
3
|
+
TerminalGameEngine.run do
|
4
|
+
on_tick do |tick|
|
5
|
+
number = tick.to_s
|
6
|
+
|
7
|
+
height = 3
|
8
|
+
width = number.length + 2
|
9
|
+
|
10
|
+
frame = TerminalGameEngine::Frame.new width, height
|
11
|
+
|
12
|
+
# draw number
|
13
|
+
frame.draw_center 1, number
|
14
|
+
|
15
|
+
# draw corners
|
16
|
+
frame.draw 0, 0, '+'
|
17
|
+
frame.draw 0, height-1, '+'
|
18
|
+
frame.draw width-1, 0, '+'
|
19
|
+
frame.draw width-1, height-1, '+'
|
20
|
+
|
21
|
+
on_input do |key_code|
|
22
|
+
case key_code
|
23
|
+
when 'q'.ord, TerminalGameEngine::Input::Keys::ESCAPE, TerminalGameEngine::Input::Keys::CTRL_C
|
24
|
+
exit
|
25
|
+
else
|
26
|
+
frame.draw 0, 1, ' ' * (number.length + 1)
|
27
|
+
frame.draw_center 1, key_code.chr
|
28
|
+
end
|
28
29
|
end
|
29
|
-
end
|
30
30
|
|
31
|
-
|
31
|
+
frame.render
|
32
|
+
end
|
32
33
|
end
|
data/lib/terminal_game_engine.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
class TerminalGameEngine::EngineProxy
|
2
|
+
def initialize(tick_sleep: nil)
|
3
|
+
@tick_sleep = tick_sleep
|
4
|
+
end
|
5
|
+
|
6
|
+
def on_tick(&block)
|
7
|
+
TerminalGameEngine::Engine.tick *tick_args, &block
|
8
|
+
end
|
9
|
+
|
10
|
+
def on_input(&block)
|
11
|
+
TerminalGameEngine::Input.call &block
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def tick_args
|
17
|
+
args = []
|
18
|
+
args << ({tick_sleep: @tick_sleep}) if @tick_sleep
|
19
|
+
args
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: terminal_game_engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Odin Dutton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- examples/counter.rb
|
71
71
|
- lib/terminal_game_engine.rb
|
72
72
|
- lib/terminal_game_engine/engine.rb
|
73
|
+
- lib/terminal_game_engine/engine_proxy.rb
|
73
74
|
- lib/terminal_game_engine/frame.rb
|
74
75
|
- lib/terminal_game_engine/input.rb
|
75
76
|
- lib/terminal_game_engine/network.rb
|