tuvi 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +38 -33
- data/example_program.rb +28 -12
- data/lib/tuvi/application_runner.rb +2 -1
- data/lib/tuvi/step.rb +1 -1
- data/lib/tuvi/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -14,69 +14,74 @@ Here is a basic example program followed by an explanation:
|
|
14
14
|
|
15
15
|
require 'tuvi'
|
16
16
|
|
17
|
-
step
|
18
|
-
say "
|
19
|
-
response "
|
20
|
-
response "left" => 3
|
17
|
+
step "start" do
|
18
|
+
say "You have just woken up from a fitful sleep. You get out of your bed ... and you realize that you are not in your bedroom. As your eyes take in your surroundings, you realize that you are in some sort of dungeon. 'How did I get here?' you wonder. You see a small table with with a key on it."
|
19
|
+
response "take key" => "door"
|
21
20
|
end
|
22
21
|
|
23
|
-
step
|
24
|
-
say "You're
|
25
|
-
response "
|
26
|
-
response "
|
27
|
-
response "
|
22
|
+
step "door" do
|
23
|
+
say "You're holding the key. In front of you is a locked door with 3 locks. One is painted red, one is painted blue, and one is painted black. Which lock do you want to try the key on?"
|
24
|
+
response "red" => "locked door"
|
25
|
+
response "blue" => "locked door"
|
26
|
+
response "black" => "open door"
|
28
27
|
end
|
29
28
|
|
30
|
-
step
|
31
|
-
say "
|
32
|
-
response "
|
33
|
-
response "
|
29
|
+
step "locked door" do
|
30
|
+
say "Hmmm. That didn't work. Perhaps the key would work on a different lock..."
|
31
|
+
response "red" => "locked door"
|
32
|
+
response "blue" => "locked door"
|
33
|
+
response "black" => "open door"
|
34
34
|
end
|
35
35
|
|
36
|
-
step
|
37
|
-
say "
|
36
|
+
step "open door" do
|
37
|
+
say "It worked! The door swings open slowly, and you enter what seems to be a dark hallway. Eventually the hallway comes to a pair of staircases, one of which goes up, and the other of which goes down. You hear footsteps on the floor above you, and you wonder which staircase you should take."
|
38
|
+
response "up" => "second floor"
|
39
|
+
response "down" => "basement"
|
40
|
+
end
|
41
|
+
|
42
|
+
step "second floor" do
|
43
|
+
say "You walk up the stairs and see a strange creature. It comes towards you with its mouth gaping open and..."
|
38
44
|
stop
|
39
45
|
end
|
40
46
|
|
41
|
-
step
|
42
|
-
say "
|
47
|
+
step "basement" do
|
48
|
+
say "There's an open door in front of you, and you make your escape from the haunted castle!"
|
43
49
|
stop
|
44
50
|
end
|
45
51
|
|
46
52
|
First, create a ruby file and on the first line require the Tuvi library with `require 'tuvi'`
|
47
53
|
|
48
|
-
From here on in, the Tuvi language is used. As you can see, the program is divided into
|
54
|
+
From here on in, the Tuvi language is used. As you can see, the program is divided into Steps, which represent a step in the program where the program provides some instructions, and either prompts the user for input or simply exits.
|
49
55
|
|
50
56
|
Every step needs a `say`, which sets the computer's instructions for that step.
|
51
57
|
|
52
|
-
Every step can establish one or more lines declaring
|
58
|
+
Every step can establish one or more lines declaring a `response` which is followed first by a valid user response, a hashrocket arrow, and then by the Step title (as a string) that that particular user response should lead to.
|
53
59
|
|
54
|
-
Some steps, instead of having responses, can simply end the program using the `stop` keyword.
|
60
|
+
Some steps, instead of having responses, can simply `say` a message and then end the program using the `stop` keyword.
|
55
61
|
|
56
62
|
You can run this file like any other Ruby file, using `ruby filename.rb`.
|
57
63
|
|
58
|
-
You can also add
|
64
|
+
You can also add arbitrary Ruby code by placing it in a block passed to the `code` method. If you set a variable, you'll have to do it as global variable. For example:
|
59
65
|
|
60
|
-
step
|
61
|
-
code {$
|
66
|
+
step "start" do
|
67
|
+
code {$points = 0}
|
62
68
|
say "Welcome to KrazyMaze. Will you ever get out? BWAAHAAA! You have a choice to make: Go right or left"
|
63
|
-
response "right" =>
|
64
|
-
response "left" =>
|
69
|
+
response "right" => "middle"
|
70
|
+
response "left" => "east end"
|
65
71
|
end
|
66
72
|
|
67
|
-
step
|
73
|
+
step "middle" do
|
68
74
|
code do
|
69
|
-
$
|
70
|
-
puts "You have
|
75
|
+
$points += 1
|
76
|
+
puts "You have #{$points} points."
|
71
77
|
end
|
72
78
|
say "You're in the middle of the maze. Go right or left or straight."
|
73
|
-
response "right" =>
|
74
|
-
response "left" =>
|
75
|
-
response "straight" =>
|
79
|
+
response "right" => "west end"
|
80
|
+
response "left" => "start"
|
81
|
+
response "straight" => "dungeon"
|
76
82
|
end
|
77
83
|
|
78
|
-
|
79
|
-
## Contributing
|
84
|
+
## Contributing (please do!)
|
80
85
|
|
81
86
|
1. Fork it
|
82
87
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
data/example_program.rb
CHANGED
@@ -1,20 +1,36 @@
|
|
1
1
|
require_relative 'lib/tuvi.rb'
|
2
2
|
|
3
|
-
step
|
4
|
-
|
5
|
-
|
6
|
-
response "Yes" => 2
|
7
|
-
response "No" => 3
|
3
|
+
step "start" do
|
4
|
+
say "You have just woken up from a fitful sleep. You get out of your bed ... and you realize that you are not in your bedroom. As your eyes take in your surroundings, you realize that you are in some sort of dungeon. 'How did I get here?' you wonder. You see a small table with with a key on it."
|
5
|
+
response "take key" => "door"
|
8
6
|
end
|
9
7
|
|
10
|
-
step
|
11
|
-
|
12
|
-
|
13
|
-
response "
|
14
|
-
response "
|
8
|
+
step "door" do
|
9
|
+
say "You're holding the key. In front of you is a locked door with 3 locks. One is painted red, one is painted blue, and one is painted black. Which lock do you want to try the key on?"
|
10
|
+
response "red" => "locked door"
|
11
|
+
response "blue" => "locked door"
|
12
|
+
response "black" => "open door"
|
15
13
|
end
|
16
14
|
|
17
|
-
step
|
18
|
-
say "
|
15
|
+
step "locked door" do
|
16
|
+
say "Hmmm. That didn't work. Perhaps the key would work on a different lock..."
|
17
|
+
response "red" => "locked door"
|
18
|
+
response "blue" => "locked door"
|
19
|
+
response "black" => "open door"
|
20
|
+
end
|
21
|
+
|
22
|
+
step "open door" do
|
23
|
+
say "It worked! The door swings open slowly, and you enter what seems to be a dark hallway. Eventually the hallway comes to a pair of staircases, one of which goes up, and the other of which goes down. You hear footsteps on the floor above you, and you wonder which staircase you should take."
|
24
|
+
response "up" => "second floor"
|
25
|
+
response "down" => "basement"
|
26
|
+
end
|
27
|
+
|
28
|
+
step "second floor" do
|
29
|
+
say "You walk up the stairs and see a strange creature. It comes towards you and..."
|
19
30
|
stop
|
20
31
|
end
|
32
|
+
|
33
|
+
step "basement" do
|
34
|
+
say "There's an open door in front of you, and you make your escape from the haunted castle!"
|
35
|
+
stop
|
36
|
+
end
|
data/lib/tuvi/step.rb
CHANGED
data/lib/tuvi/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tuvi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
12
|
+
date: 2014-01-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -100,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
100
|
version: '0'
|
101
101
|
segments:
|
102
102
|
- 0
|
103
|
-
hash:
|
103
|
+
hash: 1645267499597312688
|
104
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
version: '0'
|
110
110
|
segments:
|
111
111
|
- 0
|
112
|
-
hash:
|
112
|
+
hash: 1645267499597312688
|
113
113
|
requirements: []
|
114
114
|
rubyforge_project:
|
115
115
|
rubygems_version: 1.8.25
|