rsb-gol 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rsb/gol/game.rb +13 -6
- data/lib/rsb/gol/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3da5ccda1bc86c201ea34f365e97e54f96e3852
|
4
|
+
data.tar.gz: 227feae90ef9c9cab4c6cd437d2022892947229f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 426fda512a0efc72141d96d9039467891068522db30ac8b0ef840a143529cf7a0c581c91ddef9c10251516958db6f0f3d3aca79276cbda7d345e81a4b93f18e4
|
7
|
+
data.tar.gz: 0d2b80588b01f2ff3d77f851454557bf6e664ece729d998caff8cdeed2d5c409b972efe303ea2806a15c6ff3ad43919dee064b9ae1fa5eb7a0b064fd708c121f
|
data/lib/rsb/gol/game.rb
CHANGED
@@ -3,15 +3,21 @@ module Rsb
|
|
3
3
|
class Game
|
4
4
|
CLEAR_SCREEN_CHAR = "\e[H\e[2J"
|
5
5
|
|
6
|
-
attr_reader :universe
|
6
|
+
attr_reader :universe, :stop_running
|
7
7
|
attr_accessor :seed
|
8
8
|
|
9
9
|
def initialize(options = {})
|
10
|
-
random_seed
|
11
|
-
rows
|
12
|
-
cols
|
13
|
-
grid
|
14
|
-
@universe
|
10
|
+
random_seed = options[:random_seed] == false ? false : true
|
11
|
+
rows = options[:rows] || 40
|
12
|
+
cols = options[:cols] || 80
|
13
|
+
grid = Rsb::Gol::Grid.new(rows, cols, random_seed)
|
14
|
+
@universe = options[:universe] || Rsb::Gol::Universe.new(grid: grid)
|
15
|
+
@stop_running = false
|
16
|
+
|
17
|
+
trap('INT') do
|
18
|
+
puts "\ngame of life will now stop running\n"
|
19
|
+
@stop_running = true
|
20
|
+
end
|
15
21
|
end
|
16
22
|
|
17
23
|
def clear_screen
|
@@ -26,6 +32,7 @@ module Rsb
|
|
26
32
|
def start(iterations = 1000, alive='0', dead=' ', step=3)
|
27
33
|
clear_screen
|
28
34
|
iterations.times do
|
35
|
+
exit if stop_running
|
29
36
|
data = universe.tick!
|
30
37
|
abort('empty universe') if data[:empty_universe]
|
31
38
|
status = status_line(data)
|
data/lib/rsb/gol/version.rb
CHANGED