mastermind_sname 1.0 → 2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67589eac9cd726e2ba4f78c089f239bf7dc55cb2
4
- data.tar.gz: 7858ff6c00b0fac69d94fe26237cbd5d3e7d9f1b
3
+ metadata.gz: 3b5cbfe80156234fb5b143fc49bc6011b533a056
4
+ data.tar.gz: b1fe6b5d36c85eaac5777d4b32ee3c5004b81e67
5
5
  SHA512:
6
- metadata.gz: a593657e9430e598931f869e48ba2def9a3bc22ac349d1682d935d7a528bdb69d196f96f1865a8131b886c96511979a9429417db53a964cb83d335ff79776aa7
7
- data.tar.gz: f7d9ea3f0f6a9915bb82ea70640cb64bcdc259afc943c357af7c74b49cb36e4d10bfa54cbb590e960783fbb0cca0264566d4f88acc174c90c42cda5c19549532
6
+ metadata.gz: fae0790effd1f82fa8b85f2ca93861098dccee1006ce9213dcd38ad57f6537a9ea7fae0eb1f419c8e5286ff745fff44e8ddf4ba560c9e61fe6390a35007ae631
7
+ data.tar.gz: 5c6bcb6c05ecec2a02f54a85f078077e9424d195a88d5b9d88e0b21ebda190512497b1819bbb26930fc72f08b650226ea51c6fcdccbe4c1ca8e67effa87767a5
@@ -0,0 +1,27 @@
1
+ engines:
2
+ duplication:
3
+ enabled: true
4
+ config:
5
+ languages:
6
+ - ruby
7
+ - javascript
8
+ - python
9
+ - php
10
+ fixme:
11
+ enabled: true
12
+ rubocop:
13
+ enabled: true
14
+ checks:
15
+ Rubocop/Rails/Output:
16
+ enabled: false
17
+ ratings:
18
+ paths:
19
+ - "**.inc"
20
+ - "**.js"
21
+ - "**.jsx"
22
+ - "**.module"
23
+ - "**.php"
24
+ - "**.py"
25
+ - "**.rb"
26
+ exclude_paths:
27
+ - spec/**/*
@@ -0,0 +1,233 @@
1
+ AllCops:
2
+ Exclude:
3
+ - "vendor/**/*"
4
+ - "db/schema.rb"
5
+ UseCache: false
6
+ Style/CollectionMethods:
7
+ Description: Preferred collection methods.
8
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
9
+ Enabled: true
10
+ PreferredMethods:
11
+ collect: map
12
+ collect!: map!
13
+ find: detect
14
+ find_all: select
15
+ reduce: inject
16
+ Style/DotPosition:
17
+ Description: Checks the position of the dot in multi-line method calls.
18
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
19
+ Enabled: true
20
+ EnforcedStyle: trailing
21
+ SupportedStyles:
22
+ - leading
23
+ - trailing
24
+ Style/FileName:
25
+ Description: Use snake_case for source file names.
26
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files
27
+ Enabled: false
28
+ Exclude: []
29
+ Style/GuardClause:
30
+ Description: Check for conditionals that can be replaced with guard clauses
31
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
32
+ Enabled: false
33
+ MinBodyLength: 1
34
+ Style/IfUnlessModifier:
35
+ Description: Favor modifier if/unless usage when you have a single-line body.
36
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
37
+ Enabled: false
38
+ MaxLineLength: 80
39
+ Style/OptionHash:
40
+ Description: Don't use option hashes when you can use keyword arguments.
41
+ Enabled: false
42
+ Style/PercentLiteralDelimiters:
43
+ Description: Use `%`-literal delimiters consistently
44
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
45
+ Enabled: false
46
+ PreferredDelimiters:
47
+ "%": "()"
48
+ "%i": "()"
49
+ "%q": "()"
50
+ "%Q": "()"
51
+ "%r": "{}"
52
+ "%s": "()"
53
+ "%w": "()"
54
+ "%W": "()"
55
+ "%x": "()"
56
+ Style/PredicateName:
57
+ Description: Check the names of predicate methods.
58
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
59
+ Enabled: true
60
+ NamePrefix:
61
+ - is_
62
+ - has_
63
+ - have_
64
+ NamePrefixBlacklist:
65
+ - is_
66
+ Exclude:
67
+ - spec/**/*
68
+ Style/RaiseArgs:
69
+ Description: Checks the arguments passed to raise/fail.
70
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
71
+ Enabled: false
72
+ EnforcedStyle: exploded
73
+ SupportedStyles:
74
+ - compact
75
+ - exploded
76
+ Style/SignalException:
77
+ Description: Checks for proper usage of fail and raise.
78
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
79
+ Enabled: false
80
+ EnforcedStyle: semantic
81
+ SupportedStyles:
82
+ - only_raise
83
+ - only_fail
84
+ - semantic
85
+ Style/SingleLineBlockParams:
86
+ Description: Enforces the names of some block params.
87
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
88
+ Enabled: false
89
+ Methods:
90
+ - reduce:
91
+ - a
92
+ - e
93
+ - inject:
94
+ - a
95
+ - e
96
+ Style/SingleLineMethods:
97
+ Description: Avoid single-line methods.
98
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
99
+ Enabled: false
100
+ AllowIfMethodIsEmpty: true
101
+ Style/StringLiterals:
102
+ Description: Checks if uses of quotes match the configured preference.
103
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
104
+ Enabled: true
105
+ EnforcedStyle: double_quotes
106
+ SupportedStyles:
107
+ - single_quotes
108
+ - double_quotes
109
+ Style/StringLiteralsInInterpolation:
110
+ Description: Checks if uses of quotes inside expressions in interpolated strings
111
+ match the configured preference.
112
+ Enabled: true
113
+ EnforcedStyle: single_quotes
114
+ SupportedStyles:
115
+ - single_quotes
116
+ - double_quotes
117
+ Style/TrailingCommaInLiteral:
118
+ Description: Checks for trailing comma in parameter lists and literals.
119
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas
120
+ Enabled: false
121
+ EnforcedStyleForMultiline: no_comma
122
+ SupportedStyles:
123
+ - comma
124
+ - no_comma
125
+ Metrics/AbcSize:
126
+ Description: A calculated magnitude based on number of assignments, branches, and
127
+ conditions.
128
+ Enabled: false
129
+ Max: 15
130
+ Metrics/ClassLength:
131
+ Description: Avoid classes longer than 100 lines of code.
132
+ Enabled: false
133
+ CountComments: false
134
+ Max: 100
135
+ Metrics/ModuleLength:
136
+ CountComments: false
137
+ Max: 100
138
+ Description: Avoid modules longer than 100 lines of code.
139
+ Enabled: false
140
+ Metrics/CyclomaticComplexity:
141
+ Description: A complexity metric that is strongly correlated to the number of test
142
+ cases needed to validate a method.
143
+ Enabled: false
144
+ Max: 6
145
+ Metrics/MethodLength:
146
+ Description: Avoid methods longer than 10 lines of code.
147
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
148
+ Enabled: false
149
+ CountComments: false
150
+ Max: 10
151
+ Metrics/ParameterLists:
152
+ Description: Avoid parameter lists longer than three or four parameters.
153
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
154
+ Enabled: false
155
+ Max: 5
156
+ CountKeywordArgs: true
157
+ Metrics/PerceivedComplexity:
158
+ Description: A complexity metric geared towards measuring complexity for a human
159
+ reader.
160
+ Enabled: false
161
+ Max: 7
162
+ Lint/AssignmentInCondition:
163
+ Description: Don't use assignment in conditions.
164
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
165
+ Enabled: false
166
+ AllowSafeAssignment: true
167
+ Style/InlineComment:
168
+ Description: Avoid inline comments.
169
+ Enabled: false
170
+ Style/AccessorMethodName:
171
+ Description: Check the naming of accessor methods for get_/set_.
172
+ Enabled: false
173
+ Style/Alias:
174
+ Description: Use alias_method instead of alias.
175
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
176
+ Enabled: false
177
+ Style/Documentation:
178
+ Description: Document classes and non-namespace modules.
179
+ Enabled: false
180
+ Style/DoubleNegation:
181
+ Description: Checks for uses of double negation (!!).
182
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang
183
+ Enabled: false
184
+ Style/EachWithObject:
185
+ Description: Prefer `each_with_object` over `inject` or `reduce`.
186
+ Enabled: false
187
+ Style/EmptyLiteral:
188
+ Description: Prefer literals to Array.new/Hash.new/String.new.
189
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
190
+ Enabled: false
191
+ Style/ModuleFunction:
192
+ Description: Checks for usage of `extend self` in modules.
193
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
194
+ Enabled: false
195
+ Style/OneLineConditional:
196
+ Description: Favor the ternary operator(?:) over if/then/else/end constructs.
197
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
198
+ Enabled: false
199
+ Style/PerlBackrefs:
200
+ Description: Avoid Perl-style regex back references.
201
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers
202
+ Enabled: false
203
+ Style/Send:
204
+ Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
205
+ may overlap with existing methods.
206
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
207
+ Enabled: false
208
+ Style/SpecialGlobalVars:
209
+ Description: Avoid Perl-style global variables.
210
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
211
+ Enabled: false
212
+ Style/VariableInterpolation:
213
+ Description: Don't interpolate global, instance and class variables directly in
214
+ strings.
215
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
216
+ Enabled: false
217
+ Style/WhenThen:
218
+ Description: Use when x then ... for one-line cases.
219
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
220
+ Enabled: false
221
+ Lint/EachWithObjectArgument:
222
+ Description: Check for immutable argument given to each_with_object.
223
+ Enabled: true
224
+ Lint/HandleExceptions:
225
+ Description: Don't suppress exception.
226
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
227
+ Enabled: false
228
+ Lint/LiteralInCondition:
229
+ Description: Checks of literals used in conditions.
230
+ Enabled: false
231
+ Lint/LiteralInInterpolation:
232
+ Description: Checks for literals used in interpolation.
233
+ Enabled: false
data/Gemfile CHANGED
@@ -1,5 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in mastermind_sname.gemspec
1
+ source "https://rubygems.org"
4
2
  gemspec
5
3
  gem "codeclimate-test-reporter", group: :test
4
+ gem "pry"
data/README.md CHANGED
@@ -1,9 +1,15 @@
1
1
  <a href="https://codeclimate.com/github/andela-oosiname/mastermind_sname"><img src="https://codeclimate.com/github/andela-oosiname/mastermind_sname/badges/gpa.svg" /></a>
2
- [![Build Status](https://travis-ci.org/andela-oosiname/mastermind_sname.svg)](https://travis-ci.org/andela-oosiname/mastermind_sname)
2
+ [![S Status](https://travis-ci.org/andela-oosiname/mastermind_sname.svg)](https://travis-ci.org/andela-oosiname/mastermind_sname)
3
3
  <a href="https://codeclimate.com/github/andela-oosiname/mastermind_sname/coverage"><img src="https://codeclimate.com/github/andela-oosiname/mastermind_sname/badges/coverage.svg" /></a>
4
4
  # MastermindSname
5
5
 
6
- Welcome to Mastermind by sname. An interactive gem packaged and played in a ruby environment.
6
+ Welcome to Mastermind by sname. An interactive gem packaged and played in a ruby environment.
7
+
8
+ ##About Mastermind
9
+
10
+ Mastermind or Master Mind is a code-breaking game. The modern game with pegs was invented in 1970 by Mordecai Meirowitz, an Israeli postmaster and telecommunications expert. It resembles an earlier pencil and paper game called Bulls and Cows that may date back a century or more.
11
+
12
+ The player decides in advance how many games they will play, which must be an even number. The computer is the codemaker, the player is the codebreaker. The codemaker chooses a pattern of colours. Duplicates are allowed. The codebreaker tries to figure out the pattern with a limited number of guesses.
7
13
 
8
14
  ## Installation
9
15
 
@@ -23,7 +29,7 @@ Or install it yourself as:
23
29
 
24
30
  $ gem install mastermind_sname
25
31
 
26
- ## Usage
32
+ ## Game Play
27
33
 
28
34
  A splash screen is showed once a game is started from where the user can start a game or read instructions.
29
35
 
data/Rakefile CHANGED
@@ -2,5 +2,4 @@ require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
5
+ task default: :spec
@@ -1,5 +1,4 @@
1
- #!/usr/bin/env ruby
2
-
3
1
  require 'mastermind_sname'
2
+ new_game = MastermindSname::Sname.new
3
+ new_game.start
4
4
 
5
- MastermindSname::Sname.start
@@ -1,34 +1,28 @@
1
- require_relative "mastermind_sname/sname/test.rb"
2
- require_relative "mastermind_sname/sname/colour_generator.rb"
1
+ require_relative "mastermind_sname/sname/game_logic.rb"
2
+ require_relative "mastermind_sname/sname/game_colour.rb"
3
+ require_relative "mastermind_sname/sname/command.rb"
3
4
  require_relative "mastermind_sname/sname/game.rb"
4
- require_relative "mastermind_sname/sname/player_details.rb"
5
- require_relative "mastermind_sname/sname/messages.rb"
6
- require_relative "mastermind_sname/sname/checkers.rb"
7
- require_relative "mastermind_sname/sname/commands.rb"
8
- require_relative "mastermind_sname/sname/timer.rb"
5
+ require_relative "mastermind_sname/sname/message.rb"
6
+ require_relative "mastermind_sname/sname/input.rb"
7
+ require_relative "mastermind_sname/sname/player.rb"
9
8
 
10
9
  module MastermindSname
11
10
  class Sname
12
- def self.start
13
- SnameMessages::Messages.splash_screen
14
- my_choice = get_choice
15
- start_choice(my_choice)
11
+ include Input
12
+ def start
13
+ @message = Message.new
14
+ @message.splash_screen
15
+ start_choice get_input
16
16
  end
17
- def self.start_choice(user_choice)
17
+
18
+ def start_choice(user_choice)
18
19
  case user_choice
19
20
  when "p", "play"
20
- SnamePlayer::Player.set_player
21
- SnameGame::Game.new.play
22
- when "q","quit" then exit
23
- when "r", "read" then SnameMessages::Messages.get_instructions
21
+ player = Player.new.set_player
22
+ Game.new(player).play
23
+ when "q", "quit" then exit
24
+ when "r", "read" then @message.get_instructions
24
25
  end
25
26
  end
26
-
27
- def self.get_choice
28
- choice = gets.chomp.downcase
29
- choice
30
- end
31
27
  end
32
28
  end
33
-
34
-
@@ -0,0 +1,32 @@
1
+ require_relative "game.rb"
2
+ module MastermindSname
3
+ class Command
4
+ attr_accessor :game_colours, :guesses
5
+ def initialize
6
+ @game_colours = game_colours
7
+ end
8
+
9
+ def action(guess, game_colours, guesses)
10
+ @game_colours = game_colours
11
+ @guesses = guesses
12
+ case guess
13
+ when "quit", "q" then exit
14
+ when "cheat", "c" then cheat_mode
15
+ when "h", "history" then get_history
16
+ end
17
+ end
18
+
19
+ def cheat_mode
20
+ puts Message.new.cheat(@game_colours)
21
+ exit
22
+ end
23
+
24
+ def get_history
25
+ return "No guesses yet" if @guesses.empty?
26
+ @guesses.each_with_index\
27
+ { |val, i| print " #{i + 1} ==> #{val} \n" }
28
+ print "\n"
29
+ puts "Enter guess"
30
+ end
31
+ end
32
+ end
@@ -1,129 +1,91 @@
1
- require_relative "commands.rb"
2
- require_relative "dump_data.rb"
3
- module SnameGame
1
+ require_relative "record.rb"
2
+ require_relative "input.rb"
3
+ module MastermindSname
4
4
  class Game
5
- attr_accessor :level,:game_colours,:user_colours,:number_of_guesses, :user_guess, :player_hash, :user_guess_array, :user_guess_count
6
-
7
- def initialize_values
8
- @user_guess_count = 0
9
- @user_guess_array = []
10
- @player_hash = SnamePlayer::Player.get_player
11
- @game_colours = SnameGameColours::GameColours.get_colours(@player_hash["level"])
12
- create_records_file unless File.file?("game_records.json")
13
- File.file?("game_records.json")
5
+ include Input
6
+ attr_accessor :game_colours, :guess, :player,
7
+ :start_time
8
+ def initialize(player)
9
+ @guesses = []
10
+ @player = player
11
+ @game_colours = GameColour.new(@player).get_colours
12
+ puts @game_colours.join("")
13
+ create_records_file unless File.file?("game_records.json")
14
+ @message = Message.new
14
15
  end
15
16
 
16
17
  def play
17
- initialize_values
18
- @player_hash["start_time"] = SnameTimer::Timer.set_time
19
- SnameMessages::Messages.start_message(@player_hash,@game_colours)
18
+ @start_time = Time.now
19
+ puts @message.start(@player, @game_colours)
20
20
  start_guessing
21
- play_again
21
+ play_again
22
22
  end
23
23
 
24
24
  def start_guessing
25
- while @user_guess_count <= 11 && !is_correct? do
25
+ loop do
26
26
  collect_user_guess
27
- break if is_quit?
28
27
  puts record_guess
29
- end
30
- unless SnameLogics::Logics.is_input_command?(@user_guess)
31
- puts game_end
28
+ break if @guesses.length > 9 || correct?
32
29
  end
30
+ puts game_end
33
31
  end
34
32
 
35
- def is_quit?
36
- arr = ["cheat","quit","q","c"]
37
- arr.each do |x|
38
- return true if @user_guess == x
39
- end
40
- return false
41
- end
42
-
43
-
44
- def is_correct?
45
- return true if @user_guess == @game_colours.join("")
46
- return false
33
+ def correct?
34
+ @guess == @game_colours.join("")
47
35
  end
48
36
 
49
37
  def create_records_file
50
- system "echo '{\"beginner\":[],\"intermediate\":[],\"advanced\":[]}' > game_records.json"
51
- File.file?("game_records.json")
38
+ system "echo '{\"beginner\":[],\"intermediate\":[],\"advanced\":[]}' > g"\
39
+ "ame_records.json"
52
40
  end
53
41
 
54
42
  def update_player
55
- @player_hash["guesses_count"] = @user_guess_array.length
56
- @player_hash["full_level"] = get_full_level_name
57
- @player_hash["game_colours"] = @game_colours
58
- @player_hash["end_time"] = SnameTimer::Timer.set_time
59
- @player_hash["time"] = SnameTimer::Timer.get_time_taken(@player_hash["start_time"],@player_hash["end_time"])
60
- @player_hash
61
- end
62
-
63
- def get_full_level_name
64
- case @player_hash["level"]
65
- when "i" then return "intermediate"
66
- when "b" then return "beginner"
67
- when "a" then return "advanced"
68
- end
43
+ @player[:guesses_count] = @guesses.length
44
+ @player[:game_colours] = @game_colours
45
+ @player[:time] = (Time.now - @start_time).round.time_format
69
46
  end
70
47
 
71
48
  def game_end
72
- if @user_guess_count > 11
73
- return "GAME OVER! Out of Guesses"
74
- else
49
+ if correct?
75
50
  update_player
76
- BuildRecord::Sname.new.set_new_record(@player_hash)
77
- SnameMessages::Messages.congratulations_screen(@player_hash)
78
- BuildRecord::Sname.new.display_top_ten(@player_hash)
51
+ record = Record.new(@player)
52
+ record.set_new
53
+ @message.congratulations_screen @player
54
+ record.display_top_ten
55
+ else
56
+ @message.game_over
79
57
  end
80
58
  end
81
59
 
82
60
  def collect_user_guess
83
- valid = false
84
- puts "You've taken #{@user_guess_array.length} guess(es)" if @user_guess_array != []
85
- @user_guess = gets.chomp.downcase
86
- if @user_guess == "h"
87
- valid = true
88
- return get_guess_history
61
+ puts "#{10 - @guesses.length} guess(es) left" unless @guesses.empty?
62
+ @guess = get_input
63
+ loop do
64
+ @game_logic = GameLogic.new(@guess, @game_colours)
65
+ valid = @game_logic.valid_length? || @game_logic.input_command?
66
+ Command.new.action(@guess, @game_colours, @guesses)
67
+ puts @game_logic.length_feedback unless valid
68
+ @guess = get_input unless valid
69
+ break if valid
89
70
  end
90
- until valid == true do
91
- valid = true if SnameLogics::Logics.is_input_command?(@user_guess)
92
- puts SnameCommands::Commands.command_action(@user_guess,@game_colours)
93
- valid = SnameLogics::Logics.check_guess?(@user_guess, @player_hash["level"]) if !valid
94
- puts SnameLogics::Logics.check_guess_length?(@user_guess, @player_hash["level"]) if !valid
95
- @user_guess = gets.chomp.downcase if !valid
96
- end
97
- end
98
-
99
- def user_guess_check
100
71
  end
101
72
 
102
73
  def play_again
103
- puts "Do you want to play again? (y for yes/ press any other key to quit)"
104
- choice = gets.chomp.downcase
74
+ @message.play_again
75
+ choice = get_input
105
76
  if choice == "y"
106
- MastermindSname::Sname.start
77
+ Game.new(@player).play
107
78
  else
108
79
  exit
109
80
  end
110
81
  end
111
82
 
112
- def get_guess_history
113
- for i in (0...@user_guess_array.length) do print " #{i+1} ==> #{@user_guess_array[i]} \n" end
114
- print "\n"
115
- puts "Enter guess"
116
- return @user_guess_array
117
- end
118
-
119
83
  def record_guess
120
- if @user_guess != "h"
121
- @user_guess_count += 1
122
- @user_guess_array << @user_guess
123
- is_correct?
124
- SnameLogics::Logics.get_feedback(@user_guess,@game_colours)
125
- end
84
+ unless @guess == "h"
85
+ @guesses << @guess
86
+ correct?
87
+ @game_logic.get_feedback
88
+ end
126
89
  end
127
-
128
- end
90
+ end
129
91
  end