forked from CheerOnMars/Word-Guess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathword-guess-1.rb
142 lines (115 loc) Β· 3.92 KB
/
word-guess-1.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#Word Guess Game - Sara Stiltner and Lily Sky
#ADA c9
#Week 2
#Pair Programming exercise
#============ GEMS ========
require "colorize"
require "colorized_string"
require "awesome_print"
#============ CLASS ========
class Word
attr_reader :word, :word_array
attr_writer :letter
attr_accessor :working_word, :word_length
def initialize(word)
@word = word
end
def word_length
@word.length
end
def word_to_array
word_array = @word.chars
return word_array
end
def working_word
working_word = []
@word.length.times do |i|
working_word << "_ "
end
return working_word
end
end
#============ STORAGE ========
library = ["LOVE", 'CUPID', "HEART", "ROSES", "GALENTINE", "ROMANCE", "HYGGE", "SECURITY", "SWEETHEART", "INSURANCE", "CHOCOLATE", "ATTENTION", "FLOWERS", "ADORATION", "AFFECTION", "HONEY", "DINNER", "DRAMA", "DELUSION", "SOULMATE", "PANCAKES", "COURT", "CRUSH", "SWEETHEART", "CONSENT"]
heart = [ " .:::. .:::. ".colorize(:red), " :::::::.::::::: ".colorize(:red), " ::::::::::::::: ".colorize(:red), " '::::::::::::' ".colorize(:red), " ':::::::' ".colorize(:red), " ':' ".colorize(:red)]
#============ PLAY GAME ========
word = library.sample
problem = Word.new(word)
working_word_game = problem.working_word
word_array = problem.word_to_array
counter = 6 #set to lines in heart
guesses = [] #bin for wrong guesses
puts "\n========== π Welcome to Valentine's Word Guess Game π =========="
puts "\nMission:"
puts "\n β§" + " Your aim is to guess the #{word.length }-letter word by guessing letters.".colorize(:blue)
puts "\nRules:"
puts "\n β§ You have #{counter} lives."
puts "\n β§ If your entries are wrong, the heart will disapear and you will die!"
puts "\n- - - - - - - - - - - - - - PLAY GAME - - - - - - - - - - - - - -"
36.times do
puts
puts heart[0..counter-1] #heart sinks as you do worse in the game
puts "+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +"
#get and hold user input to play game
print "\nπ Guess a letter or try for the word β’ "
input = gets.chomp.upcase.to_s
#option to enter word or letter and consequences for each
if input.length > 1 && input == word
puts "\n π π π π π β€οΈ Correct! Hooray, you won! β€οΈ π π π π π"
puts
exit
elsif input.length > 1 && input != word
if counter >= 1
counter -= 1
puts "\n π Heartbreak! You are incorrect."
elsif counter == 0
puts "\n π You die, love lostπ "
puts "\n In lieu of a puppy, here is the word: " + word
puts
exit
end
else
until input =~ /^[A-Z]{1}$/i && guesses.include?(input) == false
print "Guess a valid letter: "
input = gets.chomp.upcase.to_s
end
if word_array.include?(input) == false
guesses.push(input)
counter -= 1
puts "\n #{input} not included!".colorize(:green,)
else
word.length.times do |i|
if input == word_array[i]
working_word_game[i] = "#{input} "
end
end
end
end
#continutaion of consequences to end game and offer feedback
if word_array.include?(input) == false && counter == 0
puts "\n π Love lost, you lost π "
puts "\n In lieu of a puppy, here is the word: " + word
puts
exit
elsif working_word_game.include?("_ ") == false
puts "\n π π π π π β€οΈ Hooray, you won! β€οΈ π π π π π"
puts
exit
elsif word_array.include?(input) == true
puts "\n Great job! #{input} is included!".colorize(:magenta)
end
#output to display lives left
puts "\n Lives left: " + counter.to_s
#output to display bin of letters already tried
print " This is your bin: "
guesses.each do |input|
print "#{input} "
end
puts
#output to display current progress with working word
print " Current progress: "
working_word_game.each do |input|
print "#{input} "
end
puts
end