added word choosing method
This commit is contained in:
parent
cfccae02cd
commit
8c74032a3d
22
hangman.rb
22
hangman.rb
@ -4,8 +4,22 @@
|
|||||||
#load in dictionary file
|
#load in dictionary file
|
||||||
#select random word between 5 and 12 letters long
|
#select random word between 5 and 12 letters long
|
||||||
a = Array.new
|
a = Array.new
|
||||||
dictionary = File.open('5desk.txt')
|
|
||||||
dictionary.each do |row|
|
def pick_word(a)
|
||||||
a.push(row)
|
rand_int = rand(0..a.size)
|
||||||
puts row
|
return a[rand_int].chop!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#loading file into an array
|
||||||
|
dict = File.open('5desk.txt')
|
||||||
|
dict.each do |row|
|
||||||
|
a.push(row)
|
||||||
|
end
|
||||||
|
|
||||||
|
#picking a word between 5 and 12 characters long
|
||||||
|
word = pick_word(a)
|
||||||
|
until word.length.between?(5, 12)
|
||||||
|
word = pick_word(a)
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "Your word is #{word}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user