forked from Ada-C6/Word-Guess
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguess.rb
More file actions
53 lines (46 loc) · 1.15 KB
/
Copy pathguess.rb
File metadata and controls
53 lines (46 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require_relative 'art'
class Guess
attr_accessor :guessing_right, :guessing_wrong, :check, :wrong_guess_counter, :wrong_guess_array, :right_guess_array, :word_letter_array
def initialize(word)
@wrong_guess_array = []
@right_guess_array = []
@word_letter_array = []
word.chars.each do |char|
@word_letter_array << char
end
@wrong_guess_counter = 0
@art = Art.new
@word = word
end
def guessing_right
@check
@art.bad_guess(@wrong_guess_counter)
end
def guessing_wrong
@wrong_guess_counter += 1
@check
@art.bad_guess(@wrong_guess_counter)
end
def win?
@right_guess_array == @word_letter_array
end
def lose?
@wrong_guess_counter == 5 # NO IFs HERE :)
end
def check
if lose? == true
puts "\nYou've guessed too many times without getting the word. Village dead."
puts @art.lose_art
exit
elsif win? == true
@right_guess_array.each do |i|
print "#{i.upcase} "
end
puts "\nYou win! The correct word was \"#{@word}\"!"
puts @art.win_art
exit
else
puts "\nKeep going!\n"
end
end
end #end of class Guess