escape-room 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9689c8757fb50ad38757025143e777f8363eaa237f318ce48ab61d5eccc7cfe0
4
+ data.tar.gz: c7ab9a9f6239e0edd1d1163336229cf89f8219ff46ddc246683f675334a4cb6a
5
+ SHA512:
6
+ metadata.gz: c1fa93a2e0b3e2970266c17a7b68cc4b63f3b828164160e45eeb829fe1a004ec65d66dc8e35f68f95d5c0d9b92f57e5eb4027aa310cb11481138b483eafa4e37
7
+ data.tar.gz: 12e49a1e3b118b31857aa99447cbf5dbf835e0a536df48b89170c868b13d40c73636af98df94f1aed8cffe5d7f63a40be5596f47f265c6e7a29cc37e3b280150
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ escape-room (0.0.2)
5
+ thor
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ rake (12.3.2)
12
+ rspec (3.8.0)
13
+ rspec-core (~> 3.8.0)
14
+ rspec-expectations (~> 3.8.0)
15
+ rspec-mocks (~> 3.8.0)
16
+ rspec-core (3.8.0)
17
+ rspec-support (~> 3.8.0)
18
+ rspec-expectations (3.8.2)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.8.0)
21
+ rspec-mocks (3.8.0)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-support (3.8.0)
25
+ thor (0.20.3)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler
32
+ escape-room!
33
+ rake
34
+ rspec
35
+
36
+ BUNDLED WITH
37
+ 1.16.6
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2019 Jamie Wright
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,96 @@
1
+ escape
2
+ ======
3
+
4
+ The escape room CLI
5
+
6
+ ## DESCRIPTION
7
+
8
+ Escape is a command line interface for asking questions to get out of an escape room. Complete with tests.
9
+
10
+ The CLI loops through a list of questions (that you can define) and for each correct answer, you will receive a piece of the code. The
11
+ actors can use this code for a combination lock or whatever clue you want to provide them.
12
+
13
+ If the actor gets an answer wrong, the CLI will give them an answer but it is not part of the code. They can go through all of the questions and
14
+ one or more may be wrong but they will not know the wrong answer.
15
+
16
+ ### Usage
17
+
18
+ You can modify the [configuration.yml](./configuration.yml) file with your own questions, answers, and the code.
19
+
20
+ To start, the actors are greated with a welcome message and they hit return to start:
21
+
22
+ ```
23
+ > WELCOME TO THE ESCAPE ROOM!
24
+ >
25
+ > You were chosen to take part in this clue. Be careful, any answer will give you a part
26
+ > of the clue but if the answer is wrong, the clue is wrong. Any wrong part and you will
27
+ > have to start all over.
28
+ >
29
+ > Hit RETURN to start!
30
+ >
31
+ ```
32
+
33
+ It then loops through the questions:
34
+
35
+ ```
36
+ > WHAT IS THE VALUE OF PI? (Answer the question and hit RETURN)
37
+ >
38
+ ```
39
+
40
+ The CLI will then provide them with an answer, right or wrong:
41
+
42
+ ```
43
+ > YOUR NEXT CLUE IS: '4'
44
+ >
45
+ ```
46
+
47
+ Once the CLI loops through all of the questions, you will get a message with a chance to start over:
48
+
49
+ ```
50
+ > YOU HAVE COMPLETED THE CHALLENGE.
51
+ >
52
+ > Hit RETURN to restart.
53
+ ```
54
+
55
+ ### Installation
56
+
57
+ 1. Pull down this repository
58
+
59
+ ```
60
+ git clone https://github.com/jwright/escape
61
+ ```
62
+
63
+ 2. `cd` into this directory
64
+
65
+ ```
66
+ cd escape
67
+ ```
68
+
69
+ 3. Configure your welcome message, questions, answers, and code at [./configuration.yml](./configuration.yml)
70
+
71
+ 4. Run the application at the command line
72
+
73
+ ```
74
+ escape
75
+ ```
76
+
77
+ ## RELEASING A NEW GEM
78
+
79
+ 1. Bump the VERSION in `lib/escape/version.rb`
80
+ 1. Commit changes and push to GitHub
81
+ 1. run `bundle exec rake release`
82
+
83
+ ## CONTRIBUTING
84
+
85
+ 1. Clone the repository `git clone git@github.com:jwright/escape`
86
+ 1. Create a feature branch `git checkout -b my-awesome-feature`
87
+ 1. Codez!
88
+ 1. Commit your changes (small commits please)
89
+ 1. Push your new branch `git push origin my-awesome-feature`
90
+ 1. Create a pull request `hub pull-request -b jwright:master -h jwright:my-awesome-feature`
91
+
92
+ ## LICENSE
93
+
94
+ Copyright (c) 2019, Jamie Wright.
95
+
96
+ This project is licensed under the [MIT License](LICENSE.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path(File.dirname(__FILE__) + "/../lib")
4
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
+
6
+ require "escape"
7
+
8
+ Escape::CLI.start
@@ -0,0 +1,22 @@
1
+ welcome_message: |
2
+ Welcome to the Escape Room!
3
+ +------------------------------------------------+
4
+
5
+ We are here to solve a puzzle together.
6
+ You will asked a series of questions.
7
+ Each question will provide you an answer.
8
+ The trick is that some of those questions may be wrong if your answer is wrong.
9
+ You will not know until you try the code that is provided to you after each answer.
10
+ Good luck.
11
+
12
+ Hit RETURN to start.
13
+
14
+ questions:
15
+ - text: What is the meaning of life?
16
+ answer: 42
17
+ - text: What is the value of PI?
18
+ answer: 3
19
+
20
+ clues:
21
+ - 4
22
+ - H
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "escape/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "escape-room"
8
+ spec.version = Escape::VERSION
9
+ spec.authors = ["Jamie Wright"]
10
+ spec.email = ["jamie@brilliantfantastic.com"]
11
+
12
+ spec.summary = %q{A command line interface for asking questions to get out of an escape room}
13
+ spec.description = %q{Create your own quiz to reveal clues in an escape room.}
14
+ spec.homepage = "https://github.com/jwright/escape"
15
+ spec.license = "MIT"
16
+
17
+ spec.required_ruby_version = "~> 2.5.0"
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.require_paths = ["lib"]
20
+ spec.executable = "escape"
21
+
22
+ spec.add_dependency "thor"
23
+
24
+ spec.add_development_dependency "bundler"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ end
@@ -0,0 +1,6 @@
1
+ require_relative "escape/cli"
2
+ require_relative "escape/clue"
3
+ require_relative "escape/commands"
4
+ require_relative "escape/configuration"
5
+ require_relative "escape/question"
6
+ require_relative "escape/question_list"
@@ -0,0 +1,40 @@
1
+ require "thor"
2
+
3
+ module Escape
4
+ class CLI < Thor
5
+ default_task :start
6
+
7
+ desc "start", "Starts a new game"
8
+ def start
9
+ raise RuntimeError, "Number of questions does not match the number of clues" unless valid_configuration?
10
+
11
+ Escape::Commands::Welcome.new(self).show(configuration.welcome_message)
12
+ Escape::Commands::Questions.new(self).start(configuration.questions, configuration.clues)
13
+ Escape::Commands::Restart.new(self).restart_or_quit
14
+ end
15
+
16
+ desc "restart", "Restarts a new game"
17
+ def restart
18
+ Escape::Commands::Questions.new(self).start(configuration.questions, configuration.clues)
19
+ Escape::Commands::Restart.new(self).restart_or_quit
20
+ end
21
+
22
+ no_commands do
23
+ def execute(command)
24
+ self.class.new.invoke command
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ no_commands do
31
+ def configuration
32
+ @configuration ||= Escape::Configuration.load(File.join(File.dirname(__FILE__), "..", "..", "configuration.yml"))
33
+ end
34
+
35
+ def valid_configuration?
36
+ configuration.questions.count == configuration.clues.count
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,20 @@
1
+ module Escape
2
+ class Clue
3
+ attr_reader :clues
4
+
5
+ def initialize(clues)
6
+ @clues = clues
7
+ end
8
+
9
+ def correct(index)
10
+ clues[index]
11
+ end
12
+
13
+ def incorrect(index)
14
+ correct = self.correct(index)
15
+
16
+ return ([*0..99] - [correct]).sample if correct.is_a?(Integer)
17
+ return ([*"A".."Z"] - [correct]).sample if correct.is_a?(String)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+ require_relative "commands/base"
2
+ require_relative "commands/questions"
3
+ require_relative "commands/restart"
4
+ require_relative "commands/welcome"
@@ -0,0 +1,11 @@
1
+ module Escape
2
+ module Commands
3
+ class Base
4
+ attr_reader :runner
5
+
6
+ def initialize(runner)
7
+ @runner = runner
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module Escape
2
+ module Commands
3
+ class Questions < Base
4
+ def start(questions, clues)
5
+ questions.each_with_index do |question, index|
6
+ answer = runner.ask(question.text)
7
+ runner.say(question.correct?(answer) ? Clue.new(clues).correct(index) : Clue.new(clues).incorrect(index))
8
+ runner.say
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Escape
2
+ module Commands
3
+ class Restart < Base
4
+ def restart_or_quit
5
+ response = runner.ask "Hit RETURN to restart or Q to quit"
6
+ unless (response.to_s.strip.upcase == "Q")
7
+ runner.say
8
+ runner.execute :restart
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ module Escape
2
+ module Commands
3
+ class Welcome < Base
4
+ def show(message)
5
+ runner.say message
6
+ runner.ask "\n"
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,31 @@
1
+ require "yaml"
2
+
3
+ module Escape
4
+ class Configuration
5
+ def clues
6
+ config["clues"]
7
+ end
8
+
9
+ def questions
10
+ QuestionList.load(config["questions"])
11
+ end
12
+
13
+ def welcome_message
14
+ config["welcome_message"]
15
+ end
16
+
17
+ class << self
18
+ def load(path)
19
+ new(YAML.load_file(path))
20
+ end
21
+ end
22
+
23
+ protected
24
+
25
+ attr_reader :config
26
+
27
+ def initialize(config)
28
+ @config = config
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,20 @@
1
+ module Escape
2
+ class Question
3
+ attr_reader :answer, :text
4
+
5
+ def initialize(text, answer: nil)
6
+ @text = text
7
+ @answer = answer
8
+ end
9
+
10
+ def correct?(answer)
11
+ self.answer.to_s == answer
12
+ end
13
+
14
+ class << self
15
+ def load(question)
16
+ new(question["text"], answer: question["answer"])
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ module Escape
2
+ class QuestionList
3
+ include Enumerable
4
+
5
+ def initialize(*questions)
6
+ @questions = questions || []
7
+ end
8
+
9
+ def each(&block)
10
+ questions.each(&block)
11
+ end
12
+
13
+ class << self
14
+ def load(list)
15
+ new(*list.map { |item| Question.load(item) })
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :questions
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Escape
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: escape-room
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Jamie Wright
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-01-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Create your own quiz to reveal clues in an escape room.
70
+ email:
71
+ - jamie@brilliantfantastic.com
72
+ executables:
73
+ - escape
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".rspec"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE.md
81
+ - README.md
82
+ - Rakefile
83
+ - bin/escape
84
+ - configuration.yml
85
+ - escape.gemspec
86
+ - lib/escape.rb
87
+ - lib/escape/cli.rb
88
+ - lib/escape/clue.rb
89
+ - lib/escape/commands.rb
90
+ - lib/escape/commands/base.rb
91
+ - lib/escape/commands/questions.rb
92
+ - lib/escape/commands/restart.rb
93
+ - lib/escape/commands/welcome.rb
94
+ - lib/escape/configuration.rb
95
+ - lib/escape/question.rb
96
+ - lib/escape/question_list.rb
97
+ - lib/escape/version.rb
98
+ homepage: https://github.com/jwright/escape
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 2.5.0
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.7.3
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: A command line interface for asking questions to get out of an escape room
122
+ test_files: []