Skip to content

Instantly share code, notes, and snippets.

@livmaria7891
Created August 18, 2016 22:27
Show Gist options
  • Save livmaria7891/623b3c03b943d9674e9cfe43c370e886 to your computer and use it in GitHub Desktop.
Save livmaria7891/623b3c03b943d9674e9cfe43c370e886 to your computer and use it in GitHub Desktop.
For Nkiru
class Game
attr_accessor :word
def initialize(word)
@wrong_guesses = 0 #counter down
@total_guesses = 0 #counter
@word = word.upcase.split("")
@correct_guesses = 0 #compare to word.length
##__________Creates array of all blanks to put in user output
@show_user = []
i = 0
while i < @word.length
@show_user.push("_ ")
i += 1
end
puts "Can you guess this word??"
puts @show_user.join
end
#____________ASKS USER FOR A GUESS
def collect_guesses
until @wrong_guesses == 6 || @word == @show_user
print "Guess a letter:"
@guess = gets.chomp.upcase!
test_guess(@guess)
end
end
#____________TESTS IF GUESS MATCHES A WORD, KEEPS COUNT OF RIGHT AND WRONG GUESSES
def test_guess(guess)
if @word.include?(guess)
puts "Great! #{guess} is a match!"
@correct_guesses += 1
array
else
puts "Nope"
@wrong_guesses += 1
build_picture
end
@total_guesses += 1
puts @show_user.join
end
def array
@word.length.times do |i|
if @guess == @word[i]
@show_user[i] = @guess
end
end
end
def build_picture
end
end
test = Game.new("apple")
test.collect_guesses
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment