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 +4 -4
- data/.codeclimate.yml +27 -0
- data/.rubocop.yml +233 -0
- data/Gemfile +2 -3
- data/README.md +9 -3
- data/Rakefile +1 -2
- data/bin/mastermind +2 -3
- data/lib/mastermind_sname.rb +17 -23
- data/lib/mastermind_sname/sname/command.rb +32 -0
- data/lib/mastermind_sname/sname/game.rb +51 -89
- data/lib/mastermind_sname/sname/game_colour.rb +27 -0
- data/lib/mastermind_sname/sname/game_logic.rb +54 -0
- data/lib/mastermind_sname/sname/input.rb +8 -0
- data/lib/mastermind_sname/sname/message.rb +131 -0
- data/lib/mastermind_sname/sname/player.rb +44 -0
- data/lib/mastermind_sname/sname/record.rb +40 -0
- data/mastermind_sname.gemspec +10 -11
- data/mastermind_sname.sublime-workspace +166 -0
- metadata +16 -17
- data/game_records.json +0 -1
- data/lib/mastermind_sname/sname/checkers.rb +0 -57
- data/lib/mastermind_sname/sname/colour_generator.rb +0 -53
- data/lib/mastermind_sname/sname/commands.rb +0 -15
- data/lib/mastermind_sname/sname/dump_data.rb +0 -75
- data/lib/mastermind_sname/sname/messages.rb +0 -117
- data/lib/mastermind_sname/sname/player_details.rb +0 -33
- data/lib/mastermind_sname/sname/test.rb +0 -0
- data/lib/mastermind_sname/sname/testjason.json +0 -0
- data/lib/mastermind_sname/sname/timer.rb +0 -26
- data/lib/records.json +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b5cbfe80156234fb5b143fc49bc6011b533a056
|
4
|
+
data.tar.gz: b1fe6b5d36c85eaac5777d4b32ee3c5004b81e67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fae0790effd1f82fa8b85f2ca93861098dccee1006ce9213dcd38ad57f6537a9ea7fae0eb1f419c8e5286ff745fff44e8ddf4ba560c9e61fe6390a35007ae631
|
7
|
+
data.tar.gz: 5c6bcb6c05ecec2a02f54a85f078077e9424d195a88d5b9d88e0b21ebda190512497b1819bbb26930fc72f08b650226ea51c6fcdccbe4c1ca8e67effa87767a5
|
data/.codeclimate.yml
ADDED
@@ -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/**/*
|
data/.rubocop.yml
ADDED
@@ -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
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
|
-
[![
|
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
|
-
##
|
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
data/bin/mastermind
CHANGED
data/lib/mastermind_sname.rb
CHANGED
@@ -1,34 +1,28 @@
|
|
1
|
-
require_relative "mastermind_sname/sname/
|
2
|
-
require_relative "mastermind_sname/sname/
|
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/
|
5
|
-
require_relative "mastermind_sname/sname/
|
6
|
-
require_relative "mastermind_sname/sname/
|
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
include Input
|
12
|
+
def start
|
13
|
+
@message = Message.new
|
14
|
+
@message.splash_screen
|
15
|
+
start_choice get_input
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
|
+
def start_choice(user_choice)
|
18
19
|
case user_choice
|
19
20
|
when "p", "play"
|
20
|
-
|
21
|
-
|
22
|
-
when "q","quit" then exit
|
23
|
-
when "r", "read" then
|
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 "
|
2
|
-
require_relative "
|
3
|
-
module
|
1
|
+
require_relative "record.rb"
|
2
|
+
require_relative "input.rb"
|
3
|
+
module MastermindSname
|
4
4
|
class Game
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@game_colours =
|
12
|
-
|
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
|
-
|
18
|
-
@
|
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
|
-
|
25
|
+
loop do
|
26
26
|
collect_user_guess
|
27
|
-
break if is_quit?
|
28
27
|
puts record_guess
|
29
|
-
|
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
|
36
|
-
|
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\":[]}' >
|
51
|
-
|
38
|
+
system "echo '{\"beginner\":[],\"intermediate\":[],\"advanced\":[]}' > g"\
|
39
|
+
"ame_records.json"
|
52
40
|
end
|
53
41
|
|
54
42
|
def update_player
|
55
|
-
@
|
56
|
-
@
|
57
|
-
@
|
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
|
73
|
-
return "GAME OVER! Out of Guesses"
|
74
|
-
else
|
49
|
+
if correct?
|
75
50
|
update_player
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
valid =
|
88
|
-
|
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
|
-
|
104
|
-
choice =
|
74
|
+
@message.play_again
|
75
|
+
choice = get_input
|
105
76
|
if choice == "y"
|
106
|
-
|
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
|
-
|
121
|
-
@
|
122
|
-
|
123
|
-
|
124
|
-
|
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
|