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 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 1 do
18
- say "Welcome to KrazyMaze. Will you ever get out? BWAAHAAA! You have a choice to make: Go right or left"
19
- response "right" => 2
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 2 do
24
- say "You're in the middle of the maze. Go right or left or straight."
25
- response "right" => 3
26
- response "left" => 4
27
- response "straight" => 3
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 3 do
31
- say "You've encountered a monster! You can either go straight, or punch the monster."
32
- response "straight" => 2
33
- response "punch" => 5
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 4 do
37
- say "Drat. You've reached the end of the maze! I'll get you next time..."
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 5 do
42
- say "The monster was stronger than you! You died."
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 steps, which represent a step in the program where the program provides some instructions, and either prompts the user for input or simply exits.
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 an `response` which is followed first by a valid user response, a hashrocket arrow, and then by the step number that that particular user response should lead to.
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 any custom Ruby code by placing it block passed to the `code` method. Also note that variables should be set as globals. For example:
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 1 do
61
- code {$steps = 1}
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" => 2
64
- response "left" => 3
69
+ response "right" => "middle"
70
+ response "left" => "east end"
65
71
  end
66
72
 
67
- step 2 do
73
+ step "middle" do
68
74
  code do
69
- $steps += 1
70
- puts "You have taken #{$steps} steps."
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" => 3
74
- response "left" => 4
75
- response "straight" => 3
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 1 do
4
- code {$x = "hello"}
5
- say "This is Step 1. Type yes to go to Step 2. Type no to go to Step 3."
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 2 do
11
- code {puts $x}
12
- say "This is Step 2. Type hi to go to Step 3. Type bye to go to step 1."
13
- response "Hi" => 3
14
- response "Bye" => 1
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 3 do
18
- say "You've reached the end!"
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
@@ -5,7 +5,8 @@ class ApplicationRunner
5
5
  end
6
6
 
7
7
  def run
8
- current_step_id = 1
8
+ puts "Welcome! Type 'exit' to quit at any time."
9
+ current_step_id = "start"
9
10
  while true do
10
11
  current_step_id = execute_step(current_step_id)
11
12
  end
data/lib/tuvi/step.rb CHANGED
@@ -28,7 +28,7 @@ class Step
28
28
  end
29
29
 
30
30
  def formatted_responses
31
- "You can type one of the following: [#{@response_paths.keys.join(", ")}]. Enter 'exit' to quit."
31
+ "Choose a command: [#{@response_paths.keys.join(", ")}]"
32
32
  end
33
33
 
34
34
  def code(&block)
data/lib/tuvi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tuvi
2
- VERSION = "0.0.13"
2
+ VERSION = "0.0.14"
3
3
  end
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.13
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-27 00:00:00.000000000 Z
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: 920541473869891771
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: 920541473869891771
112
+ hash: 1645267499597312688
113
113
  requirements: []
114
114
  rubyforge_project:
115
115
  rubygems_version: 1.8.25