mastermind_sname 1.0 → 2.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 +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
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mastermind_sname
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '
|
4
|
+
version: '2.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Olumuyiwa Osiname
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,8 +52,8 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description: Mastermind is a game where a user tries to guess a sequence of colour
|
56
|
-
codes.
|
55
|
+
description: '["Mastermind is a game where a user tries to guess a sequence of colour
|
56
|
+
codes."]'
|
57
57
|
email:
|
58
58
|
- olumuyiwa.osiname@andela.com
|
59
59
|
executables:
|
@@ -61,7 +61,9 @@ executables:
|
|
61
61
|
extensions: []
|
62
62
|
extra_rdoc_files: []
|
63
63
|
files:
|
64
|
+
- ".codeclimate.yml"
|
64
65
|
- ".gitignore"
|
66
|
+
- ".rubocop.yml"
|
65
67
|
- ".travis.yml"
|
66
68
|
- Gemfile
|
67
69
|
- LICENSE
|
@@ -71,21 +73,18 @@ files:
|
|
71
73
|
- bin/console
|
72
74
|
- bin/mastermind
|
73
75
|
- bin/setup
|
74
|
-
- game_records.json
|
75
76
|
- lib/mastermind_sname.rb
|
76
|
-
- lib/mastermind_sname/sname/
|
77
|
-
- lib/mastermind_sname/sname/colour_generator.rb
|
78
|
-
- lib/mastermind_sname/sname/commands.rb
|
79
|
-
- lib/mastermind_sname/sname/dump_data.rb
|
77
|
+
- lib/mastermind_sname/sname/command.rb
|
80
78
|
- lib/mastermind_sname/sname/game.rb
|
81
|
-
- lib/mastermind_sname/sname/
|
82
|
-
- lib/mastermind_sname/sname/
|
83
|
-
- lib/mastermind_sname/sname/
|
84
|
-
- lib/mastermind_sname/sname/
|
85
|
-
- lib/mastermind_sname/sname/
|
79
|
+
- lib/mastermind_sname/sname/game_colour.rb
|
80
|
+
- lib/mastermind_sname/sname/game_logic.rb
|
81
|
+
- lib/mastermind_sname/sname/input.rb
|
82
|
+
- lib/mastermind_sname/sname/message.rb
|
83
|
+
- lib/mastermind_sname/sname/player.rb
|
84
|
+
- lib/mastermind_sname/sname/record.rb
|
86
85
|
- lib/mastermind_sname/version.rb
|
87
|
-
- lib/records.json
|
88
86
|
- mastermind_sname.gemspec
|
87
|
+
- mastermind_sname.sublime-workspace
|
89
88
|
- rspec.rake
|
90
89
|
homepage: https://github.com/andela-oosiname/mastermind_sname
|
91
90
|
licenses:
|
@@ -107,8 +106,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
106
|
version: '0'
|
108
107
|
requirements: []
|
109
108
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.4.
|
109
|
+
rubygems_version: 2.4.6
|
111
110
|
signing_key:
|
112
111
|
specification_version: 4
|
113
|
-
summary: This installs mastermind on the pc.
|
112
|
+
summary: '["This installs mastermind on the pc."]'
|
114
113
|
test_files: []
|
data/game_records.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"beginner":[{"name":"Aaaa","game_colours":"rgrr","guesses":5,"times":"25s"}],"intermediate":[],"advanced":[]}
|
@@ -1,57 +0,0 @@
|
|
1
|
-
module SnameLogics
|
2
|
-
class Logics
|
3
|
-
def self.is_valid_level?(level)
|
4
|
-
@level = level
|
5
|
-
if @level == "a" || @level == "i" || @level == "b"
|
6
|
-
return true
|
7
|
-
else
|
8
|
-
return false
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.check_guess_length?(guess,level)
|
13
|
-
result = case
|
14
|
-
when level == "b" && guess.length > 4 then return "guess is too long"
|
15
|
-
when level == "i" && guess.length > 6 then return "guess is too long"
|
16
|
-
when level == "a" && guess.length > 8 then return "guess is too long"
|
17
|
-
end
|
18
|
-
return "guess is too short"
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.is_input_command?(guess)
|
22
|
-
return true if guess == "cheat" || guess == "exit" || guess == "h" || guess == "c" || guess == "q"
|
23
|
-
return true if guess == "quit"
|
24
|
-
return false
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.check_guess?(guess,level)
|
28
|
-
return true if guess.length == 4 && level == "b"
|
29
|
-
return true if guess.length == 6 && level == "i"
|
30
|
-
return true if guess.length == 8 && level == "a"
|
31
|
-
return false
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.get_no_correct_elements
|
35
|
-
no_of_elements = 0
|
36
|
-
for i in (0...@user_guess.length) do
|
37
|
-
no_of_elements += 1 if @user_guess.split("").sort[i] == @colour_code.sort[i]
|
38
|
-
end
|
39
|
-
no_of_elements
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.get_no_correct_positions
|
43
|
-
correct_positions = 0
|
44
|
-
for i in (0... @user_guess.length) do
|
45
|
-
correct_positions += 1 if @user_guess[i] == @colour_code[i]
|
46
|
-
end
|
47
|
-
correct_positions
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.get_feedback(user_guess,colour_code)
|
51
|
-
@user_guess = user_guess
|
52
|
-
@colour_code = colour_code
|
53
|
-
feedback = "#{@user_guess} has #{get_no_correct_elements} of the correct elements with #{get_no_correct_positions} in the correct positions"
|
54
|
-
feedback
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
module SnameGameColours
|
2
|
-
class GameColours
|
3
|
-
|
4
|
-
attr_accessor :beginner_colours, :intermediate_colours, :advanced_colours, :level
|
5
|
-
|
6
|
-
def self.beginner_colours
|
7
|
-
["r","y","g","b"]
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.intermediate_colours
|
11
|
-
beginner_colours << "o"
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.advanced_colours
|
15
|
-
intermediate_colours << "v"
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
|
-
def self.set_colours(level)
|
20
|
-
case level
|
21
|
-
when "b"
|
22
|
-
return beginner_colours
|
23
|
-
when "i"
|
24
|
-
return intermediate_colours
|
25
|
-
when "a"
|
26
|
-
return advanced_colours
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.get_colours(level)
|
31
|
-
@level = level
|
32
|
-
final_colour_array = []
|
33
|
-
initial_colour_array = set_colours(level)
|
34
|
-
code_length = set_length_of_colours
|
35
|
-
until final_colour_array.length == code_length
|
36
|
-
final_colour_array << initial_colour_array.sample
|
37
|
-
end
|
38
|
-
final_colour_array
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.set_length_of_colours
|
42
|
-
case @level
|
43
|
-
when "b"
|
44
|
-
return 4
|
45
|
-
when "i"
|
46
|
-
return 6
|
47
|
-
when "a"
|
48
|
-
return 8
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require_relative "game.rb"
|
2
|
-
module SnameCommands
|
3
|
-
class Commands
|
4
|
-
def self.command_action(to_do,colours)
|
5
|
-
colours = colours
|
6
|
-
exit if to_do == "quit" || to_do == "q"
|
7
|
-
cheat_mode(colours) if to_do == "cheat" || to_do == "c"
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.cheat_mode(game_colours)
|
11
|
-
"The sequence is #{game_colours.join}"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
module BuildRecord
|
2
|
-
class Sname
|
3
|
-
require 'json'
|
4
|
-
def set_new_record(player_hash)
|
5
|
-
@player_hash = player_hash
|
6
|
-
@record = get_record
|
7
|
-
@new_record = @record[player_hash["full_level"]] << {"name"=>player_hash["name"],"game_colours" => player_hash["game_colours"].join(""), "guesses" => player_hash["guesses_count"], "times" => player_hash["time"]}
|
8
|
-
select_level
|
9
|
-
end
|
10
|
-
def get_record
|
11
|
-
json = File.read("game_records.json")
|
12
|
-
obj = JSON.parse(json)
|
13
|
-
return obj
|
14
|
-
end
|
15
|
-
|
16
|
-
|
17
|
-
def select_level
|
18
|
-
case @player_hash["level"]
|
19
|
-
when "b"
|
20
|
-
update_beginner_record
|
21
|
-
when "i"
|
22
|
-
update_intermediate_record
|
23
|
-
when "a"
|
24
|
-
update_advanced_record
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def update_beginner_record
|
29
|
-
tempHash = {
|
30
|
-
"beginner" => @new_record,
|
31
|
-
"intermediate" => @record["intermediate"],
|
32
|
-
"advanced" => @record["advanced"]
|
33
|
-
}
|
34
|
-
File.open("game_records.json","w") do |f|
|
35
|
-
f.write(tempHash.to_json)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def update_intermediate_record
|
40
|
-
tempHash = {
|
41
|
-
"beginner" => @record["beginner"],
|
42
|
-
"intermediate" => @new_record,
|
43
|
-
"advanced" => @record["advanced"]
|
44
|
-
}
|
45
|
-
File.open("game_records.json","w") do |f|
|
46
|
-
f.write(tempHash.to_json)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
def update_advanced_record
|
50
|
-
tempHash = {
|
51
|
-
"beginner" => @record["beginner"],
|
52
|
-
"intermediate" => @record["intermediate"],
|
53
|
-
"advanced" => @new_record
|
54
|
-
}
|
55
|
-
File.open("game_records.json","w") do |f|
|
56
|
-
f.write(tempHash.to_json)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def display_top_ten(player_hash)
|
61
|
-
SnameMessages::Messages.top_ten_head
|
62
|
-
level = player_hash["full_level"]
|
63
|
-
record = get_record
|
64
|
-
level_record = record[level].sort_by { |hsh| hsh["guesses"] }
|
65
|
-
n = 0
|
66
|
-
record[level].length.times do
|
67
|
-
print "#{level_record[n]["name"]} solved #{level_record[n]["game_colours"]} in #{level_record[n]["guesses"]} guesses over #{level_record[n]["times"]}"
|
68
|
-
n += 1
|
69
|
-
print "\n"
|
70
|
-
break if n == 10
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,117 +0,0 @@
|
|
1
|
-
module SnameMessages
|
2
|
-
class Messages
|
3
|
-
def self.invalid_level
|
4
|
-
puts "Please enter a valid level, 'b' for Beginner, 'i' for Intermediate, 'a' for Advanced"
|
5
|
-
end
|
6
|
-
def self.invalid_code
|
7
|
-
puts "Your colour code contains invalid letters. TIP: it should be one of r,g,y,b,o,v"
|
8
|
-
end
|
9
|
-
def self.get_level_message
|
10
|
-
puts "Select your level: (b)eginner, (i)ntermediate, (a)dvanced"
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.congratulations_screen(player_hash)
|
14
|
-
@player_hash = player_hash
|
15
|
-
horizontal_stars
|
16
|
-
vertical_stars
|
17
|
-
body_message(player_hash)
|
18
|
-
vertical_stars
|
19
|
-
horizontal_stars
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.start_message(player_hash,game_colours)
|
23
|
-
colours = SnameGameColours::GameColours.beginner_colours.join("") if game_colours.length == 4
|
24
|
-
colours = SnameGameColours::GameColours.intermediate_colours.join("") if game_colours.length == 6
|
25
|
-
colours = SnameGameColours::GameColours.advanced_colours.join("") if game_colours.length == 8
|
26
|
-
puts "Hello #{player_hash["name"]} I have generated a sequence with #{game_colours.length} elements made up of a combination of any of: #{colours}... Can you guess the colour"
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
def self.horizontal_stars
|
31
|
-
30.times do
|
32
|
-
print "* "
|
33
|
-
end
|
34
|
-
print "\n"
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.vertical_stars
|
38
|
-
3.times do
|
39
|
-
print "*"
|
40
|
-
blank_space(59)
|
41
|
-
print "*"
|
42
|
-
print "\n"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.body_message(player_hash)
|
47
|
-
blank_space(10)
|
48
|
-
puts "CONGRATULATIONS!! You got the sequence '#{player_hash["game_colours"].join("")}'"
|
49
|
-
blank_space(10)
|
50
|
-
puts "LEVEL: #{player_hash["full_level"]}"
|
51
|
-
blank_space(10)
|
52
|
-
puts "GUESSES: #{player_hash["guesses_count"]}"
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.blank_space(n)
|
56
|
-
n.times do
|
57
|
-
print " "
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.message_border
|
62
|
-
blank_space(10)
|
63
|
-
56.times do
|
64
|
-
print "="
|
65
|
-
end
|
66
|
-
print "\n"
|
67
|
-
blank_space(20)
|
68
|
-
end
|
69
|
-
def self.goodbye_message
|
70
|
-
message_border
|
71
|
-
puts "Thank you for playing MASTERMIND"
|
72
|
-
end
|
73
|
-
|
74
|
-
def self.splash_screen
|
75
|
-
blank_space(10)
|
76
|
-
56.times do
|
77
|
-
print "="
|
78
|
-
end
|
79
|
-
print "\n"
|
80
|
-
blank_space(10)
|
81
|
-
puts "Welcome to MASTERMIND"
|
82
|
-
blank_space(10)
|
83
|
-
puts "Would you like to (p)lay, (r)ead instructions or (q)uit"
|
84
|
-
end
|
85
|
-
|
86
|
-
def self.border
|
87
|
-
59.times do
|
88
|
-
print "="
|
89
|
-
end
|
90
|
-
print "\n"
|
91
|
-
end
|
92
|
-
|
93
|
-
def self.top_ten_head
|
94
|
-
20.times do
|
95
|
-
print "="
|
96
|
-
end
|
97
|
-
print "Top Players"
|
98
|
-
20.times do
|
99
|
-
print "="
|
100
|
-
end
|
101
|
-
print "\n"
|
102
|
-
end
|
103
|
-
|
104
|
-
def self.get_instructions
|
105
|
-
print "Instructions\nEnter p from splash screen to start a new game\n\nEnter your name and select a level
|
106
|
-
\nb - beginner, code is 4 elements long\ni - intermediate, code is 6 elements long\na - advanced, code is 8 elements long
|
107
|
-
\nRandom code of elements is generated depending on the level. You have 12 guesses
|
108
|
-
\nafter every guess, you are presented with a message identifying the number of elements you got correctly, and in what positions.
|
109
|
-
\nTo view entry history, enter h or history at any time.
|
110
|
-
\nTo view sequence generated, enter c or cheat at any time
|
111
|
-
\nTo quit the game at any point enter q or quit.
|
112
|
-
\nThe game is timed and on successful completion, the user gets a detail of his performance and a top players list is displayed"
|
113
|
-
puts ""
|
114
|
-
MastermindSname::Sname.start
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module SnamePlayer
|
2
|
-
class Player
|
3
|
-
attr_accessor :level, :name
|
4
|
-
|
5
|
-
def self.set_player
|
6
|
-
set_player_name
|
7
|
-
set_level
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.set_player_name
|
11
|
-
puts "Enter first name"
|
12
|
-
@name = gets.chomp.downcase
|
13
|
-
@name.capitalize!
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.set_level
|
17
|
-
puts SnameMessages::Messages.get_level_message
|
18
|
-
level = gets.chomp.downcase
|
19
|
-
status = SnameLogics::Logics.is_valid_level?(level)
|
20
|
-
while status == false do
|
21
|
-
puts SnameMessages::Messages.invalid_level
|
22
|
-
level = gets.chomp.downcase
|
23
|
-
status = SnameLogics::Logics.is_valid_level?(level)
|
24
|
-
end
|
25
|
-
@level = level
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.get_player
|
29
|
-
{"name" => @name, "level" => @level}
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
File without changes
|
File without changes
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module SnameTimer
|
2
|
-
class Timer
|
3
|
-
|
4
|
-
def self.set_time
|
5
|
-
time = Time.now
|
6
|
-
time_array = [time.hour, time.min, time.sec]
|
7
|
-
(time_array[0] * 3600) + (time_array[1] * 60) + time_array[2]
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.format_time(time_interval)
|
11
|
-
mins = 0
|
12
|
-
while time_interval > 59 do
|
13
|
-
mins = mins + time_interval/60
|
14
|
-
time_interval -= (mins * 60)
|
15
|
-
end
|
16
|
-
secs = time_interval
|
17
|
-
return "#{secs}s" if mins == 0
|
18
|
-
return "#{mins}m#{secs}s"
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.get_time_taken(start_time,end_time)
|
22
|
-
time_interval = end_time.to_i - start_time.to_i
|
23
|
-
format_time(time_interval)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|