edlvj_codebreaker 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/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +23 -0
- data/Rakefile +11 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/codebreaker.gemspec +35 -0
- data/lib/codebreaker/version.rb +3 -0
- data/lib/console.rb +42 -0
- data/lib/game.rb +59 -0
- data/stat.yml +8 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b474f8e6aac4c1cb934d18412475eb81341b4a56
|
4
|
+
data.tar.gz: ecf7c180467217587a3ebdcf0eaa8624cf0d5971
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 903769902f485844e15927ddc69d596e733af4a96ff6e12140c2ca1ff6ac2f4a6eb0722b8341de14e1ddccf1ccac191fcea792d516633b883d016b99a4988cdf
|
7
|
+
data.tar.gz: 7fa31f4a1ee112ecb0ee29f75b800845774e80e9541e979439944dbabdadab5e88e2b3c139496319ad8af587e9244f082aad92e2f111c0d311fe94be41ff2a8a
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
_____ _ ______ _
|
2
|
+
/ __ \ | | | ___ \ | |
|
3
|
+
| / \/ ___ __| | ___| |_/ /_ __ __ _| | _____ _ __
|
4
|
+
| | / _ \ / _` |/ _ \ ___ \ '__/ _` | |/ / _ \ '__|
|
5
|
+
| \__/\ (_) | (_| | __/ |_/ / | | (_| | < __/ |
|
6
|
+
\____/\___/ \__,_|\___\____/|_| \__,_|_|\_\___|_|
|
7
|
+
|
8
|
+
|
9
|
+
A great way to get started gathering user stories is to do a high-level brain dump of the sorts of things we might like to do. Here are some titles to get started:
|
10
|
+
|
11
|
+
Start game - When a new game was started, the game generates secret code. The code should have 4 items.
|
12
|
+
|
13
|
+
Code-breaker submits guess - The code-breaker propose a guess, and the system replies by marking the guess according to the marking algorithm.
|
14
|
+
|
15
|
+
Code-breaker wins game - The code-breaker propose a guess that matches the secret code exactly. The system responds by marking the guess with four + signs.
|
16
|
+
|
17
|
+
Code-breaker loses game - After some number of turns, the game tells the code-breaker that the game is over (need to decide how many turns and whether to reveal the code).
|
18
|
+
|
19
|
+
Code-breaker plays again - After the game is won or lost, the system prompts the code-breaker to play again. If the code-breaker indicates yes, a new game begins. If the code-breaker indicates no, the system shuts down.
|
20
|
+
|
21
|
+
Code-breaker requests hint - At any time during a game, the code-breaker can request a hint, at which point the system reveals one of the numbers in the secret code.
|
22
|
+
|
23
|
+
Code-breaker saves score - After the game is won or lost, the code-breaker can opt to save information about the game: who (initials?), how many turns, and so on.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "./lib/console.rb"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
Codebreaker::Console.new.play
|
14
|
+
|
data/bin/setup
ADDED
data/codebreaker.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'codebreaker/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "edlvj_codebreaker"
|
8
|
+
spec.version = Codebreaker::VERSION
|
9
|
+
spec.authors = ["Ed Goryach"]
|
10
|
+
spec.email = ["gorachedik96@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{"Codebreaker"}
|
13
|
+
spec.description = %q{"Codebreaker"}
|
14
|
+
spec.homepage = "https://github.com/edlvj/ruby_codebreaker"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
35
|
+
end
|
data/lib/console.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require "./lib/game.rb"
|
2
|
+
|
3
|
+
module Codebreaker
|
4
|
+
class Console
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@game = Game.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def play
|
11
|
+
puts "You have #{Game::ATTEMPS} attemps and #{Game::HINT} hint.
|
12
|
+
Enter 'hint' for get hint. And 'exit' for exit from a game."
|
13
|
+
|
14
|
+
until @game.loose?
|
15
|
+
case code = gets.chomp
|
16
|
+
when 'hint'
|
17
|
+
puts "The hint is #{ @game.get_hint }"
|
18
|
+
when 'exit'
|
19
|
+
exit
|
20
|
+
when /^[1-6]{4}$/
|
21
|
+
puts @game.match_guess(code)
|
22
|
+
end
|
23
|
+
break if @game.win?
|
24
|
+
end
|
25
|
+
|
26
|
+
save
|
27
|
+
@game = Game.new if try_again?
|
28
|
+
play
|
29
|
+
end
|
30
|
+
|
31
|
+
def try_again?
|
32
|
+
puts 'Do you want try again?(y/n)'
|
33
|
+
gets.chomp == 'y' ? true : exit
|
34
|
+
end
|
35
|
+
|
36
|
+
def save
|
37
|
+
puts 'Enter your name:'
|
38
|
+
user_name = gets.chomp
|
39
|
+
@game.save_stat( user_name )
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/game.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Codebreaker
|
4
|
+
class Game
|
5
|
+
|
6
|
+
HINT = 1
|
7
|
+
ATTEMPS = 10
|
8
|
+
|
9
|
+
PROPER = '+'
|
10
|
+
WRONG_POSITION = '-'
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@secret_code = Array.new(4) { rand(1..6) }.join
|
14
|
+
@hint = HINT
|
15
|
+
@attempts = ATTEMPS
|
16
|
+
@win_status = false
|
17
|
+
end
|
18
|
+
|
19
|
+
def match_guess(code)
|
20
|
+
return "Your code is not valid" unless code.match(/(^([1-6]{4})$)/)
|
21
|
+
|
22
|
+
@attempts -= 1
|
23
|
+
secret = @secret_code.chars.map(&:to_i)
|
24
|
+
|
25
|
+
res = []
|
26
|
+
code.chars.map(&:to_i).each_with_index do |number, index|
|
27
|
+
if number == secret[index]
|
28
|
+
secret[index] = nil
|
29
|
+
res << PROPER
|
30
|
+
elsif secret.include? number
|
31
|
+
secret[secret.find_index(number)] = nil
|
32
|
+
res << WRONG_POSITION
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
@win_status = true if res.join == '++++'
|
37
|
+
res.join
|
38
|
+
end
|
39
|
+
|
40
|
+
def loose?
|
41
|
+
@attempts == 0
|
42
|
+
end
|
43
|
+
|
44
|
+
def win?
|
45
|
+
@win_status
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_hint
|
49
|
+
@hint -= 1
|
50
|
+
@hint >= 0 ? @secret_code[rand(4)] : "Not Available"
|
51
|
+
end
|
52
|
+
|
53
|
+
def save_stat( username )
|
54
|
+
File.open('./stat.yml','a+') do |f|
|
55
|
+
f.write([user: username, attempts: @attempts, date: Time.now].to_yaml)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/stat.yml
ADDED
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: edlvj_codebreaker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ed Goryach
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: '"Codebreaker"'
|
56
|
+
email:
|
57
|
+
- gorachedik96@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- bin/console
|
68
|
+
- bin/setup
|
69
|
+
- codebreaker.gemspec
|
70
|
+
- lib/codebreaker/version.rb
|
71
|
+
- lib/console.rb
|
72
|
+
- lib/game.rb
|
73
|
+
- stat.yml
|
74
|
+
homepage: https://github.com/edlvj/ruby_codebreaker
|
75
|
+
licenses: []
|
76
|
+
metadata:
|
77
|
+
allowed_push_host: https://rubygems.org
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.5.1
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: '"Codebreaker"'
|
98
|
+
test_files: []
|