codebracker 0.1.2 → 0.1.21

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc631764fccbb45a57b3846cbca2efb2ee2783a46c884dd70818276886e5a58d
4
- data.tar.gz: e30cbe348f5b4f36f1dc97a890b33e99ea16ecea805c474898259d86753d83d3
3
+ metadata.gz: ad9c96cd567666e3bd802d28b2c43d187dbabd4cbc6c0f3e80006424485ebfcb
4
+ data.tar.gz: 2b15dfec8d3dcc2b003cfa414c83687dc71061baf32a1720e17c615cc552e488
5
5
  SHA512:
6
- metadata.gz: c6cde3b296f4859827642fa54ed142757943dc391d415b23cf8604abe48e5cabcc9fb5824c648adcc75fa4cae574c044663039ee2441789a3a7b9c9246f7c666
7
- data.tar.gz: f1dfef04245c27775b426d388ce00067dfd79d068eb16c505ce679e9de7f93bb556ecba083fe50c8e28daf5bf8db80619c66dc58d782dc098265fdf8d69ab315
6
+ metadata.gz: 255cddf83ee3a29d2ce0fda7ea69ef39d48aa48d968ffdbcec545aa7e5e24042eb8f443a5b987db0ce83f7766fce14620daddc2ab31bf807e5d9fee757853ec3
7
+ data.tar.gz: f0a4d1bbdf15db6b546046237a58d285682466ee40ca6fc4db2628bb98d31f2f46aaee8f26963a8f1be2c24e0b0e2810503db84f1dece4fd0459029d99d8b697
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.4.2
4
+ - 2.5.1
5
5
  before_install: gem install bundler -v 1.16.2
data/README2.md ADDED
File without changes
Binary file
data/codebracker.gemspec CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  lib = File.expand_path("../lib", __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require "codebracker/version"
@@ -35,4 +34,4 @@ Gem::Specification.new do |spec|
35
34
  spec.add_development_dependency "bundler", "~> 1.16"
36
35
  spec.add_development_dependency "rake", "~> 10.0"
37
36
  spec.add_development_dependency "rspec", "~> 3.0"
38
- end
37
+ end
data/lib/codebracker.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require "codebracker/version"
2
+ require 'codebraker/interface'
3
+ require 'codebraker/game'
2
4
 
3
5
  module Codebracker
4
6
  # Your code goes here...
@@ -0,0 +1,39 @@
1
+ module Codebraker
2
+ GREETING = "\nWelcome to the Codebreaker!".freeze
3
+
4
+ START_MENU = "
5
+ 1 - Set User Name
6
+ 2 - Play game
7
+ 3 - Show score table
8
+ 4 - Show rools
9
+ 5 - Exit".freeze
10
+
11
+ GAME_MENU = "1 - Set User Name \n
12
+ 2 - Play\n
13
+ 3 - Back to the start menu\n".freeze
14
+
15
+ GOODBUY_MESSAGE = "\nGoodbuy! Thanks for good game!".freeze
16
+
17
+ QUESTION_FOR_HINT = "\nDo you want to use hint? (y/n)".freeze
18
+
19
+ QUESTION_FOR_NEW_GAME = "\nDo you want to play again? (y/n)".freeze
20
+
21
+ ABSENT_HITNS_MESSAGE = "\n Sorry, you have no hints".freeze
22
+
23
+ LOOSE_MESSAGE = "\nDon't get upset! Try one more time!".freeze
24
+
25
+ CONGRATULATIONS = "\n You win! Good job! Try to improove your result :)"
26
+
27
+ ROOLS = "
28
+ \nIntroducing Codebreaker\n
29
+ Codebreaker is a logic game in which a code-breaker tries to break a secret code
30
+ created by a code-maker. The code-maker, which will be played by the application
31
+ we’re going to write, creates a secret code of four numbers between 1 and 6.\n
32
+ The code-breaker then gets some number of chances to break the code. In each turn,
33
+ the code-breaker makes a guess of four numbers. The code-maker then marks the guess
34
+ with up to four + and - signs.\n
35
+ A + indicates an exact match: one of the numbers in the guess is the same as one
36
+ of the numbers in the secret code and in the same position.\n
37
+ A - indicates a number match: one of the numbers in the guess is the same as one
38
+ of the numbers in the secret code but in a different position.\n".freeze
39
+ end
@@ -0,0 +1,87 @@
1
+ require_relative 'interface'
2
+ require_relative 'constants'
3
+ # require 'pry'
4
+
5
+ module Codebraker
6
+ class Game
7
+ attr_reader :attempts, :hints, :result_of_comparing
8
+
9
+ def initialize
10
+ @secret_code = ''
11
+ @user_suggested_code = ''
12
+ @attempts = 5
13
+ @hints = 2
14
+ @score = 0
15
+ generate_code
16
+ end
17
+
18
+ def start(user_suggested_code)
19
+ @user_suggested_code = user_suggested_code
20
+ decrease_attempts
21
+ validate_input(user_suggested_code)
22
+ compare_codes
23
+ show_result_of_comparing
24
+ end
25
+
26
+ def win?
27
+ @result_of_comparing == '++++'
28
+ end
29
+
30
+ def loose?
31
+ @attempts.zero?
32
+ end
33
+
34
+ def generate_code
35
+ @secret_code = (1..4).map { rand(1..6) }.join
36
+ end
37
+
38
+ def validate_input(input)
39
+ raise ArgumentError, 'Type exactly 4 integer' unless input.length == 4
40
+ raise ArgumentError, 'Type only integers from 1 to 6' if input =~ /[^1-6]/
41
+ end
42
+
43
+ def compare_codes
44
+ @secret_code_for_comparing = @secret_code.dup
45
+ 4.times { |i|
46
+ if @secret_code_for_comparing[i] == @user_suggested_code[i]
47
+ @secret_code_for_comparing[i] = '$'
48
+ @user_suggested_code[i] = '+'
49
+ end
50
+ }
51
+ 4.times { |i|
52
+ if @secret_code_for_comparing.include?(@user_suggested_code[i])
53
+ @secret_code_for_comparing.sub!(@user_suggested_code[i], '$')
54
+ @user_suggested_code[i] = '-'
55
+ end
56
+ }
57
+ 4.times { |i|
58
+ if /[\d]/ =~ @user_suggested_code[i]
59
+ @user_suggested_code[i] = ' '
60
+ end
61
+ }
62
+ @result_of_comparing = @user_suggested_code.dup
63
+ end
64
+
65
+ def count_score
66
+ @score = @attempts * 10 + @hints * 15
67
+ end
68
+
69
+ def decrease_attempts
70
+ @attempts -= 1
71
+ end
72
+
73
+ def use_hint
74
+ return ABSENT_HITNS_MESSAGE if @hints.zero?
75
+ @hints -= 1
76
+ show_hint
77
+ end
78
+
79
+ def show_hint
80
+ puts @secret_code[rand(0..3)]
81
+ end
82
+
83
+ def show_result_of_comparing
84
+ puts @user_suggested_code
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,56 @@
1
+ ---
2
+ :Username: New User
3
+ :Score: 70
4
+ :Remaining_attempts: 4
5
+ :Remaining_hints: 2
6
+ :Secret_cod_of_game: '4564'
7
+ :Date: 24/06/2018 22:/48
8
+ ---
9
+ :Username: New User
10
+ :Score: 60
11
+ :Remaining_attempts: 3
12
+ :Remaining_hints: 2
13
+ :Secret_cod_of_game: '4426'
14
+ :Date: 24/06/2018 23:/03
15
+ ---
16
+ :Username: New User
17
+ :Score: 70
18
+ :Remaining_attempts: 4
19
+ :Remaining_hints: 2
20
+ :Secret_cod_of_game: '3411'
21
+ :Date: 24/06/2018 23:/15
22
+ ---
23
+ :Username: Eagle
24
+ :Score: 50
25
+ :Remaining_attempts: 2
26
+ :Remaining_hints: 2
27
+ :Secret_cod_of_game: '4153'
28
+ :Date: 24/06/2018 23:/23
29
+ ---
30
+ :Username: Eagle
31
+ :Score: 40
32
+ :Remaining_attempts: 1
33
+ :Remaining_hints: 2
34
+ :Secret_cod_of_game: '2322'
35
+ :Date: 24/06/2018 23:/24
36
+ ---
37
+ :Username: Jack
38
+ :Score: 30
39
+ :Remaining_attempts: 0
40
+ :Remaining_hints: 2
41
+ :Secret_cod_of_game: '3364'
42
+ :Date: 24/06/2018 23:/37
43
+ ---
44
+ :Username: Jack
45
+ :Score: 30
46
+ :Remaining_attempts: 0
47
+ :Remaining_hints: 2
48
+ :Secret_cod_of_game: '3446'
49
+ :Date: 24/06/2018 23:/38
50
+ ---
51
+ :Username: Jack
52
+ :Score: 40
53
+ :Remaining_attempts: 1
54
+ :Remaining_hints: 2
55
+ :Secret_cod_of_game: '4163'
56
+ :Date: 24/06/2018 23:/40
@@ -1,3 +1,3 @@
1
1
  module Codebracker
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.21"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codebracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir2706
@@ -66,12 +66,16 @@ files:
66
66
  - Gemfile
67
67
  - LICENSE.txt
68
68
  - README.md
69
+ - README2.md
69
70
  - Rakefile
70
71
  - bin/console
71
72
  - bin/setup
72
73
  - codebracker-0.1.0.gem
73
74
  - codebracker.gemspec
74
75
  - lib/codebracker.rb
76
+ - lib/codebracker/constants.rb
77
+ - lib/codebracker/game.rb
78
+ - lib/codebracker/scores_table.yaml
75
79
  - lib/codebracker/version.rb
76
80
  homepage: https://github.com/Vladimir2706/gem_for_codebreaker_RACK/tree/feature/change_gem
77
81
  licenses: