From a25aa260e6554d656285790dca77ddaaa3193071 Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Thu, 17 Aug 2017 14:15:33 -0700 Subject: [PATCH 01/20] Initial upload --- mywordguess.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 mywordguess.rb diff --git a/mywordguess.rb b/mywordguess.rb new file mode 100644 index 0000000..e69de29 From 31d1c7ca407e843b453d4d371b0b15273ab65c17 Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Thu, 17 Aug 2017 14:19:48 -0700 Subject: [PATCH 02/20] learning git --- mywordguess.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/mywordguess.rb b/mywordguess.rb index e69de29..21ff5aa 100644 --- a/mywordguess.rb +++ b/mywordguess.rb @@ -0,0 +1 @@ +some change From 12393a0b52a0588d0af45ab6199fcda1b17c1085 Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Thu, 17 Aug 2017 15:07:11 -0700 Subject: [PATCH 03/20] method for underscores to appear in array works --- mywordguess.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/mywordguess.rb b/mywordguess.rb index 21ff5aa..7f2298c 100644 --- a/mywordguess.rb +++ b/mywordguess.rb @@ -1 +1,19 @@ -some change +class Word + attr_accessor :random_word + def initialize (random_word) + @random_word = random_word + end + + def word_display + word_display = [] + random_word.length.times do + # i.gsub("i", "_") + word_display.push "_" + end + return word_display + end + +end + +tanja = Word.new("Tanja") +print tanja.word_display From 5758c3ec7f4dc047e9bcab5d4841a11052ba3123 Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Thu, 17 Aug 2017 15:49:17 -0700 Subject: [PATCH 04/20] adding reveal method but have to figure out how to scan each index --- mywordguess.rb | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/mywordguess.rb b/mywordguess.rb index 7f2298c..8208f99 100644 --- a/mywordguess.rb +++ b/mywordguess.rb @@ -1,7 +1,7 @@ class Word attr_accessor :random_word def initialize (random_word) - @random_word = random_word + @random_word = random_word.split("") end def word_display @@ -13,7 +13,23 @@ def word_display return word_display end + def reveal(letter) + if @random_word.include?(letter) + @random_word.each do |i| + if i == letter + word_display[i] = letter + end + end + end + return word_display + end + end -tanja = Word.new("Tanja") -print tanja.word_display +# tanja = Word.new("Tanja") +# print tanja.word_display + + + +gale = Word.new("Gale") +print gale.reveal("a") From 55b845c60ba425d490f2fea302a4dc53560e7ea9 Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Thu, 17 Aug 2017 17:06:32 -0700 Subject: [PATCH 05/20] Figured out how to replace element of the array from underscore to letter provided, otherwise leave as is --- mywordguess.rb | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/mywordguess.rb b/mywordguess.rb index 8208f99..42ee942 100644 --- a/mywordguess.rb +++ b/mywordguess.rb @@ -1,35 +1,42 @@ class Word - attr_accessor :random_word + attr_accessor :random_word, :word_display def initialize (random_word) @random_word = random_word.split("") + @word_display = word_display end def word_display - word_display = [] + @word_display = [] random_word.length.times do # i.gsub("i", "_") - word_display.push "_" + @word_display.push " _ " end - return word_display + return @word_display end def reveal(letter) - if @random_word.include?(letter) - @random_word.each do |i| - if i == letter - word_display[i] = letter - end + counter = 0 + @random_word.each do |alpha| + if alpha == letter + @word_display[counter] = letter end + counter += 1 end - return word_display + return @word_display end - end # tanja = Word.new("Tanja") # print tanja.word_display +# letters = ["G", "a", "l", "e"] + +# numbers = ["_ ", "_ ", "_ ", "_ "] + +# letter = "a" + gale = Word.new("Gale") -print gale.reveal("a") +print gale.reveal("y") +print gale.reveal("y").join From 86686bf0a2b426ca6f4f429551c5a80d9e5fd023 Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Thu, 17 Aug 2017 17:31:45 -0700 Subject: [PATCH 06/20] add def reveal and it works and replaces --- mywordguess.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mywordguess.rb b/mywordguess.rb index 42ee942..818bac7 100644 --- a/mywordguess.rb +++ b/mywordguess.rb @@ -37,6 +37,9 @@ def reveal(letter) -gale = Word.new("Gale") -print gale.reveal("y") -print gale.reveal("y").join +gale = Word.new("foobarfoo") +print gale.reveal("o") +print gale.reveal("f") + + +print gale.word_display From 95cc3e4bc688464cc3cf410da75c0da7e5f2926f Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Thu, 17 Aug 2017 18:45:57 -0700 Subject: [PATCH 07/20] added game class that needs work --- mywordguess.rb | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/mywordguess.rb b/mywordguess.rb index 818bac7..dbc648b 100644 --- a/mywordguess.rb +++ b/mywordguess.rb @@ -26,6 +26,35 @@ def reveal(letter) end end +class Game + attr_accessor :random_word + def initialize + @win = false + @guesses_taken = 0 + @guesses_allowed = 5 #random_word.length , does it need to be an argument in initialize? + + #when guesses_taken > guesses_allowed game over + #or + #when guesses_taken == guesses_allowed && word_display.includes? " _ " game over + #when guesses_taken == guesses_allowed && random_word != word_display game over + end + + def play + word = Word.new("faker") + while @win == false + @guesses_allowed.times do + puts "Please guess the letter" + guess = gets.chomp.downcase + word.reveal(guess) # + @guesses_taken += 1 + if @random_word == @word_display #is not comparing + @win = true + puts "Congrats!" + end + end + end + end +end # tanja = Word.new("Tanja") # print tanja.word_display @@ -35,11 +64,14 @@ def reveal(letter) # letter = "a" +puts "welcome to the game" +word = Game.new.play -gale = Word.new("foobarfoo") -print gale.reveal("o") -print gale.reveal("f") +# gale = Word.new("foobarfoo") +# print gale.reveal() +# print gale.reveal("f") -print gale.word_display +# +# print gale.word_display From 4f7fd93f38fa1dcdd1d132176a7fcbc9ff2eaa5b Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Fri, 18 Aug 2017 15:24:26 -0700 Subject: [PATCH 08/20] reworked bad guesses added more functionality --- mywordguess.rb | 80 ++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 45 deletions(-) diff --git a/mywordguess.rb b/mywordguess.rb index dbc648b..d7bdd17 100644 --- a/mywordguess.rb +++ b/mywordguess.rb @@ -1,77 +1,67 @@ class Word - attr_accessor :random_word, :word_display + attr_accessor :random_word, :word_display, :num_bad_guess def initialize (random_word) @random_word = random_word.split("") - @word_display = word_display + @word_display = Array.new(random_word.length, "_ ") + @num_bad_guess = 0 end - def word_display - @word_display = [] - random_word.length.times do - # i.gsub("i", "_") - @word_display.push " _ " - end - return @word_display - end - - def reveal(letter) + def reveal(letter) counter = 0 + @changed = nil @random_word.each do |alpha| if alpha == letter @word_display[counter] = letter + @changed = true end counter += 1 end return @word_display end + + def count_bad_guess + if @changed == nil + @num_bad_guess += 1 + print "You have made #{@num_bad_guess} wrong guess(es)." + end + return @num_bad_guess + end + end class Game - attr_accessor :random_word + attr_accessor :random_word, :word_display, :num_bad_guess def initialize - @win = false - @guesses_taken = 0 - @guesses_allowed = 5 #random_word.length , does it need to be an argument in initialize? - #when guesses_taken > guesses_allowed game over + + #when guesses_taken > guesses_allowed game over #or #when guesses_taken == guesses_allowed && word_display.includes? " _ " game over #when guesses_taken == guesses_allowed && random_word != word_display game over end - def play + + def play word = Word.new("faker") - while @win == false - @guesses_allowed.times do - puts "Please guess the letter" - guess = gets.chomp.downcase - word.reveal(guess) # - @guesses_taken += 1 - if @random_word == @word_display #is not comparing - @win = true - puts "Congrats!" - end + @bad_guess_allowed = word.random_word.length + 3 + while true + print "\nLetter guess: " + guess = gets.chomp.downcase + print word.reveal(guess).join + @num_bad_guess = word.count_bad_guess + print @num_bad_guess + if word.random_word == word.word_display #check for the 'win condition' + puts "\nCongrats!" + break + end + if @num_bad_guess == @bad_guess_allowed #if this happens the 'win condition', you lost :disappointed: + puts "\nSorry, you're out of guesses!" + break end end end end -# tanja = Word.new("Tanja") -# print tanja.word_display - -# letters = ["G", "a", "l", "e"] - -# numbers = ["_ ", "_ ", "_ ", "_ "] -# letter = "a" - -puts "welcome to the game" +puts "Welcome to Word Guess!" word = Game.new.play - - -# gale = Word.new("foobarfoo") -# print gale.reveal() -# print gale.reveal("f") - -# -# print gale.word_display From 1ca84853e68732f70f229ab6da8348841658dbaa Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Fri, 18 Aug 2017 15:51:44 -0700 Subject: [PATCH 09/20] small change in string --- mywordguess.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mywordguess.rb b/mywordguess.rb index d7bdd17..5223ae6 100644 --- a/mywordguess.rb +++ b/mywordguess.rb @@ -2,17 +2,17 @@ class Word attr_accessor :random_word, :word_display, :num_bad_guess def initialize (random_word) @random_word = random_word.split("") - @word_display = Array.new(random_word.length, "_ ") - @num_bad_guess = 0 + @word_display = Array.new(random_word.length, "_ ") #make array of underscores + @num_bad_guess = 0 #had to give it initial val so that we cound increment it with count bad guess method end def reveal(letter) - counter = 0 + counter = 0 # keeps track of random word index number @changed = nil @random_word.each do |alpha| if alpha == letter @word_display[counter] = letter - @changed = true + @changed = true # indicates that guess was right end counter += 1 end @@ -20,11 +20,11 @@ def reveal(letter) end def count_bad_guess - if @changed == nil - @num_bad_guess += 1 - print "You have made #{@num_bad_guess} wrong guess(es)." + if @changed == nil #checks to see if guess was wrong + @num_bad_guess += 1 # if guess is wrong increments bad guess otherwise gives "free" guess + print "You have made #{@num_bad_guess} bad guesses which include ()." #prints to user how many bad guesses they took end - return @num_bad_guess + return @num_bad_guess #otherwise method returns nil end end From 4709c9cefee7852c1a7f99f2a44f19781ea244c9 Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Fri, 18 Aug 2017 16:49:14 -0700 Subject: [PATCH 10/20] bad letter added --- mywordguess.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mywordguess.rb b/mywordguess.rb index 5223ae6..36c7bb3 100644 --- a/mywordguess.rb +++ b/mywordguess.rb @@ -4,6 +4,7 @@ def initialize (random_word) @random_word = random_word.split("") @word_display = Array.new(random_word.length, "_ ") #make array of underscores @num_bad_guess = 0 #had to give it initial val so that we cound increment it with count bad guess method + @bad_letters = [] end def reveal(letter) @@ -13,6 +14,8 @@ def reveal(letter) if alpha == letter @word_display[counter] = letter @changed = true # indicates that guess was right + else + @bad_letter << letter end counter += 1 end @@ -22,7 +25,7 @@ def reveal(letter) def count_bad_guess if @changed == nil #checks to see if guess was wrong @num_bad_guess += 1 # if guess is wrong increments bad guess otherwise gives "free" guess - print "You have made #{@num_bad_guess} bad guesses which include ()." #prints to user how many bad guesses they took + print "You have made #{@num_bad_guess} bad guesses which include #{@bad_letter.join("")}." #prints to user how many bad guesses they took end return @num_bad_guess #otherwise method returns nil end From c57c9859d249fe1a072e41a54aca17c39c069f85 Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Fri, 18 Aug 2017 16:56:37 -0700 Subject: [PATCH 11/20] displays wrong letters --- mywordguess.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mywordguess.rb b/mywordguess.rb index 36c7bb3..67f4ada 100644 --- a/mywordguess.rb +++ b/mywordguess.rb @@ -1,5 +1,5 @@ class Word - attr_accessor :random_word, :word_display, :num_bad_guess + attr_accessor :random_word, :word_display, :num_bad_guess, :bad_letters, :letter def initialize (random_word) @random_word = random_word.split("") @word_display = Array.new(random_word.length, "_ ") #make array of underscores @@ -8,14 +8,13 @@ def initialize (random_word) end def reveal(letter) + @letter = letter counter = 0 # keeps track of random word index number @changed = nil @random_word.each do |alpha| - if alpha == letter - @word_display[counter] = letter + if alpha == @letter + @word_display[counter] = @letter @changed = true # indicates that guess was right - else - @bad_letter << letter end counter += 1 end @@ -25,7 +24,8 @@ def reveal(letter) def count_bad_guess if @changed == nil #checks to see if guess was wrong @num_bad_guess += 1 # if guess is wrong increments bad guess otherwise gives "free" guess - print "You have made #{@num_bad_guess} bad guesses which include #{@bad_letter.join("")}." #prints to user how many bad guesses they took + @bad_letters << @letter + print "You have made #{@num_bad_guess} bad guesses which include #{@bad_letters.join(",")}." #prints to user how many bad guesses they took end return @num_bad_guess #otherwise method returns nil end @@ -33,7 +33,7 @@ def count_bad_guess end class Game - attr_accessor :random_word, :word_display, :num_bad_guess + attr_accessor :random_word, :word_display, :num_bad_guess, :bad_letters, :letter def initialize From 45a11774c6f575d6437e688953f05eef8e299dcf Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Sat, 19 Aug 2017 09:10:27 -0700 Subject: [PATCH 12/20] added faker --- mywordguess.rb | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/mywordguess.rb b/mywordguess.rb index 67f4ada..0b13de4 100644 --- a/mywordguess.rb +++ b/mywordguess.rb @@ -1,3 +1,9 @@ +require 'faker' +require 'colorize' +require 'artii' + + + class Word attr_accessor :random_word, :word_display, :num_bad_guess, :bad_letters, :letter def initialize (random_word) @@ -7,8 +13,8 @@ def initialize (random_word) @bad_letters = [] end - def reveal(letter) - @letter = letter + def reveal(letter) + @letter = letter counter = 0 # keeps track of random word index number @changed = nil @random_word.each do |alpha| @@ -22,12 +28,15 @@ def reveal(letter) end def count_bad_guess - if @changed == nil #checks to see if guess was wrong - @num_bad_guess += 1 # if guess is wrong increments bad guess otherwise gives "free" guess - @bad_letters << @letter - print "You have made #{@num_bad_guess} bad guesses which include #{@bad_letters.join(",")}." #prints to user how many bad guesses they took + unless @letter == @random_word.join("") + if @changed == nil #checks to see if guess was wrong + @num_bad_guess += 1 # if guess is wrong increments bad guess otherwise gives "free" guess + @bad_letters << @letter + puts "\nNumber of failed guesses: #{@num_bad_guess}" + puts "Letters you have guessed: #{@bad_letters.join(", ")}." #prints to user how many bad guesses they took + end + return @num_bad_guess #otherwise method returns nil end - return @num_bad_guess #otherwise method returns nil end end @@ -37,28 +46,30 @@ class Game def initialize - #when guesses_taken > guesses_allowed game over + #when guesses_taken > guesses_allowed game over #or #when guesses_taken == guesses_allowed && word_display.includes? " _ " game over #when guesses_taken == guesses_allowed && random_word != word_display game over end - def play - word = Word.new("faker") + def play + word = Word.new(Faker::Hipster.unique.word.downcase) @bad_guess_allowed = word.random_word.length + 3 + while true print "\nLetter guess: " guess = gets.chomp.downcase print word.reveal(guess).join @num_bad_guess = word.count_bad_guess - print @num_bad_guess - if word.random_word == word.word_display #check for the 'win condition' + + if word.random_word == word.word_display || guess == word.random_word.join("") + #check for the 'win condition' puts "\nCongrats!" break end if @num_bad_guess == @bad_guess_allowed #if this happens the 'win condition', you lost :disappointed: - puts "\nSorry, you're out of guesses!" + puts "\nSorry, you're out of guesses! The word was #{word.random_word.join("")}. Rad." break end end From f8b56666f10ad64fb0c17c3faebece2c876509f6 Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Sat, 19 Aug 2017 10:41:17 -0700 Subject: [PATCH 13/20] hipster complete --- mywordguess.rb | 191 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 183 insertions(+), 8 deletions(-) diff --git a/mywordguess.rb b/mywordguess.rb index 0b13de4..d1432e5 100644 --- a/mywordguess.rb +++ b/mywordguess.rb @@ -5,11 +5,12 @@ class Word - attr_accessor :random_word, :word_display, :num_bad_guess, :bad_letters, :letter + attr_accessor :random_word, :word_display, :num_bad_guess, :bad_letters, :letter, :num_good_guess def initialize (random_word) @random_word = random_word.split("") @word_display = Array.new(random_word.length, "_ ") #make array of underscores @num_bad_guess = 0 #had to give it initial val so that we cound increment it with count bad guess method + @num_good_guess = 0 @bad_letters = [] end @@ -39,10 +40,152 @@ def count_bad_guess end end + def count_good_guess + if @changed == true + @num_good_guess += 1 + end + return @num_good_guess + end +end + +class Art + attr_accessor :num_good_guess, :part1, :part2, :part3, :part4, :part5, :part6, :part7 + def initialize + @part1 = "        ....                                ....             + ... . . .........    .. .    .. .  ......... .. . .          + MMMMMMMMM8I~....:~7DMMMMMMMMMDDMMMMMMMMM$+~~~~~IOMMMMMMMMMM. + MMMMM=.              ...MMMMMMMMMMN..           . .  MMMMMM. " + @part2 = "        ....                                ....             + ... . . .........    .. .    .. .  ......... .. . .          + MMMMMMMMM8I~....:~7DMMMMMMMMMDDMMMMMMMMM$+~~~~~IOMMMMMMMMMM. + MMMMM=.              ...MMMMMMMMMMN..           . .  MMMMMM. + .MMMM                    DMMMMMMM7                    MMMM~  +   MMN                   .~MM .:MM                   ..MMM    +   .MM                   .IM?...NM.                  ..MM .   +    :M                   .MM.  ..M8                  .,M.     " + @part3 = "        ....                                ....             + ... . . .........    .. .    .. .  ......... .. . .          + MMMMMMMMM8I~....:~7DMMMMMMMMMDDMMMMMMMMM$+~~~~~IOMMMMMMMMMM. + MMMMM=.              ...MMMMMMMMMMN..           . .  MMMMMM. + .MMMM                    DMMMMMMM7                    MMMM~  +   MMN                   .~MM .:MM                   ..MMM    +   .MM                   .IM?...NM.                  ..MM .   +    :M                   .MM.  ..M8                  .,M.     + MM..                .M,.  . 8M..                .MM.     +     .M$.               ,MZ..    .MM.              ..OM..     +       MM....    ......,M?.        MM....    .......MM        +        8MM+.........MMM. .          MM?...  .....MM8..       " + @part4 = "        ....                                ....             + ... . . .........    .. .    .. .  ......... .. . .          + MMMMMMMMM8I~....:~7DMMMMMMMMMDDMMMMMMMMM$+~~~~~IOMMMMMMMMMM. + MMMMM=.              ...MMMMMMMMMMN..           . .  MMMMMM. + .MMMM                    DMMMMMMM7                    MMMM~  +   MMN                   .~MM .:MM                   ..MMM    +   .MM                   .IM?...NM.                  ..MM .   +    :M                   .MM.  ..M8                  .,M.     + MM..                .M,.  . 8M..                .MM.     +     .M$.               ,MZ..    .MM.              ..OM..     +       MM....    ......,M?.        MM....    .......MM        +        8MM+.........MMM. .          MM?...  .....MM8..       + ...ZMMMMN$.....            ...?MMMMMMM=....         +                                                              +                     .   ..   ...  .  .                       +                      MMMMMMM  .MMMMMMM                       " + @part5 = "        ....                                ....             + ... . . .........    .. .    .. .  ......... .. . .          + MMMMMMMMM8I~....:~7DMMMMMMMMMDDMMMMMMMMM$+~~~~~IOMMMMMMMMMM. + MMMMM=.              ...MMMMMMMMMMN..           . .  MMMMMM. + .MMMM                    DMMMMMMM7                    MMMM~  +   MMN                   .~MM .:MM                   ..MMM    +   .MM                   .IM?...NM.                  ..MM .   +    :M                   .MM.  ..M8                  .,M.     + MM..                .M,.  . 8M..                .MM.     +     .M$.               ,MZ..    .MM.              ..OM..     +       MM....    ......,M?.        MM....    .......MM        +        8MM+.........MMM. .          MM?...  .....MM8..       + ...ZMMMMN$.....            ...?MMMMMMM=....         +                                                              +                     .   ..   ...  .  .                       +                      MMMMMMM  .MMMMMMM                            + ....       MMMMMMMMMMMMMMMMMMMMM        ....         +       MM..?.  ..,MMMMMMMMMMMMMMMMMMMMMMMMM.     $..MM        +     .MM.    . .NMMMMMMMMMMMMMMMMMMMMMMMMMMMM..  ....MM .     +     MMM.   .?MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM~.....MM?      " + @part6 = "        ....                                ....             + ... . . .........    .. .    .. .  ......... .. . .          + MMMMMMMMM8I~....:~7DMMMMMMMMMDDMMMMMMMMM$+~~~~~IOMMMMMMMMMM. + MMMMM=.              ...MMMMMMMMMMN..           . .  MMMMMM. + .MMMM                    DMMMMMMM7                    MMMM~  +   MMN                   .~MM .:MM                   ..MMM    +   .MM                   .IM?...NM.                  ..MM .   +    :M                   .MM.  ..M8                  .,M.     + MM..                .M,.  . 8M..                .MM.     +     .M$.               ,MZ..    .MM.              ..OM..     +       MM....    ......,M?.        MM....    .......MM        +        8MM+.........MMM. .          MM?...  .....MM8..       + ...ZMMMMN$.....            ...?MMMMMMM=....         +                                                              +                     .   ..   ...  .  .                       +                      MMMMMMM  .MMMMMMM                            + ....       MMMMMMMMMMMMMMMMMMMMM        ....         +       MM..?.  ..,MMMMMMMMMMMMMMMMMMMMMMMMM.     $..MM        +     .MM.    . .NMMMMMMMMMMMMMMMMMMMMMMMMMMMM..  ....MM .     +     MMM.   .?MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM~.....MM?          + .MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM .     +      .MMMMMMMMMMMMMMMMMMMMMM8 NMMMMMMMMMMMMMMMMMMMMMM        +       . 7MMMMMMMMMMMMMMMMM.   . :MMMMMMMMMMMMMMMMM?          +           ...=I77?=,   .              .:=I77+~               " + @part7 = "        ....                                ....             + ... . . .........    .. .    .. .  ......... .. . .          + MMMMMMMMM8I~....:~7DMMMMMMMMMDDMMMMMMMMM$+~~~~~IOMMMMMMMMMM. + MMMMM=.              ...MMMMMMMMMMN..           . .  MMMMMM. + .MMMM                    DMMMMMMM7                    MMMM~  +   MMN                   .~MM .:MM                   ..MMM    +   .MM                   .IM?...NM.                  ..MM .   +    :M                   .MM.  ..M8                  .,M.     + MM..                .M,.  . 8M..                .MM.     +     .M$.               ,MZ..    .MM.              ..OM..     +       MM....    ......,M?.        MM....    .......MM        +        8MM+.........MMM. .          MM?...  .....MM8..       + ...ZMMMMN$.....            ...?MMMMMMM=....         +                                                              +                     .   ..   ...  .  .                       +                      MMMMMMM  .MMMMMMM                            + ....       MMMMMMMMMMMMMMMMMMMMM        ....         +       MM..?.  ..,MMMMMMMMMMMMMMMMMMMMMMMMM.     $..MM        +     .MM.    . .NMMMMMMMMMMMMMMMMMMMMMMMMMMMM..  ....MM .     +     MMM.   .?MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM~.....MM?          + .MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM .     +      .MMMMMMMMMMMMMMMMMMMMMM8 NMMMMMMMMMMMMMMMMMMMMMM        +       . 7MMMMMMMMMMMMMMMMM.   . :MMMMMMMMMMMMMMMMM?          +           ...=I77?=,   .              .:=I77+~               +            .. . .  ....                  .  .                +                                         ....                 + " + end + + def display(num_good_guess) + case num_good_guess + when 1 + puts @part1 + when 2 + puts @part2 + when 3 + puts @part3 + when 4 + puts @part4 + when 5 + puts @part5 + when 6 + puts @part6 + when 7 + puts @part7 + end + end end class Game - attr_accessor :random_word, :word_display, :num_bad_guess, :bad_letters, :letter + attr_accessor :random_word, :word_display, :num_bad_guess, :bad_letters, :letter, :num_good_guess, :part1 def initialize @@ -52,30 +195,62 @@ def initialize #when guesses_taken == guesses_allowed && random_word != word_display game over end - def play word = Word.new(Faker::Hipster.unique.word.downcase) @bad_guess_allowed = word.random_word.length + 3 - +print word.random_word.join("") while true print "\nLetter guess: " guess = gets.chomp.downcase print word.reveal(guess).join @num_bad_guess = word.count_bad_guess - + @num_good_guess = word.count_good_guess + puts @num_good_guess + Art.new.display(@num_good_guess) if word.random_word == word.word_display || guess == word.random_word.join("") #check for the 'win condition' - puts "\nCongrats!" + puts "\e[H\e[2J" + puts "\nCongrats! You guessed the word AND you look the part!" + Art.new.display(7) break end if @num_bad_guess == @bad_guess_allowed #if this happens the 'win condition', you lost :disappointed: - puts "\nSorry, you're out of guesses! The word was #{word.random_word.join("")}. Rad." + puts "\nSorry, you're out of guesses! The word was #{word.random_word.join("")}. Guess you didn't know the word before it was cool." break end end end end -puts "Welcome to Word Guess!" +puts "Welcome to Artisanal Haaang Maaaaan. Words are single-origin blah ...... " word = Game.new.play + +# +# print "        ....                                ....             +# ... . . .........    .. .    .. .  ......... .. . .          +# MMMMMMMMM8I~....:~7DMMMMMMMMMDDMMMMMMMMM$+~~~~~IOMMMMMMMMMM. +# MMMMM=.              ...MMMMMMMMMMN..           . .  MMMMMM. +# .MMMM                    DMMMMMMM7                    MMMM~  +#   MMN                   .~MM .:MM                   ..MMM    +#   .MM                   .IM?...NM.                  ..MM .   +#    :M                   .MM.  ..M8                  .,M.     +# MM..                .M,.  . 8M..                .MM.     +#     .M$.               ,MZ..    .MM.              ..OM..     +#       MM....    ......,M?.        MM....    .......MM        +#        8MM+.........MMM. .          MM?...  .....MM8..       +# ...ZMMMMN$.....            ...?MMMMMMM=....         +#                                                              +#                     .   ..   ...  .  .                       +#                      MMMMMMM  .MMMMMMM                            +# ....       MMMMMMMMMMMMMMMMMMMMM        ....         +#       MM..?.  ..,MMMMMMMMMMMMMMMMMMMMMMMMM.     $..MM        +#     .MM.    . .NMMMMMMMMMMMMMMMMMMMMMMMMMMMM..  ....MM .     +#     MMM.   .?MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM~.....MM?          +# .MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM .     +#      .MMMMMMMMMMMMMMMMMMMMMM8 NMMMMMMMMMMMMMMMMMMMMMM        +#       . 7MMMMMMMMMMMMMMMMM.   . :MMMMMMMMMMMMMMMMM?          +#           ...=I77?=,   .              .:=I77+~               +#            .. . .  ....                  .  .                +#                                         ....                 +# " From cfe129a499652cd9b73ead72371bc89c3d0aead2 Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Sat, 19 Aug 2017 13:34:21 -0700 Subject: [PATCH 14/20] Fixed number of guesses allowed and added hipster lingo --- mywordguess.rb | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/mywordguess.rb b/mywordguess.rb index d1432e5..3e86eaf 100644 --- a/mywordguess.rb +++ b/mywordguess.rb @@ -33,8 +33,8 @@ def count_bad_guess if @changed == nil #checks to see if guess was wrong @num_bad_guess += 1 # if guess is wrong increments bad guess otherwise gives "free" guess @bad_letters << @letter - puts "\nNumber of failed guesses: #{@num_bad_guess}" - puts "Letters you have guessed: #{@bad_letters.join(", ")}." #prints to user how many bad guesses they took + puts "\n\nFutile attempts: #{@num_bad_guess}" + puts "It's not these: #{@bad_letters.join(", ")}." #prints to user how many bad guesses they took end return @num_bad_guess #otherwise method returns nil end @@ -197,34 +197,53 @@ def initialize def play word = Word.new(Faker::Hipster.unique.word.downcase) - @bad_guess_allowed = word.random_word.length + 3 -print word.random_word.join("") + @bad_guess_allowed = 7 +#print word.random_word.join("") while true - print "\nLetter guess: " + print "Go!" + print ">>".blink guess = gets.chomp.downcase print word.reveal(guess).join @num_bad_guess = word.count_bad_guess @num_good_guess = word.count_good_guess - puts @num_good_guess + #puts @num_good_guess Art.new.display(@num_good_guess) if word.random_word == word.word_display || guess == word.random_word.join("") #check for the 'win condition' - puts "\e[H\e[2J" - puts "\nCongrats! You guessed the word AND you look the part!" Art.new.display(7) + puts "\nThey are vintage." break end if @num_bad_guess == @bad_guess_allowed #if this happens the 'win condition', you lost :disappointed: - puts "\nSorry, you're out of guesses! The word was #{word.random_word.join("")}. Guess you didn't know the word before it was cool." + puts "\nSo underground! The word was #{word.random_word.join("")}. I used this word for months before it was even cool." + Art.new.display(7) break end end end end -puts "Welcome to Artisanal Haaang Maaaaan. Words are single-origin blah ...... " - +let_me_help_you = [ + "Not to be a conformist, but there is only one right way to prep chai.", + "Nope! Hint: You can get a gallon of it at Trader Joe's, but I doubt it's organic.", + "That's not niche enough." +] +puts "This hang-man game is elite and invite-only (requires a password).\nHow do you take your vegan chai?" +puts ">".blue.blink +password = gets.chomp.downcase +until password == "dirty" + puts "#{let_me_help_you.sample.red}" + password = gets.chomp.downcase +end +if password == "dirty" +puts "Righteous! Every word is small-batch and artisanal. +If we had to classify it, it would be Avant-garde. +You get 7 guesses, 7 just feels right. +You can also type the entire word. +This way you win the game, but the word immediately becomes too mainstream. +Please begin:".green word = Game.new.play +end # # print "        ....                                ....             From 1c12fc0743f276a56e1d6e39252bc3e5050fb51a Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Sat, 19 Aug 2017 13:41:10 -0700 Subject: [PATCH 15/20] cleaned up some comments --- mywordguess.rb | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/mywordguess.rb b/mywordguess.rb index 3e86eaf..1c92abe 100644 --- a/mywordguess.rb +++ b/mywordguess.rb @@ -244,32 +244,3 @@ def play Please begin:".green word = Game.new.play end - -# -# print "        ....                                ....             -# ... . . .........    .. .    .. .  ......... .. . .          -# MMMMMMMMM8I~....:~7DMMMMMMMMMDDMMMMMMMMM$+~~~~~IOMMMMMMMMMM. -# MMMMM=.              ...MMMMMMMMMMN..           . .  MMMMMM. -# .MMMM                    DMMMMMMM7                    MMMM~  -#   MMN                   .~MM .:MM                   ..MMM    -#   .MM                   .IM?...NM.                  ..MM .   -#    :M                   .MM.  ..M8                  .,M.     -# MM..                .M,.  . 8M..                .MM.     -#     .M$.               ,MZ..    .MM.              ..OM..     -#       MM....    ......,M?.        MM....    .......MM        -#        8MM+.........MMM. .          MM?...  .....MM8..       -# ...ZMMMMN$.....            ...?MMMMMMM=....         -#                                                              -#                     .   ..   ...  .  .                       -#                      MMMMMMM  .MMMMMMM                            -# ....       MMMMMMMMMMMMMMMMMMMMM        ....         -#       MM..?.  ..,MMMMMMMMMMMMMMMMMMMMMMMMM.     $..MM        -#     .MM.    . .NMMMMMMMMMMMMMMMMMMMMMMMMMMMM..  ....MM .     -#     MMM.   .?MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM~.....MM?          -# .MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM .     -#      .MMMMMMMMMMMMMMMMMMMMMM8 NMMMMMMMMMMMMMMMMMMMMMM        -#       . 7MMMMMMMMMMMMMMMMM.   . :MMMMMMMMMMMMMMMMM?          -#           ...=I77?=,   .              .:=I77+~               -#            .. . .  ....                  .  .                -#                                         ....                 -# " From 0cc1e9052e84dbec901ab4f0d4527b5284171fda Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Sat, 19 Aug 2017 13:51:01 -0700 Subject: [PATCH 16/20] some styling --- mywordguess.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mywordguess.rb b/mywordguess.rb index 1c92abe..9f22f6b 100644 --- a/mywordguess.rb +++ b/mywordguess.rb @@ -179,7 +179,7 @@ def display(num_good_guess) when 6 puts @part6 when 7 - puts @part7 + puts @part7.blink end end end From ba9b51e3dedf4c36e5303648cd2590be46e634d1 Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Sat, 19 Aug 2017 17:57:46 -0700 Subject: [PATCH 17/20] changed attr and some wording --- mywordguess.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mywordguess.rb b/mywordguess.rb index 9f22f6b..9a323c4 100644 --- a/mywordguess.rb +++ b/mywordguess.rb @@ -34,7 +34,7 @@ def count_bad_guess @num_bad_guess += 1 # if guess is wrong increments bad guess otherwise gives "free" guess @bad_letters << @letter puts "\n\nFutile attempts: #{@num_bad_guess}" - puts "It's not these: #{@bad_letters.join(", ")}." #prints to user how many bad guesses they took + puts "You've already typed: #{@bad_letters.join(", ")}." #prints to user how many bad guesses they took end return @num_bad_guess #otherwise method returns nil end @@ -185,7 +185,7 @@ def display(num_good_guess) end class Game - attr_accessor :random_word, :word_display, :num_bad_guess, :bad_letters, :letter, :num_good_guess, :part1 + attr_reader :random_word, :word_display, :num_bad_guess, :bad_letters, :letter, :num_good_guess, :part1 def initialize @@ -214,7 +214,7 @@ def play puts "\nThey are vintage." break end - if @num_bad_guess == @bad_guess_allowed #if this happens the 'win condition', you lost :disappointed: + if @num_bad_guess == @bad_guess_allowed #if this happens you lose. puts "\nSo underground! The word was #{word.random_word.join("")}. I used this word for months before it was even cool." Art.new.display(7) break @@ -236,7 +236,8 @@ def play password = gets.chomp.downcase end if password == "dirty" -puts "Righteous! Every word is small-batch and artisanal. +puts "Righteous! +Welcome to the game! Every word is sourced locally and responsibly. If we had to classify it, it would be Avant-garde. You get 7 guesses, 7 just feels right. You can also type the entire word. From 05c3d5ae60f9638c677d6ce52baaf6ad5b17e176 Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Sat, 19 Aug 2017 18:05:11 -0700 Subject: [PATCH 18/20] change attr for Art class --- mywordguess.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mywordguess.rb b/mywordguess.rb index 9a323c4..f94c902 100644 --- a/mywordguess.rb +++ b/mywordguess.rb @@ -49,7 +49,7 @@ def count_good_guess end class Art - attr_accessor :num_good_guess, :part1, :part2, :part3, :part4, :part5, :part6, :part7 + attr_reader :num_good_guess, :part1, :part2, :part3, :part4, :part5, :part6, :part7 def initialize @part1 = "        ....                                ....             ... . . .........    .. .    .. .  ......... .. . .          From f3bdd2b50c584b4af1a4881f4944a9b1f7e6db31 Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Sat, 19 Aug 2017 18:30:57 -0700 Subject: [PATCH 19/20] added quotes --- mywordguess.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mywordguess.rb b/mywordguess.rb index f94c902..0ed3483 100644 --- a/mywordguess.rb +++ b/mywordguess.rb @@ -215,7 +215,7 @@ def play break end if @num_bad_guess == @bad_guess_allowed #if this happens you lose. - puts "\nSo underground! The word was #{word.random_word.join("")}. I used this word for months before it was even cool." + puts "\nSo underground! The word was '#{word.random_word.join("")}'. I used this word for months before it was even cool." Art.new.display(7) break end From d277b43966a3e55e9452db26e7ffa375f02a8eca Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Mon, 21 Aug 2017 15:13:38 -0700 Subject: [PATCH 20/20] final edit refactored and updated wording --- mywordguess.rb | 146 ++++++++++++++++++++++++------------------------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/mywordguess.rb b/mywordguess.rb index 0ed3483..ceea563 100644 --- a/mywordguess.rb +++ b/mywordguess.rb @@ -1,55 +1,35 @@ require 'faker' require 'colorize' -require 'artii' - - class Word - attr_accessor :random_word, :word_display, :num_bad_guess, :bad_letters, :letter, :num_good_guess - def initialize (random_word) + attr_reader :random_word, :word_display, :changed + + def initialize(random_word) @random_word = random_word.split("") - @word_display = Array.new(random_word.length, "_ ") #make array of underscores - @num_bad_guess = 0 #had to give it initial val so that we cound increment it with count bad guess method - @num_good_guess = 0 - @bad_letters = [] + @word_display = Array.new(random_word.length, "_ ") end - def reveal(letter) - @letter = letter - counter = 0 # keeps track of random word index number + def reveal(guess) + counter = 0 #keeps track of random_word array index number @changed = nil - @random_word.each do |alpha| - if alpha == @letter - @word_display[counter] = @letter - @changed = true # indicates that guess was right + @random_word.each do |char| + if char == guess + @word_display[counter] = guess + @changed = true end counter += 1 end return @word_display end - def count_bad_guess - unless @letter == @random_word.join("") - if @changed == nil #checks to see if guess was wrong - @num_bad_guess += 1 # if guess is wrong increments bad guess otherwise gives "free" guess - @bad_letters << @letter - puts "\n\nFutile attempts: #{@num_bad_guess}" - puts "You've already typed: #{@bad_letters.join(", ")}." #prints to user how many bad guesses they took - end - return @num_bad_guess #otherwise method returns nil - end - end - - def count_good_guess - if @changed == true - @num_good_guess += 1 - end - return @num_good_guess + def changed? #keeps track of whether word_display changed i.e. whether the guess was right + return @changed end end class Art - attr_reader :num_good_guess, :part1, :part2, :part3, :part4, :part5, :part6, :part7 + attr_reader :part1, :part2, :part3, :part4, :part5, :part6, :part7 + def initialize @part1 = "        ....                                ....             ... . . .........    .. .    .. .  ......... .. . .          @@ -167,56 +147,75 @@ def initialize def display(num_good_guess) case num_good_guess when 1 - puts @part1 + return @part1 when 2 - puts @part2 + return @part2 when 3 - puts @part3 + return @part3 when 4 - puts @part4 + return @part4 when 5 - puts @part5 + return @part5 when 6 - puts @part6 + return @part6 when 7 - puts @part7.blink + return @part7 end end + end class Game - attr_reader :random_word, :word_display, :num_bad_guess, :bad_letters, :letter, :num_good_guess, :part1 + def initialize + @word = Word.new(Faker::Hipster.unique.word.downcase) + @bad_guess_allowed = 7 + @num_bad_guess = 0 + @num_good_guess = 0 + @bad_letters = [] + end + def count_bad_guess(guess) + unless guess == @word.random_word.join("") + if @changed == nil + @num_bad_guess += 1 + @bad_letters << guess + puts "\n\nFutile attempts: #{@num_bad_guess}" + puts "You’ve already tried: #{@bad_letters.join(", ")}" + end + return @num_bad_guess + end + end - #when guesses_taken > guesses_allowed game over - #or - #when guesses_taken == guesses_allowed && word_display.includes? " _ " game over - #when guesses_taken == guesses_allowed && random_word != word_display game over + def count_good_guess + if @changed == true + @num_good_guess += 1 #stores how many good guesses has taken so Art.display can show that many parts of the image + puts "\n\nGood guess! You're on a roll!" + puts "You’ve already tried: #{@bad_letters.join(", ")}" + end + return @num_good_guess end def play - word = Word.new(Faker::Hipster.unique.word.downcase) - @bad_guess_allowed = 7 -#print word.random_word.join("") + while true - print "Go!" - print ">>".blink + print "\nGo! " + print ">> ".blink guess = gets.chomp.downcase - print word.reveal(guess).join - @num_bad_guess = word.count_bad_guess - @num_good_guess = word.count_good_guess - #puts @num_good_guess - Art.new.display(@num_good_guess) - if word.random_word == word.word_display || guess == word.random_word.join("") - #check for the 'win condition' - Art.new.display(7) - puts "\nThey are vintage." + print @word.reveal(guess).join + @changed = @word.changed? + @num_bad_guess = count_bad_guess(guess) + @num_good_guess = count_good_guess + puts Art.new.display(@num_good_guess) + if @word.random_word == @word.word_display || guess == @word.random_word.join("") + #check for the ‘win condition’ + puts Art.new.display(7).blue.blink + puts "\nLook at you: you guessed the word and looked good doing it! They're vintage." break end - if @num_bad_guess == @bad_guess_allowed #if this happens you lose. - puts "\nSo underground! The word was '#{word.random_word.join("")}'. I used this word for months before it was even cool." - Art.new.display(7) + if @num_bad_guess == @bad_guess_allowed #if this happens before the win condition is satisfied, you lose :( + puts "\nUh-oh! You're out of guesses. The word was ‘#{@word.random_word.join("").capitalize}‘. I used this word for months before it was even cool." + puts Art.new.display(7).red.blink break end end @@ -225,8 +224,8 @@ def play let_me_help_you = [ "Not to be a conformist, but there is only one right way to prep chai.", - "Nope! Hint: You can get a gallon of it at Trader Joe's, but I doubt it's organic.", - "That's not niche enough." + "Nope! Hint: You can get a gallon of it at Trader Joe’s, but I doubt it’s organic.", + "That’s not niche enough." ] puts "This hang-man game is elite and invite-only (requires a password).\nHow do you take your vegan chai?" puts ">".blue.blink @@ -236,12 +235,13 @@ def play password = gets.chomp.downcase end if password == "dirty" -puts "Righteous! -Welcome to the game! Every word is sourced locally and responsibly. -If we had to classify it, it would be Avant-garde. -You get 7 guesses, 7 just feels right. -You can also type the entire word. -This way you win the game, but the word immediately becomes too mainstream. -Please begin:".green -word = Game.new.play + puts "Righteous! + Welcome to the game! Every word is sourced locally and responsibly. + If we had to classify it, it would be Avant-garde. + You get 7 guesses, 7 just feels right. + You can also type the entire word. + This way you win the game, but the word immediately becomes too mainstream. + Please begin:".green + + Game.new.play end