forked from Ada-C6/Word-Guess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
guessing_game.rb
127 lines (108 loc) · 2.85 KB
/
guessing_game.rb
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
require 'colorize'
require_relative 'flower'
class GuessingGame
def initialize
@rand_answer = ["ZEBRA", "DIZZY", "JUMBO", "RHINOS", "KITTEN", "DRAGON"].sample
@answer = @rand_answer.chars
@num_wrong_guess = 0
@letter_art = Array.new(@rand_answer.length, "_")
@flower_art = Flower.new
@wrong_guesses = []
puts @flower_art.print_props(0)
puts " "
@letter_art.each do | i |
print i
end
puts " "
puts " "
end
def compare?
@answer.include?@guess
end
def ascii_art
if @num_wrong_guess == 0
puts @flower_art.print_props(0)
elsif @num_wrong_guess == 1
puts @flower_art.print_props(1)
elsif @num_wrong_guess == 2
puts @flower_art.print_props(2)
elsif @num_wrong_guess == 3
puts @flower_art.print_props(3)
elsif @num_wrong_guess == 4
puts @flower_art.print_props(4)
else
puts @flower_art.print_props(5)
end
end
def letter_art_change
num_of_letters = @answer.length
num_of_letters.times do |i|
if @guess == @answer[i]
@letter_art[i] = @answer[i]
else
i += 1
end
end
end
def check_progress?
@letter_art.include?"_"
end
def game_over?
if check_progress? == false
puts " "
puts "Congrats you won!".colorize(:green)
puts " "
exit
elsif @num_wrong_guess == 5
puts " "
puts "You Lost.".colorize(:red)
puts "The correct word was: " + @rand_answer.colorize(:red)
puts " "
exit
else
method
end
end
def special_character?
@guess.include?("!")||@guess.include?("?")||@guess.include?(",")||@guess.include?(".")||@guess.include?(",")||@guess.include?("#")||@guess.include?(":")||@guess.include?(";")||@guess.include?("&")
end
def method #to ask user
puts " "
puts "Guess a letter!"
@guess = gets.chomp.to_s.upcase
if special_character? == true
puts "Your guess should only contain a letter!"
else
if @wrong_guesses.include? @guess
puts "You've already guessed that."
else
if compare? == true
#ascii_art (doesnt change stays the same for num_wrong_guess)
ascii_art
letter_art_change
@letter_art.each do | i |
print i
end
puts " "
puts " "
puts "Yay! That is a correct letter."
else
#ascii_art (changes corresponds to num_wrong_guess, looses flowers)
@num_wrong_guess += 1
ascii_art
@letter_art.each do | i |
print i
end
@wrong_guesses << @guess
puts " "
puts " "
puts "Sorry! That letter is wrong. You lost a flower."
puts "Here are your wrong guesses so far: " + @wrong_guesses.to_s
end
end
end
game_over?
end
end
g = GuessingGame.new
g.method