added the word scrambler and printer
This commit is contained in:
parent
8c74032a3d
commit
66a7e236a8
30
hangman.rb
30
hangman.rb
@ -23,3 +23,33 @@ until word.length.between?(5, 12)
|
|||||||
end
|
end
|
||||||
|
|
||||||
puts "Your word is #{word}"
|
puts "Your word is #{word}"
|
||||||
|
|
||||||
|
#turn word into an array
|
||||||
|
#hide 50% of letters randomly
|
||||||
|
#ask user to guess letters
|
||||||
|
#have two arrays, word and hidden word
|
||||||
|
#display hidden word
|
||||||
|
#if input is included in word but not hidden word then
|
||||||
|
#if word[x] == input then hidden[x] == input
|
||||||
|
#do this over the array
|
||||||
|
#if guess == a hidden letter
|
||||||
|
# fill in that letter
|
||||||
|
#else
|
||||||
|
# increase hangman counter
|
||||||
|
|
||||||
|
def scramble_word(word)
|
||||||
|
scrambled_word = Array.new
|
||||||
|
word.length.times do |i|
|
||||||
|
if rand(0..1) == 0 #do this 50% of the time
|
||||||
|
scrambled_word.push("_")
|
||||||
|
else
|
||||||
|
scrambled_word.push(word[i])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return scrambled_word
|
||||||
|
end
|
||||||
|
|
||||||
|
scrambled_word = scramble_word(word)
|
||||||
|
#puts the array as a readable string
|
||||||
|
puts scrambled_word.inspect[1...-1].gsub('"',"").gsub(',','')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user