lib/femis_hangman/game.rb in femis_hangman-0.1.1 vs lib/femis_hangman/game.rb in femis_hangman-0.1.2
- old
+ new
@@ -11,16 +11,13 @@
@feedback = feedback
@status = 'play'
end
def control(input)
- if input.size > 1
- commands(input)
- elsif input.size == 1
- play(input)
- else
- invalid_prompt
+ if input.size > 1 then commands(input)
+ elsif input.size == 1 then play(input)
+ else invalid_prompt
end
end
def commands(input)
case input
@@ -37,16 +34,15 @@
end
def include_letter(letter, history)
if history.include?(letter)
duplicate_prompt(letter)
- false
+ @history
else
history << letter
@history = history
end
- @history
end
def check_game
if won? then game_won
elsif lost? then game_lost
@@ -55,30 +51,26 @@
puts show_word
end
end
def show_word
- word = @word.split('')
output = ''
- word.each do |letter|
+ @word.split('').each do |letter|
if @history.include?(letter)
output << "#{letter} "
else
output << '_ '
end
end
output
end
def won?
- word = @word.split('')
length = 0
- word.each {|val| length += 1 if @history.include?(val)}
- if length == word.size
- true
- else
- false
+ @word.split('').each {|val| length += 1 if @history.include?(val)}
+ if length == word.size then true
+ else false
end
end
def lost?
@turns == 0
@@ -103,13 +95,13 @@
replay_prompt
@status = 'restart'
end
def game_history
- output = ''
if @history.empty?
- ''
+ 'NO LETTER YET'
else
+ output = ''
@history.each {|letter| output << "#{letter} "}
end
output
end