Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ampers: Nicoleta && Kate #14

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions art-ideas
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Z Z Z Z Z

|\ _,,,---,,_
/,`.-'`' -. ;-;;,_
|,4- ) )-,_..;\ ( `'-'
'---''(_/--' `-'\_)

_
| \
| |
| |
|\ | |
/, ~\ / /
X `-.....-------./ /
~-. ~ ~ |
\ / |
\ /_ ___\ /
| /\ ~~~~~ \ |
| | \ || |
| |\ \ || )
(_/ (_/ ((_/
132 changes: 132 additions & 0 deletions wordguess.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
class Game
attr_accessor :words_array, :word, :guess, :tries

def initialize(words_array)
@words_array = words_array
@tries = 5
end

def choose_word
@word = Word.new(words_array.sample)
end

## Start Guess Method
def guess(letters_array)
art = Art.new
bad_guesses = []
while @tries > 0 && word.blanks_array.include?("_")
puts art.play_art
puts "\t#{word.blanks_array.join(" ")}"
print "\nPlease guess a letter: "
guess = gets.chomp

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is important to "trap" user input so they can't enter an invalid letter. You could also wrap the act of guessing into a helper method.

puts "\n------------------------------------------"


if word.letters_array.include?(guess) # if guess is right

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can break out the code that handles the logic of checking to see if the letter is in the word and updating the guesses & blanks_array into a helper method and let this method focus on the user input.

puts "Good guess!"
# finding blanks and replacing them with the guess
word.letters_array.length.times do |i|
if word.letters_array[i] == guess
word.blanks_array[i] = guess
end
end
else # if guess is wrong
@tries -= 1
puts "\nSorry try again."
puts "You have #{@tries} tries left."
bad_guesses << guess
end
if bad_guesses.length != 0 && word.blanks_array.include?("_")
puts "\nAlready guessed letters are: \n#{bad_guesses.join(", ")}\n"
end

end
return @tries
end
## End Guess Method
end

## Start Word Class
class Word
attr_accessor :blanks_array, :chosen_word, :letters_array

def initialize(word)
@chosen_word = word
end

def split
@letters_array = @chosen_word.split(//)
return @letters_array
end

def create_blanks
@blanks_array = []
@letters_array.each do
@blanks_array << "_"
end
return @blanks_array
end
end
## End Word Class

## Start Art Class
class Art

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the Art need a class or would a method do as well?

attr_accessor :art

def initialize
@art = art

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sets @Art to itself, doing nothing.

end

def play_art
@play_art = "

Z Z Z Z Z

|\\ _,,,---,,_
/,`.-'`' -. ;-;;,_
|,4- ) )-,_..;\\ ( `'-'
'---''(_/--' `-'\\_)"

return @play_art
end

def end_art
@end_art = "
_
| \\
| |
| |
|\\ | |
/, ~\\ / /
X `-.....-------./ /
~-. ~ ~ |
\\ / |
\\ /_ ___\\ /
| /\\ ~~~~~ \\ |
| | \\ || |
| |\\ \\ || )
(_/ (_/ ((_/"

return @end_art
end
end
## End Art Class

## Start Game
game = Game.new(["ampers","octos","code","ada"])

puts "\nWelcome to our Don't Wake the Cat Guessing Game!"
puts "Can you guess my word before the cat wakes up?"
game.choose_word # => word from array
game.word.split # word split
puts "The word is #{game.word.split.length} letters long."
game.word.create_blanks
game.guess(game.word)
if game.tries == 0 # ran out of tries
puts "\nSorry the cat is now awake"
our_art = Art.new
puts our_art.end_art
else # if word correct
puts "\n\t#{game.word.split.join("")}!"
puts "\nCongratulations you've guessed the word! You win!\n"
end
114 changes: 114 additions & 0 deletions wordguess_with_notes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
class Game
attr_accessor :words_array, :word

def initialize(words_array)
@words_array = words_array
end

def choose_word
@word = Word.new(words_array.sample)
end

end

class Word
attr_accessor :blanks, :word, :letters_array

def initialize(word)
@word = word
end

def split
# @letters_array = @word
@letters_array = @word.split(//)
return @letters_array
end

def create_blanks
blanks = ""
@letters_array.each do
blanks += "_ "
end
return blanks
end
end

class Art
attr_accessor :art

def initialize
@art = art
end

def play_art
play_art = "
|\\ _,,,---,,_
/,`.-'`' -. ;-;;,_
|,4- ) )-,_..;\\( `'-'
'---''(_/--' `-'\\_)"
return play_art
end

def end_art
end_art = "
_
| \\
| |
| |
|\\ | |
/, ~\\ / /
X `-.....-------./ /
~-. ~ ~ |
\\ / |
\\ /_ ___\\ /
| /\\ ~~~~~ \\ |
| | \\ || |
| |\\ \\ || )
(_/ (_/ ((_/"
return end_art
end

end

def guess(game_word)
puts "I'm in the guess method. I passed in an instance of Word called my_word_instance. This is its value:"
puts game_word

# start guess loop
print "Please guess a letter: "
guess = gets.chomp

puts "I want some letters_array. What is the letters array?"
puts game_word.letters_array

if game_word.letters_array.include?(guess) # if guess is right
puts "Good guess!"
else # if guess is wrong
# change art
puts "Sorry try again"
end
end

game = Game.new(["ampers","octos","code","ada"])

our_art = Art.new
print our_art.play_art

puts "\nWelcome to our Don't Wake the Cat Guessing Game!"
puts "Can you guess my word before the cat wakes up?"
game.choose_word
p game.word.split
p game.word.create_blanks
# add art

puts "I have an instance of Game:"
puts game
puts "My instance of Game called game has an instance of word in game.word"
puts game.word

guess(game.word)
# if word correct
puts "Congratulations you won!"
# if word incorrect
puts "Sorry the cat is now awake"
puts our_art.end_art