Class: Pendu

Inherits:
Object
  • Object
show all
Defined in:
lib/pendu.rb

Instance Method Summary collapse

Instance Method Details

#startObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pendu.rb', line 4

def start
   starting_sentence = "Hola Loco"
   sentence_array = starting_sentence.split("").map(&:downcase)
   accurate_count = sentence_array - [" "]
   final_sentence = starting_sentence.gsub(/[a-zA-Z]/, '_').split("")

   p "Let's play !"

   while sentence_array.count("") < accurate_count.count
    puts "Guess a letter:"
    guess = gets.downcase.chomp
    if sentence_array.include?(guess)
       letter_index = sentence_array.find_index(guess)
       sentence_array[letter_index] = ""
       final_sentence[letter_index] = guess
       puts "Correct! The sentence is now: #{final_sentence.join}"
    else
       puts "The letter: #{guess} is not in the sentence. Try again !"
    end
   end
   puts Wording.congrats
end