femis_hangman 0.1.1 → 0.1.2
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/README.md +3 -1
- data/lib/femis_hangman/game.rb +10 -18
- data/lib/femis_hangman/message.rb +29 -15
- data/lib/femis_hangman/router.rb +44 -67
- data/lib/femis_hangman/version.rb +1 -1
- data/lib/femis_hangman/word.rb +3 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc8e5ebdddb0d51dc27b78de8a03aaba40033dd7
|
4
|
+
data.tar.gz: 4871521fc341b6aa4821c2d7d5255f0cb6aff5fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d89ba5e9f217569d4fc74bb733b1bfc0104c44c62ab52921316eefdfa9065540fe37b1721f971f3230a73ef4206b2492551b85cdd1510021ece1321441abf4e3
|
7
|
+
data.tar.gz: 0627e01a7ee8570f13aafd2f45838248459cc7474f2525c0f5510c2bfccd64573472a441eea24fa3800baa2b26fc2f4414363d3cd7dfabbe1832c5dcad05728c
|
data/README.md
CHANGED
@@ -6,10 +6,12 @@ Hangman is a game of guesses. A word is randomly selected from a predefined list
|
|
6
6
|
|
7
7
|
The game has three levels:
|
8
8
|
1) Beginner | 4-8 words | 8 turns
|
9
|
+
|
9
10
|
2) Intermediate | 9-12 words | 9 turns
|
11
|
+
|
10
12
|
3) Advanced | Above 12 | 10 turns
|
11
13
|
|
12
|
-
The game also has an option of either a boring or graphic output. The boring feedback type looks like `You are dead. The word is unforgatable` while the graphic feedback looks something like
|
14
|
+
The game also has an option of either a boring or graphic output. The boring feedback type looks like `You are dead. The word is unforgatable` while the graphic feedback looks something like a match stick drawing.
|
13
15
|
|
14
16
|
## Installation
|
15
17
|
|
data/lib/femis_hangman/game.rb
CHANGED
@@ -13,12 +13,9 @@ module FemisHangman
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def control(input)
|
16
|
-
if input.size > 1
|
17
|
-
|
18
|
-
|
19
|
-
play(input)
|
20
|
-
else
|
21
|
-
invalid_prompt
|
16
|
+
if input.size > 1 then commands(input)
|
17
|
+
elsif input.size == 1 then play(input)
|
18
|
+
else invalid_prompt
|
22
19
|
end
|
23
20
|
end
|
24
21
|
|
@@ -39,12 +36,11 @@ module FemisHangman
|
|
39
36
|
def include_letter(letter, history)
|
40
37
|
if history.include?(letter)
|
41
38
|
duplicate_prompt(letter)
|
42
|
-
|
39
|
+
@history
|
43
40
|
else
|
44
41
|
history << letter
|
45
42
|
@history = history
|
46
43
|
end
|
47
|
-
@history
|
48
44
|
end
|
49
45
|
|
50
46
|
def check_game
|
@@ -57,9 +53,8 @@ module FemisHangman
|
|
57
53
|
end
|
58
54
|
|
59
55
|
def show_word
|
60
|
-
word = @word.split('')
|
61
56
|
output = ''
|
62
|
-
word.each do |letter|
|
57
|
+
@word.split('').each do |letter|
|
63
58
|
if @history.include?(letter)
|
64
59
|
output << "#{letter} "
|
65
60
|
else
|
@@ -70,13 +65,10 @@ module FemisHangman
|
|
70
65
|
end
|
71
66
|
|
72
67
|
def won?
|
73
|
-
word = @word.split('')
|
74
68
|
length = 0
|
75
|
-
word.each {|val| length += 1 if @history.include?(val)}
|
76
|
-
if length == word.size
|
77
|
-
|
78
|
-
else
|
79
|
-
false
|
69
|
+
@word.split('').each {|val| length += 1 if @history.include?(val)}
|
70
|
+
if length == word.size then true
|
71
|
+
else false
|
80
72
|
end
|
81
73
|
end
|
82
74
|
|
@@ -105,10 +97,10 @@ module FemisHangman
|
|
105
97
|
end
|
106
98
|
|
107
99
|
def game_history
|
108
|
-
output = ''
|
109
100
|
if @history.empty?
|
110
|
-
''
|
101
|
+
'NO LETTER YET'
|
111
102
|
else
|
103
|
+
output = ''
|
112
104
|
@history.each {|letter| output << "#{letter} "}
|
113
105
|
end
|
114
106
|
output
|
@@ -8,7 +8,7 @@ module Message
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def load_prompt
|
11
|
-
puts "Choose the game you want to resume
|
11
|
+
puts "Choose the game you want to resume from the list below\nPress the respective number"
|
12
12
|
end
|
13
13
|
|
14
14
|
def begin_prompt
|
@@ -16,12 +16,22 @@ module Message
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def instructions_prompt
|
19
|
-
puts
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
puts <<-PUTS
|
20
|
+
########################################################
|
21
|
+
|
22
|
+
This gem is an implementation of the hangman game.
|
23
|
+
Attempt to guess the missing letters correctly.
|
24
|
+
You have a limited number of tries.
|
25
|
+
If you use up all your chances without getting
|
26
|
+
the word correctly, you will be hanged.
|
27
|
+
|
28
|
+
To play a new game: Press 'p' or 'play'
|
29
|
+
To load a saved game: Press 'l' or 'load'
|
30
|
+
To show insructions: Press 'i' or 'instructions'
|
31
|
+
To quit Hangman: Press 'q' or 'quit'
|
32
|
+
|
33
|
+
########################################################
|
34
|
+
PUTS
|
25
35
|
end
|
26
36
|
|
27
37
|
def save_prompt
|
@@ -38,7 +48,7 @@ module Message
|
|
38
48
|
end
|
39
49
|
|
40
50
|
def lost_gui(word)
|
41
|
-
puts <<-
|
51
|
+
puts <<-PUTS
|
42
52
|
-+----------+-
|
43
53
|
| |
|
44
54
|
| o
|
@@ -51,11 +61,11 @@ You are dead!
|
|
51
61
|
################
|
52
62
|
The word is #{word}
|
53
63
|
################
|
54
|
-
|
64
|
+
PUTS
|
55
65
|
end
|
56
66
|
|
57
67
|
def won_gui(word)
|
58
|
-
|
68
|
+
puts <<-PUTS
|
59
69
|
-+----------+-
|
60
70
|
| |
|
61
71
|
|
|
@@ -68,20 +78,20 @@ You are free to go
|
|
68
78
|
################
|
69
79
|
The word is #{word}
|
70
80
|
################
|
71
|
-
|
81
|
+
PUTS
|
72
82
|
end
|
73
83
|
|
74
84
|
def level_prompt
|
75
|
-
puts "Choose your difficulty level\n\n1: Beginner\n2: Intermediate\n3: Advanced"
|
85
|
+
puts "Choose your difficulty level\n\n1: Beginner\n2: Intermediate\n3: Advanced\n"
|
76
86
|
end
|
77
87
|
|
78
88
|
def feedback_prompt
|
79
|
-
puts "Choose your feedback type\n\n1: Boring\n2: Funny"
|
89
|
+
puts "Choose your feedback type\n\n1: Boring\n2: Funny\n"
|
80
90
|
end
|
81
91
|
|
82
92
|
|
83
93
|
def replay_prompt
|
84
|
-
puts "Press 'r' or 'restart' to play again\nPress 'q' to quit"
|
94
|
+
puts "Press 'r' or 'restart' to play again\nPress 'q' to quit\n"
|
85
95
|
end
|
86
96
|
|
87
97
|
def invalid_prompt
|
@@ -109,6 +119,10 @@ The word is #{word}
|
|
109
119
|
end
|
110
120
|
|
111
121
|
def game_instruction_prompt
|
112
|
-
puts
|
122
|
+
puts <<-PUTS
|
123
|
+
Press ':h' or 'history' to view the letters you have used
|
124
|
+
Press ':q' or 'quit' to quit (you can save before quiting)
|
125
|
+
|
126
|
+
PUTS
|
113
127
|
end
|
114
128
|
end
|
data/lib/femis_hangman/router.rb
CHANGED
@@ -11,12 +11,10 @@ module FemisHangman
|
|
11
11
|
elsif @status == 'feedback' then choose_feedback(input)
|
12
12
|
elsif @status == 'start' then begin_game(input)
|
13
13
|
elsif @status == 'play' then play_game(input)
|
14
|
-
elsif @status == 'finish' then
|
15
|
-
elsif @status == 'save' then save_game
|
14
|
+
elsif @status == 'finish' then restart_game(input)
|
16
15
|
elsif @status == 'load' then load_game(input)
|
17
|
-
elsif @status == 'quit' || '
|
18
|
-
else
|
19
|
-
welcome(input)
|
16
|
+
elsif @status == 'quit' || 'save' then quit_game(input)
|
17
|
+
else welcome(input)
|
20
18
|
end
|
21
19
|
end
|
22
20
|
|
@@ -30,24 +28,31 @@ module FemisHangman
|
|
30
28
|
end
|
31
29
|
end
|
32
30
|
|
31
|
+
def start_game
|
32
|
+
@status = 'feedback'
|
33
|
+
welcome_prompt
|
34
|
+
feedback_prompt
|
35
|
+
end
|
36
|
+
|
33
37
|
def choose_feedback(input)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
+
if input.to_i < 1 || input.to_i > 2
|
39
|
+
invalid_prompt
|
40
|
+
false
|
41
|
+
else
|
42
|
+
level_prompt
|
43
|
+
@feedback = input.to_i
|
44
|
+
@status = 'start'
|
38
45
|
end
|
39
|
-
level_prompt
|
40
|
-
@status = 'start'
|
41
46
|
end
|
42
47
|
|
43
48
|
def begin_game(input)
|
44
|
-
|
45
|
-
if @difficulty < 1 || @difficulty > 3
|
49
|
+
if input.to_i < 1 || input.to_i > 3
|
46
50
|
invalid_prompt
|
47
|
-
|
51
|
+
else
|
52
|
+
@difficulty = input.to_i
|
53
|
+
@status = 'play'
|
54
|
+
create_game
|
48
55
|
end
|
49
|
-
@status = 'play'
|
50
|
-
create_game
|
51
56
|
end
|
52
57
|
|
53
58
|
def create_game
|
@@ -61,45 +66,25 @@ module FemisHangman
|
|
61
66
|
|
62
67
|
def play_game(input)
|
63
68
|
if @game.status == 'restart'
|
64
|
-
|
65
|
-
level_prompt
|
66
|
-
@status = 'start'
|
67
|
-
elsif input == 'q' || input == 'quit'
|
68
|
-
quit_game
|
69
|
-
else invalid_prompt
|
70
|
-
end
|
69
|
+
restart_game(input)
|
71
70
|
elsif @game.status == 'quit'
|
72
|
-
|
73
|
-
elsif input == 'q' || 'quit' then quit_game
|
74
|
-
else
|
75
|
-
invalid_prompt
|
76
|
-
end
|
71
|
+
quit_game(input)
|
77
72
|
else @game.control(input)
|
78
73
|
end
|
79
74
|
end
|
80
75
|
|
81
|
-
def
|
82
|
-
|
83
|
-
|
84
|
-
feedback_prompt
|
85
|
-
end
|
86
|
-
|
87
|
-
def finish_game(input)
|
88
|
-
if input == 'r' || 'restart'
|
76
|
+
def restart_game(input)
|
77
|
+
if input == 'r' || input == 'restart'
|
78
|
+
level_prompt
|
89
79
|
@status = 'start'
|
90
|
-
|
91
|
-
|
92
|
-
save_prompt
|
93
|
-
@status = 'save'
|
94
|
-
else
|
95
|
-
invalid_prompt
|
80
|
+
elsif input == 'q' || input == 'quit' then quit_game
|
81
|
+
else invalid_prompt
|
96
82
|
end
|
97
83
|
end
|
98
84
|
|
99
85
|
def save_game
|
100
86
|
File.open('./saved_games.yaml', 'a'){|f| f.write(YAML.dump(@game))}
|
101
|
-
|
102
|
-
@status = 'end'
|
87
|
+
@status = 'quit'
|
103
88
|
end
|
104
89
|
|
105
90
|
def show_saved_games
|
@@ -108,37 +93,29 @@ module FemisHangman
|
|
108
93
|
i = 0
|
109
94
|
YAML.load_stream(File.open('./saved_games.yaml', 'r')).each do |game|
|
110
95
|
print "#{i += 1}: "
|
111
|
-
|
112
|
-
history = game.history
|
113
|
-
word.each do |letter|
|
114
|
-
if history.include?(letter)
|
115
|
-
print "#{letter} "
|
116
|
-
else
|
117
|
-
print '_ '
|
118
|
-
end
|
119
|
-
end
|
96
|
+
print game.show_word
|
120
97
|
print "(#{game.turns} turns left)"
|
121
98
|
print "\n"
|
122
99
|
end
|
123
100
|
end
|
124
101
|
|
125
102
|
def load_game(input)
|
126
|
-
game_id =
|
127
|
-
i = 0
|
103
|
+
game_id = 0
|
128
104
|
YAML.load_stream(File.open('./saved_games.yaml', 'r')).each do |game|
|
129
|
-
|
130
|
-
|
131
|
-
@status = 'play'
|
132
|
-
@game = game
|
133
|
-
@game.status = 'play'
|
134
|
-
@game.check_game
|
135
|
-
end
|
105
|
+
game_id += 1
|
106
|
+
@game = game
|
136
107
|
end
|
108
|
+
@status = 'play'
|
109
|
+
@game.status = 'play'
|
110
|
+
@game.check_game
|
137
111
|
end
|
138
112
|
|
139
|
-
def quit_game
|
140
|
-
@status = '
|
141
|
-
|
113
|
+
def quit_game(input=nil)
|
114
|
+
if input.nil? then @status = 'quit'
|
115
|
+
elsif input == 's' || 'save' then save_game
|
116
|
+
elsif input == 'q' || 'quit' then quit_game
|
117
|
+
else invalid_prompt
|
118
|
+
end
|
142
119
|
end
|
143
120
|
|
144
121
|
def loop
|
@@ -146,8 +123,8 @@ module FemisHangman
|
|
146
123
|
print prompt
|
147
124
|
process(gets.chomp!)
|
148
125
|
end
|
149
|
-
|
150
|
-
|
126
|
+
repl['% Hangman-0.1.0: '] while @status != 'quit'
|
127
|
+
thanks_prompt
|
151
128
|
end
|
152
129
|
end
|
153
130
|
end
|
data/lib/femis_hangman/word.rb
CHANGED
@@ -5,10 +5,8 @@ module FemisHangman
|
|
5
5
|
rand(41211).times { file.gets }
|
6
6
|
word = clean_word($_)
|
7
7
|
file.close
|
8
|
-
if confirm(difficulty, word)
|
9
|
-
|
10
|
-
else
|
11
|
-
generate(difficulty)
|
8
|
+
if confirm(difficulty, word) then word
|
9
|
+
else generate(difficulty)
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
@@ -21,7 +19,7 @@ module FemisHangman
|
|
21
19
|
end
|
22
20
|
|
23
21
|
def clean_word(word)
|
24
|
-
|
22
|
+
word.delete("\n")
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: femis_hangman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Femi Senjobi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|