codebreaker234 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1986c09597fe6612e7c03d8d76a2e8de83842e1b
4
+ data.tar.gz: 22107e316bb77ccf895583588b696a25d298d58b
5
+ SHA512:
6
+ metadata.gz: 85685c9e5f0ebcd91bf87e2a8d7c4f2e0f285833f8c0ae6131f7619096c3b3f2a43dff095950abdbc1f93d2adf4ef468cefac3747158886fb9ba50cb85c15f8b
7
+ data.tar.gz: 175c2e9962703cf79d4a6ece8b2d3c414645c380b81fe0f32e59aaa74f541d458aa299d195e02c506b116cc4ecf868d1da4ed45d176e5fdc06e19ef663d662b1
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in codebreaker234.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 MaxKotsarev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Codebreaker234
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/codebreaker234`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'codebreaker234'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install codebreaker234
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/codebreaker234/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "codebreaker234"
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
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'codebreaker234/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "codebreaker234"
8
+ spec.version = Codebreaker234::VERSION
9
+ spec.authors = ["MaxKotsarev"]
10
+ spec.email = ["m.kotsariev@gmail.com"]
11
+
12
+ spec.summary = %q{Codebreacker - logic game.}
13
+ spec.description = %q{Gem was made as task on Ruby Garage curse.}
14
+ spec.homepage = "https://github.com/MaxKotsarev/codebreaker234"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ #if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ #else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ #end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.9"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec"
33
+ end
@@ -0,0 +1,71 @@
1
+ module Codebreaker234
2
+ class Game
3
+ NUMBER_OF_TURNS = 10
4
+ SECRET_CODE_LENGTH = 4
5
+
6
+ attr_accessor :user_guesses_and_answers, :game_status, :result_saved
7
+ attr_reader :number_of_turns, :hints_avaliable
8
+
9
+ def initialize
10
+ @secret_code = ""
11
+ @number_of_turns = NUMBER_OF_TURNS
12
+ @hint_position = rand(SECRET_CODE_LENGTH)
13
+ @hints_avaliable = 1
14
+ @user_guesses_and_answers = []
15
+ @game_status = "not_completed"
16
+ @result_saved = false
17
+ end
18
+
19
+ def start
20
+ SECRET_CODE_LENGTH.times {@secret_code << (1 + rand(6)).to_s}
21
+ end
22
+
23
+ def mark_user_guess(user_input)
24
+ answer = ""
25
+ tmp_code = ""
26
+ tmp_input = ""
27
+ for i in 0...SECRET_CODE_LENGTH
28
+ if user_input[i] == @secret_code[i]
29
+ tmp_code << "+"
30
+ tmp_input << "+"
31
+ else
32
+ tmp_input << user_input[i]
33
+ tmp_code << @secret_code[i]
34
+ end
35
+ end
36
+ for i in 0...SECRET_CODE_LENGTH
37
+ if tmp_input[i] == tmp_code[i]
38
+ answer << "+"
39
+ elsif tmp_code.include? tmp_input[i]
40
+ answer << "-"
41
+ end
42
+ end
43
+ return answer
44
+ end
45
+
46
+ def hint
47
+ hint = "****"
48
+ hint[@hint_position] = @secret_code[@hint_position]
49
+ @hints_avaliable -= 1
50
+ return hint
51
+ end
52
+
53
+ def decrease_avaliable_turns
54
+ @number_of_turns -= 1
55
+ end
56
+
57
+ def score
58
+ @number_of_turns*10 + @hints_avaliable*30
59
+ end
60
+
61
+ def save_to(file_name)
62
+ File.open(file_name, 'w') {|f| f.write(YAML.dump(self)) }
63
+ end
64
+
65
+ def self.load_from(file_name)
66
+ YAML.load(File.read(file_name))
67
+ end
68
+ end
69
+ end
70
+
71
+
@@ -0,0 +1,17 @@
1
+ module Codebreaker234
2
+ class ResultsCollection
3
+ attr_accessor :results
4
+
5
+ def initialize
6
+ @results = []
7
+ end
8
+
9
+ def save_to(file_name)
10
+ File.open(file_name, 'w') {|f| f.write(YAML.dump(self)) }
11
+ end
12
+
13
+ def self.load_from(file_name)
14
+ YAML.load(File.read(file_name))
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module Codebreaker234
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,8 @@
1
+ require "codebreaker234/version"
2
+ require "codebreaker234/game"
3
+ require "codebreaker234/results_collection"
4
+ require 'yaml'
5
+
6
+ module Codebreaker234
7
+ # Your code goes here...
8
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codebreaker234
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - MaxKotsarev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-06-03 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.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
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: '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
+ description: Gem was made as task on Ruby Garage curse.
56
+ email:
57
+ - m.kotsariev@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - codebreaker234.gemspec
72
+ - lib/codebreaker234.rb
73
+ - lib/codebreaker234/game.rb
74
+ - lib/codebreaker234/results_collection.rb
75
+ - lib/codebreaker234/version.rb
76
+ homepage: https://github.com/MaxKotsarev/codebreaker234
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.5
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Codebreacker - logic game.
100
+ test_files: []