mastermind-tyrbo 0.1.0
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.
- checksums.yaml +7 -0
- data/lib/game.rb +38 -0
- metadata +45 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: b967cd21c08151b05407064e2532adcf711a5627
|
|
4
|
+
data.tar.gz: 79c93b63483850a4545934d8a9b18f05250f84c1
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8f2dcd33f59160ac92e59120e98789112944c7857eeedda51c42e6dd676cc752a70dab807dc33b88ecebd61c5c35609c5ef4efc7e64a6290a23513b392b498d0
|
|
7
|
+
data.tar.gz: 1ccbf6e26fe89c3a3e081e837ab7a0aee86fd97647ba48bef10dbb14164aea78ef71b65cdaf20efad9647d4b890b6aa349b7d9662563ce04e5ab3cd5f9e5d0e7
|
data/lib/game.rb
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require './lib/errors'
|
|
2
|
+
require './lib/guess_validator'
|
|
3
|
+
require './lib/guess'
|
|
4
|
+
require './lib/sequence_generator'
|
|
5
|
+
require './lib/sequence_matcher'
|
|
6
|
+
|
|
7
|
+
class Game
|
|
8
|
+
attr_reader :guesses, :sequence
|
|
9
|
+
|
|
10
|
+
def initialize
|
|
11
|
+
@guesses = []
|
|
12
|
+
@started = false
|
|
13
|
+
@sequence = SequenceGenerator.new.random
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def start
|
|
17
|
+
raise GameAlreadyStarted if @started
|
|
18
|
+
@started = true
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def guess(guess)
|
|
22
|
+
raise GameNotStarted unless @started
|
|
23
|
+
if GuessValidator.valid?(guess)
|
|
24
|
+
process_guess(guess)
|
|
25
|
+
else
|
|
26
|
+
'You must enter a valid guess: four characters long, consisting of (R)ed, (G)reen, (B)lue, or (Y)ellow.'
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def process_guess(guess)
|
|
33
|
+
guess = Guess.new(guess)
|
|
34
|
+
match_data = SequenceMatcher.new(guess, @sequence).match?
|
|
35
|
+
@guesses << match_data
|
|
36
|
+
match_data
|
|
37
|
+
end
|
|
38
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: mastermind-tyrbo
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jonmichael Chambers
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-06-19 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Mastermind is a sequence matching game. This library attemps to provided
|
|
14
|
+
an easy way to generate and match sequences.
|
|
15
|
+
email: jon@tyrbo.net
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- lib/game.rb
|
|
21
|
+
homepage: https://github.com/tyrbo/mastermind
|
|
22
|
+
licenses: []
|
|
23
|
+
metadata: {}
|
|
24
|
+
post_install_message:
|
|
25
|
+
rdoc_options: []
|
|
26
|
+
require_paths:
|
|
27
|
+
- lib
|
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
requirements: []
|
|
39
|
+
rubyforge_project:
|
|
40
|
+
rubygems_version: 2.3.0
|
|
41
|
+
signing_key:
|
|
42
|
+
specification_version: 4
|
|
43
|
+
summary: An implementation of the mastermind game.
|
|
44
|
+
test_files: []
|
|
45
|
+
has_rdoc:
|