femis_hangman 0.1.2 → 0.1.3

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
  SHA1:
3
- metadata.gz: bc8e5ebdddb0d51dc27b78de8a03aaba40033dd7
4
- data.tar.gz: 4871521fc341b6aa4821c2d7d5255f0cb6aff5fb
3
+ metadata.gz: 531848c0a7aa6549600ba6fa38341dc908e240cc
4
+ data.tar.gz: 0a746682ce33a6ae9cf95a1b866ddceed4526df8
5
5
  SHA512:
6
- metadata.gz: d89ba5e9f217569d4fc74bb733b1bfc0104c44c62ab52921316eefdfa9065540fe37b1721f971f3230a73ef4206b2492551b85cdd1510021ece1321441abf4e3
7
- data.tar.gz: 0627e01a7ee8570f13aafd2f45838248459cc7474f2525c0f5510c2bfccd64573472a441eea24fa3800baa2b26fc2f4414363d3cd7dfabbe1832c5dcad05728c
6
+ metadata.gz: 4e47e32b83b5fc1c55e4ea3116cd2faef6039bb6e08403df76000c3d36efa42036df090e09af25f7d7f03906c36668cab8833fabd094853894770c1dbcf0a6fc
7
+ data.tar.gz: bf324adbcb177cb19dbec1b196c729a6fd1e9e553e3310429ddecb7d55c584bb2ecf2b86de2e75b46401e40c1e6e0cb7adb0b2f5dcae17bdf17d33d045ee4502
data/.gitignore CHANGED
@@ -10,4 +10,5 @@
10
10
  /.idea/
11
11
  .idea*
12
12
  /.idea*
13
- .xml
13
+ .xml
14
+ /spec/message_spec.rb
data/Gemfile CHANGED
@@ -3,3 +3,4 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in femis_hangman.gemspec
4
4
  gem 'coveralls', require: false
5
5
  gemspec
6
+ gem "bundler"
@@ -3,5 +3,5 @@ require "bundler/setup"
3
3
  require "femis_hangman"
4
4
 
5
5
  s = FemisHangman::Router.new
6
- s.instructions_prompt
6
+ puts s.instructions_prompt
7
7
  s.loop
data/bin/resume CHANGED
@@ -4,10 +4,8 @@ require "femis_hangman"
4
4
 
5
5
  s = FemisHangman::Router.new
6
6
 
7
-
8
- if ARGV.length > 2
9
- session.invalid_prompt
10
- else
7
+ if ARGV.size == 1
11
8
  s.status = 'show'
12
- s.show_saved_games
9
+ s.load_game(ARGV[0].to_i)
10
+ s.loop
13
11
  end
File without changes
@@ -1,6 +1,6 @@
1
+ require 'YAML'
1
2
  require 'femis_hangman/version'
2
3
  require 'femis_hangman/message'
3
4
  require 'femis_hangman/word'
4
5
  require 'femis_hangman/game'
5
- require 'YAML'
6
6
  require 'femis_hangman/router'
@@ -15,15 +15,15 @@ module FemisHangman
15
15
  def control(input)
16
16
  if input.size > 1 then commands(input)
17
17
  elsif input.size == 1 then play(input)
18
- else invalid_prompt
18
+ else puts invalid_prompt
19
19
  end
20
20
  end
21
21
 
22
22
  def commands(input)
23
23
  case input
24
- when ':h', 'history' then print_text("You have used: #{game_history}")
24
+ when ':h', 'history' then puts ("You have used: #{game_history}")
25
25
  when ':q', 'quit' then quit_game
26
- else invalid_prompt
26
+ else puts invalid_prompt
27
27
  end
28
28
  end
29
29
 
@@ -35,7 +35,7 @@ module FemisHangman
35
35
 
36
36
  def include_letter(letter, history)
37
37
  if history.include?(letter)
38
- duplicate_prompt(letter)
38
+ puts duplicate_prompt(letter)
39
39
  @history
40
40
  else
41
41
  history << letter
@@ -47,7 +47,7 @@ module FemisHangman
47
47
  if won? then game_won
48
48
  elsif lost? then game_lost
49
49
  else
50
- turns_prompt(@turns)
50
+ puts turns_prompt(@turns)
51
51
  puts show_word
52
52
  end
53
53
  end
@@ -78,21 +78,21 @@ module FemisHangman
78
78
 
79
79
  def game_won
80
80
  if @feedback == 2
81
- won_gui(@word)
81
+ puts won_gui(@word)
82
82
  else
83
- won_prompt(@word)
83
+ puts won_prompt(@word)
84
84
  end
85
- replay_prompt
85
+ puts replay_prompt
86
86
  @status = 'restart'
87
87
  end
88
88
 
89
89
  def game_lost
90
90
  if @feedback == 2
91
- lost_gui(@word)
91
+ puts lost_gui(@word)
92
92
  else
93
- lost_prompt(@word)
93
+ puts lost_prompt(@word)
94
94
  end
95
- replay_prompt
95
+ puts replay_prompt
96
96
  @status = 'restart'
97
97
  end
98
98
 
@@ -108,7 +108,7 @@ module FemisHangman
108
108
 
109
109
  def quit_game
110
110
  @status = 'quit'
111
- save_prompt
111
+ puts save_prompt
112
112
  end
113
113
  end
114
114
  end
@@ -1,25 +1,24 @@
1
1
  module Message
2
2
  def welcome_prompt
3
- puts 'Welcome to Hangman. Guess right or get hanged!'
3
+ 'Welcome to Hangman. Guess right or get hanged!'
4
4
  end
5
5
 
6
6
  def size_prompt(size)
7
- puts "Your word is a #{size} letter word"
7
+ "Your word is a #{size} letter word"
8
8
  end
9
9
 
10
10
  def load_prompt
11
- puts "Choose the game you want to resume from the list below\nPress the respective number"
11
+ "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
15
- puts "Let the games begin\n\n"
15
+ "Let the games begin\n\n"
16
16
  end
17
17
 
18
18
  def instructions_prompt
19
- puts <<-PUTS
19
+ <<-PUTS
20
20
  ########################################################
21
21
 
22
- This gem is an implementation of the hangman game.
23
22
  Attempt to guess the missing letters correctly.
24
23
  You have a limited number of tries.
25
24
  If you use up all your chances without getting
@@ -27,7 +26,7 @@ the word correctly, you will be hanged.
27
26
 
28
27
  To play a new game: Press 'p' or 'play'
29
28
  To load a saved game: Press 'l' or 'load'
30
- To show insructions: Press 'i' or 'instructions'
29
+ To show instructions: Press 'i' or 'instructions'
31
30
  To quit Hangman: Press 'q' or 'quit'
32
31
 
33
32
  ########################################################
@@ -35,20 +34,19 @@ To quit Hangman: Press 'q' or 'quit'
35
34
  end
36
35
 
37
36
  def save_prompt
38
- puts "Press 's' or 'save' to save before quiting\nPress 'q' to quit anyway"
37
+ "Press 's' or 'save' to save before quiting\nPress 'q' to quit anyway"
39
38
  end
40
39
 
41
40
  def lost_prompt(word)
42
- puts "You are dead!\nThe word is #{word}"
43
- puts "Press any key to continue or 'q' to quit"
41
+ "You are dead!\nThe word is #{word}\nPress any key to continue or 'q' to quit"
44
42
  end
45
43
 
46
44
  def won_prompt(word)
47
- puts "You win!\nThe word is #{word}"
45
+ "You win!\nThe word is #{word}"
48
46
  end
49
47
 
50
48
  def lost_gui(word)
51
- puts <<-PUTS
49
+ <<-HEREDOC
52
50
  -+----------+-
53
51
  | |
54
52
  | o
@@ -61,11 +59,11 @@ You are dead!
61
59
  ################
62
60
  The word is #{word}
63
61
  ################
64
- PUTS
62
+ HEREDOC
65
63
  end
66
64
 
67
65
  def won_gui(word)
68
- puts <<-PUTS
66
+ <<-HEREDOC
69
67
  -+----------+-
70
68
  | |
71
69
  |
@@ -78,48 +76,60 @@ You are free to go
78
76
  ################
79
77
  The word is #{word}
80
78
  ################
81
- PUTS
79
+ HEREDOC
82
80
  end
83
81
 
84
82
  def level_prompt
85
- puts "Choose your difficulty level\n\n1: Beginner\n2: Intermediate\n3: Advanced\n"
83
+ "Choose your difficulty level\n\n1: Beginner\n2: Intermediate\n3: Advanced\n"
86
84
  end
87
85
 
88
86
  def feedback_prompt
89
- puts "Choose your feedback type\n\n1: Boring\n2: Funny\n"
87
+ "Choose your feedback type\n\n1: Boring\n2: Funny\n"
90
88
  end
91
89
 
92
90
 
93
91
  def replay_prompt
94
- puts "Press 'r' or 'restart' to play again\nPress 'q' to quit\n"
92
+ "Press 'r' or 'restart' to play again\nPress 'q' to quit\n"
95
93
  end
96
94
 
97
95
  def invalid_prompt
98
- puts 'Invalid entry!'
96
+ 'Invalid entry!'
99
97
  end
100
98
 
101
99
  def empty_prompt
102
- puts "You haven't used any letters yet."
100
+ "You haven't used any letters yet."
103
101
  end
104
102
 
105
103
  def duplicate_prompt(letter)
106
- puts "You have used the letter #{letter} already"
104
+ "You have used the letter #{letter} already"
107
105
  end
108
106
 
109
107
  def turns_prompt(turns)
110
- puts "You have #{turns} turns left"
108
+ "You have #{turns} turns left"
111
109
  end
112
110
 
113
111
  def print_text(text)
114
- puts "#{text}"
112
+ "#{text}"
115
113
  end
116
114
 
117
115
  def thanks_prompt
118
- puts 'Thank you for playing!'
116
+ 'Thank you for playing!'
119
117
  end
120
118
 
119
+ def invalid_game_prompt
120
+ 'There is no game with such ID'
121
+ end
122
+
123
+ # def help_prompt
124
+ # <<-HELP
125
+ # Press:
126
+ # hangman - to start the hangman game
127
+ # resume `game id` - to resume saved game
128
+ # HELP
129
+ # end
130
+
121
131
  def game_instruction_prompt
122
- puts <<-PUTS
132
+ <<-PUTS
123
133
  Press ':h' or 'history' to view the letters you have used
124
134
  Press ':q' or 'quit' to quit (you can save before quiting)
125
135
 
@@ -13,7 +13,7 @@ module FemisHangman
13
13
  elsif @status == 'play' then play_game(input)
14
14
  elsif @status == 'finish' then restart_game(input)
15
15
  elsif @status == 'load' then load_game(input)
16
- elsif @status == 'quit' || 'save' then quit_game(input)
16
+ elsif @status == 'quit' then quit_game(input)
17
17
  else welcome(input)
18
18
  end
19
19
  end
@@ -23,23 +23,23 @@ module FemisHangman
23
23
  when 'p', 'play' then start_game
24
24
  when 'q', 'quit' then quit_game
25
25
  when 'l', 'load' then show_saved_games
26
- when 'i', 'instructions' then instructions_prompt
27
- else invalid_prompt
26
+ when 'i', 'instructions' then puts instructions_prompt
27
+ else puts invalid_prompt
28
28
  end
29
29
  end
30
30
 
31
31
  def start_game
32
32
  @status = 'feedback'
33
- welcome_prompt
34
- feedback_prompt
33
+ puts welcome_prompt
34
+ puts feedback_prompt
35
35
  end
36
36
 
37
37
  def choose_feedback(input)
38
38
  if input.to_i < 1 || input.to_i > 2
39
- invalid_prompt
39
+ puts invalid_prompt
40
40
  false
41
41
  else
42
- level_prompt
42
+ puts level_prompt
43
43
  @feedback = input.to_i
44
44
  @status = 'start'
45
45
  end
@@ -47,7 +47,7 @@ module FemisHangman
47
47
 
48
48
  def begin_game(input)
49
49
  if input.to_i < 1 || input.to_i > 3
50
- invalid_prompt
50
+ puts invalid_prompt
51
51
  else
52
52
  @difficulty = input.to_i
53
53
  @status = 'play'
@@ -56,12 +56,12 @@ module FemisHangman
56
56
  end
57
57
 
58
58
  def create_game
59
- begin_prompt
59
+ puts begin_prompt
60
60
  @game = Game.new(@difficulty, @feedback)
61
- size_prompt(@game.word.size)
62
- turns_prompt(@game.turns)
63
- game_instruction_prompt
64
- print_text(@game.show_word)
61
+ puts size_prompt(@game.word.size)
62
+ puts turns_prompt(@game.turns)
63
+ puts game_instruction_prompt
64
+ puts (@game.show_word)
65
65
  end
66
66
 
67
67
  def play_game(input)
@@ -75,56 +75,65 @@ module FemisHangman
75
75
 
76
76
  def restart_game(input)
77
77
  if input == 'r' || input == 'restart'
78
- level_prompt
78
+ puts level_prompt
79
79
  @status = 'start'
80
80
  elsif input == 'q' || input == 'quit' then quit_game
81
81
  else invalid_prompt
82
82
  end
83
83
  end
84
84
 
85
- def save_game
86
- File.open('./saved_games.yaml', 'a'){|f| f.write(YAML.dump(@game))}
85
+ def save_game(file='./saved_games.yaml')
86
+ File.open(file, 'a'){|f| f.write(YAML.dump(@game))}
87
87
  @status = 'quit'
88
88
  end
89
89
 
90
90
  def show_saved_games
91
91
  @status = 'load'
92
- load_prompt
93
- i = 0
92
+ puts load_prompt
93
+ counter = 0
94
94
  YAML.load_stream(File.open('./saved_games.yaml', 'r')).each do |game|
95
- print "#{i += 1}: "
96
- print game.show_word
97
- print "(#{game.turns} turns left)"
98
- print "\n"
95
+ counter += 1
96
+ puts saved_games_list(counter, game)
99
97
  end
100
98
  end
101
99
 
100
+ def saved_games_list(counter, game)
101
+ "#{counter}: " << game.show_word << "(#{game.turns} turns left)"
102
+ end
103
+
102
104
  def load_game(input)
103
105
  game_id = 0
104
106
  YAML.load_stream(File.open('./saved_games.yaml', 'r')).each do |game|
105
107
  game_id += 1
106
- @game = game
108
+ if game_id == input.to_i then resume_game(game)
109
+ else
110
+ puts invalid_game_prompt
111
+ show_saved_games
112
+ end
107
113
  end
114
+ end
115
+
116
+ def resume_game(game)
117
+ @game = game
108
118
  @status = 'play'
109
119
  @game.status = 'play'
110
120
  @game.check_game
111
121
  end
112
122
 
113
123
  def quit_game(input=nil)
114
- if input.nil? then @status = 'quit'
124
+ if input.nil? || input == 'q' || 'quit' then @status = 'quit'
115
125
  elsif input == 's' || 'save' then save_game
116
- elsif input == 'q' || 'quit' then quit_game
117
- else invalid_prompt
126
+ else puts invalid_prompt
118
127
  end
119
128
  end
120
129
 
121
130
  def loop
122
131
  repl = lambda do |prompt|
123
132
  print prompt
124
- process(gets.chomp!)
133
+ process(STDIN.gets.chomp.downcase)
125
134
  end
126
135
  repl['% Hangman-0.1.0: '] while @status != 'quit'
127
- thanks_prompt
136
+ puts thanks_prompt
128
137
  end
129
138
  end
130
139
  end
@@ -1,3 +1,3 @@
1
1
  module FemisHangman
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -0,0 +1,140 @@
1
+ ---
2
+ ...
3
+ ---
4
+ ...
5
+ ---
6
+ ...
7
+ ---
8
+ ...
9
+ ---
10
+ ...
11
+ ---
12
+ ...
13
+ ---
14
+ ...
15
+ ---
16
+ ...
17
+ ---
18
+ ...
19
+ ---
20
+ ...
21
+ ---
22
+ ...
23
+ ---
24
+ ...
25
+ ---
26
+ ...
27
+ ---
28
+ ...
29
+ ---
30
+ ...
31
+ ---
32
+ ...
33
+ ---
34
+ ...
35
+ ---
36
+ ...
37
+ ---
38
+ ...
39
+ ---
40
+ ...
41
+ ---
42
+ ...
43
+ ---
44
+ ...
45
+ ---
46
+ ...
47
+ ---
48
+ ...
49
+ ---
50
+ ...
51
+ ---
52
+ ...
53
+ ---
54
+ ...
55
+ ---
56
+ ...
57
+ ---
58
+ ...
59
+ ---
60
+ ...
61
+ ---
62
+ ...
63
+ ---
64
+ ...
65
+ ---
66
+ ...
67
+ ---
68
+ ...
69
+ ---
70
+ ...
71
+ ---
72
+ ...
73
+ ---
74
+ ...
75
+ ---
76
+ ...
77
+ ---
78
+ ...
79
+ ---
80
+ ...
81
+ ---
82
+ ...
83
+ ---
84
+ ...
85
+ ---
86
+ ...
87
+ ---
88
+ ...
89
+ ---
90
+ ...
91
+ ---
92
+ ...
93
+ ---
94
+ ...
95
+ ---
96
+ ...
97
+ ---
98
+ ...
99
+ ---
100
+ ...
101
+ ---
102
+ ...
103
+ ---
104
+ ...
105
+ ---
106
+ ...
107
+ ---
108
+ ...
109
+ ---
110
+ ...
111
+ ---
112
+ ...
113
+ ---
114
+ ...
115
+ ---
116
+ ...
117
+ ---
118
+ ...
119
+ ---
120
+ ...
121
+ ---
122
+ ...
123
+ ---
124
+ ...
125
+ ---
126
+ ...
127
+ ---
128
+ ...
129
+ ---
130
+ ...
131
+ ---
132
+ ...
133
+ ---
134
+ ...
135
+ ---
136
+ ...
137
+ ---
138
+ ...
139
+ ---
140
+ ...
@@ -5,18 +5,6 @@ turns: 10
5
5
  feedback: 2
6
6
  status: quit
7
7
  --- !ruby/object:FemisHangman::Game
8
- word: fin-de-siecle
9
- history:
10
- - e
11
- - r
12
- - n
13
- - s
14
- - d
15
- - y
16
- turns: 7
17
- feedback: 2
18
- status: quit
19
- --- !ruby/object:FemisHangman::Game
20
8
  word: delegation
21
9
  history:
22
10
  - f
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.2
4
+ version: 0.1.3
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-26 00:00:00.000000000 Z
11
+ date: 2016-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -79,6 +79,7 @@ files:
79
79
  - bin/hangman
80
80
  - bin/resume
81
81
  - bin/setup
82
+ - circle.yml
82
83
  - dictionary.txt
83
84
  - femis_hangman.gemspec
84
85
  - lib/femis_hangman.rb
@@ -87,6 +88,7 @@ files:
87
88
  - lib/femis_hangman/router.rb
88
89
  - lib/femis_hangman/version.rb
89
90
  - lib/femis_hangman/word.rb
91
+ - save_test_games.yaml
90
92
  - saved_games.yaml
91
93
  homepage: https://github.com/andela-fsenjobi/femis_hangman
92
94
  licenses: