tuvi 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
- /pkg
1
+ /pkg
2
+ Gemfile.lock
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tuvi (0.0.3)
4
+ tuvi (0.0.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Tuvi
2
2
 
3
- Tuvi is a computer language for kids to create text-based games and applications. It is a Ruby DSL which supplies a declarative format which dictates the flow of the program as a series of steps.
3
+ Tuvi is a computer language for kids to create text-based games and applications. It is a Ruby DSL which provides a simple way to declare the flow of the program as a series of steps. Although the below example demonstrates the use of Tuvi in creating a Choose-Your-Own-Adventure type game, it can be used for any text game or application. Tuvi was written in order to introduce programming to my son, Tuvi!
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,7 +10,57 @@ Install Tuvi simply with:
10
10
 
11
11
  ## Usage
12
12
 
13
- Coming Soon!
13
+ Here is a basic example program followed by an explanation:
14
+
15
+ require 'tuvi'
16
+
17
+ step 1 do
18
+ message "Welcome to KrazyMaze. Will you ever get out? BWAAHAAA! You have a choice to make: Go right or left"
19
+ answer "right", 2
20
+ answer "left", 3
21
+ end
22
+
23
+ step 2 do
24
+ message "You're in the middle of the maze. Go right or left or straight."
25
+ answer "right", 3
26
+ answer "left", 4
27
+ answer "straight", 3
28
+ end
29
+
30
+ step 3 do
31
+ message "You've encountered a monster! You can either go straight, or punch the monster."
32
+ answer "straight", 2
33
+ answer "punch", 5
34
+ end
35
+
36
+ step 4 do
37
+ message "Drat. You've reached the end of the maze! I'll get you next time..."
38
+ stop
39
+ end
40
+
41
+ step 5 do
42
+ message "The monster was stronger than you! You died."
43
+ stop
44
+ end
45
+
46
+ run
47
+
48
+
49
+ First, create a ruby file and on the first line require the Tuvi library with `require 'tuvi'`
50
+
51
+ Then, create a class with any name you desire. The first thing to do inside this class is: `extend Tuvi`.
52
+
53
+ 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
+
55
+ Every step needs a `message`, which sets the computer's instructions for that step.
56
+
57
+ Every step can establish one or more lines declaring an `answer` which is followed first by a valid user response, a comma, and then by the step number that that particular user response should lead to.
58
+
59
+ Some steps, instead of having answers, can simply end the program using the `stop` keyword.
60
+
61
+ Finally, after all the steps have been declared (but still within the class), the `run` keyword actually runs the steps.
62
+
63
+ You can run this file like any other Ruby file, using `ruby filename.rb`.
14
64
 
15
65
  ## Contributing
16
66
 
data/example_program.rb CHANGED
@@ -1,26 +1,20 @@
1
1
  require_relative 'lib/tuvi.rb'
2
2
 
3
- class ExampleProgram
3
+ step 1 do
4
+ message "This is Step 1. Type yes to go to Step 2. Type no to go to Step 3."
5
+ answer "Yes", 2
6
+ answer "No", 3
7
+ end
4
8
 
5
- extend Tuvi
9
+ step 2 do
10
+ message "This is Step 2. Type hi to go to Step 3. Type bye to go to step 1."
11
+ answer "Hi", 3
12
+ answer "Bye", 1
13
+ end
6
14
 
7
- step 1 do
8
- message "This is Step 1. Type yes to go to Step 2. Type no to go to Step 3."
9
- answer "Yes", 2
10
- answer "No", 3
11
- end
15
+ step 3 do
16
+ message "You've reached the end!"
17
+ stop
18
+ end
12
19
 
13
- step 2 do
14
- message "This is Step 2. Type hi to go to Step 3. Type bye to go to step 1."
15
- answer "Hi", 3
16
- answer "Bye", 1
17
- end
18
-
19
- step 3 do
20
- message "You've reached the end!"
21
- stop
22
- end
23
-
24
- run
25
-
26
- end
20
+ run
data/lib/tuvi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tuvi
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/tuvi.rb CHANGED
@@ -11,16 +11,28 @@ module Tuvi
11
11
  def run
12
12
  current_step = 1
13
13
  while true do
14
- puts @steps[current_step].get_message
15
- exit if @steps[current_step].exit_program
16
- puts @steps[current_step].formatted_answers
17
- input = gets.downcase.chomp
18
- if @steps[current_step].answer_paths[input]
19
- current_step = @steps[current_step].answer_paths[input]
20
- else
21
- puts "Sorry, I don't understand that answer. Please try again:"
22
- end
14
+ current_step = execute_step(current_step)
23
15
  end
24
16
  end
25
17
 
18
+ def execute_step(current_step)
19
+ puts @steps[current_step].get_message
20
+ exit if @steps[current_step].exit_program
21
+ puts @steps[current_step].formatted_answers
22
+ input = gets.downcase.chomp
23
+ determine_next_step(current_step, input)
24
+ end
25
+
26
+ def determine_next_step(current_step, input)
27
+ if @steps[current_step].answer_paths[input]
28
+ next_step = @steps[current_step].answer_paths[input]
29
+ else
30
+ puts "Sorry, I don't understand that answer. Please try again:"
31
+ next_step = current_step
32
+ end
33
+ next_step
34
+ end
35
+
26
36
  end
37
+
38
+ extend Tuvi
data/spec/tuvi_spec.rb CHANGED
@@ -40,7 +40,17 @@ describe Tuvi do
40
40
  end
41
41
  end
42
42
 
43
- describe "run" do
43
+ describe "determine_next_step" do
44
+
45
+ it "should determine the next step based on answer paths" do
46
+ @program.step(1){answer "yes", 2}
47
+ @program.determine_next_step(1, "yes").should == 2
48
+ end
49
+
50
+ it "should set the next step to be the current step if input is invalid" do
51
+ @program.step(1){answer "yes", 2}
52
+ @program.determine_next_step(1, "blah").should == 1
53
+ end
44
54
 
45
55
  end
46
56
 
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.3
4
+ version: 0.0.4
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: 2013-08-19 00:00:00.000000000 Z
12
+ date: 2013-08-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -97,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
97
  version: '0'
98
98
  segments:
99
99
  - 0
100
- hash: 4344284518542191746
100
+ hash: -202346767343120134
101
101
  required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  none: false
103
103
  requirements:
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  segments:
108
108
  - 0
109
- hash: 4344284518542191746
109
+ hash: -202346767343120134
110
110
  requirements: []
111
111
  rubyforge_project:
112
112
  rubygems_version: 1.8.25