Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
e182cac
create main.rb
tanham Aug 17, 2017
f908353
create random word class
tanham Aug 17, 2017
8f66ff9
update main.rb to include new classes
tanham Aug 17, 2017
1f95821
updates
tanham Aug 17, 2017
60a2b67
creates user_input.rb
tanham Aug 17, 2017
72397dd
fix check letter method
tanham Aug 17, 2017
9c0c18c
add a to each word
tanham Aug 17, 2017
e06caca
test new methods
tanham Aug 17, 2017
34fe2d0
add reprint method
tanham Aug 17, 2017
9365f0a
update check letter method
tanham Aug 17, 2017
aea978c
add comments to reprint methods
tanham Aug 17, 2017
7b5649e
test new methods
tanham Aug 17, 2017
78de96a
update rewrite_undercore method
tanham Aug 17, 2017
158d3cf
add get_next_letter method
tanham Aug 17, 2017
2076699
add logic/loop to run game
tanham Aug 17, 2017
3cbcf12
add test to rewrite_underscore
tanham Aug 17, 2017
08e1f79
move gets.chomp to method, not initialize.
tanham Aug 17, 2017
1e39f6d
modify
tanham Aug 17, 2017
5ad2522
create, add birthday cake ascii art
tanham Aug 17, 2017
2cce1f5
add take_away_candle method (like a boss)
tanham Aug 17, 2017
3731abb
add cake take away to game
tanham Aug 17, 2017
152f146
add cake to check method
tanham Aug 17, 2017
f8be046
add new line to underscore array
tanham Aug 18, 2017
a4304d1
colorize cake ascii
tanham Aug 18, 2017
8c16a48
comment out test code
tanham Aug 18, 2017
63de9cb
add user prompts for right and wrong guesses
tanham Aug 18, 2017
0f277cd
edit user prompts for right and wrong guesses
tanham Aug 18, 2017
02c6cfc
add game instructions and checks for winner
tanham Aug 18, 2017
36c496e
add show cake method
tanham Aug 18, 2017
45392d6
add code to check for loser
tanham Aug 18, 2017
4406f7f
change random words for easy testing
tanham Aug 18, 2017
8fc36f7
add variable to attr_reader
tanham Aug 18, 2017
1221091
check for loser and exit game
tanham Aug 18, 2017
31d784b
fix colorize
tanham Aug 18, 2017
622efb3
fix colorize and clean code up
tanham Aug 18, 2017
afa2d32
fix colorize
tanham Aug 18, 2017
f61122a
change game instructions
tanham Aug 18, 2017
e32bc87
change color of candles
tanham Aug 18, 2017
17171f3
include Bennett's code
tanham Aug 18, 2017
aa22e00
display word win player loses
tanham Aug 18, 2017
11a05c8
update color
tanham Aug 18, 2017
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
37 changes: 37 additions & 0 deletions ascii_art.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class AsciiArt
attr_reader :body, :candle_light, :candle_body
attr_writer :candle_light, :candle_body
def initialize
@body = [
" |||||
@@@@@@@@@
{~@~@~@~}
@@@@@@@@@@@@@
{~@ HAPPY @~}
{ BIRTHDAY }
@@@@@@@@@@@@@".blue
]
# @candle_light = [" `````"] #don't move
# @candle_body = [" |||||"] #don't move
@candle_light = " `````" #don't move


end

def change_candles
a = @candle_light.split('')
a.pop
@candle_light = a.join
end

def take_away_candle
change_candles
puts @candle_light.yellow
puts @body
end

def show_cake
puts @candle_light.yellow
puts @body
end
end
43 changes: 43 additions & 0 deletions main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require 'artii'
require_relative 'user_input'
require_relative 'random_word'
require_relative 'ascii_art'
require 'colorize'
require 'random_word_generator'

penny = RandomWord.new
user = UserInput.new
cake = AsciiArt.new

# game greeting and instructions
puts "Welcome to Word-Guess!".blue
puts "=".blue * 22
puts "GAME INSTRUCTIONS:".colorize(:green)
puts "1.) Guess the word I'm thinking for a chance to have my Birthday Cake.".green
puts "2.) For every incorrect letter you choose, I will blow out one candle.".green
puts "3.) If you guess incorrectly 5 times, you lose and I will happliy keep my cake.".green
cake.show_cake
puts "READY...".red
puts "SET...".red

# loops until underscore array == random word || length of wrong_letters == 5
until penny.underscore == penny.word || user.wrong_letters.length == 5
puts "Guess >> ".green

# check user input letter
user.check_letter(penny, user, cake)

# checks for loser and exits game
if user.wrong_letters.length == 5
puts
puts "=".colorize(:light_blue) * 16
puts "The word was #{penny.word.join.upcase}"
puts "YOU LOSE, I WIN!".blue
end
end

# checks for winner and outputs win message
if penny.underscore == penny.word
puts "YOU WIN!!!. You can eat my birthday cake!".green
cake.show_cake
end
33 changes: 33 additions & 0 deletions random_word.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class RandomWord
attr_reader :word, :underscore

def initialize()
# word_arr = ["envelope", "cat", "dragon", "coffee", "water", "pencil"]
# @word = word_arr[rand(word_arr.length)].split('')
@word = RandomWordGenerator.of_length(5).split('')
@length = @word.length
@underscore = ("_ " * @length).split(' ')
end


def rewrite_underscore(user_input)
# if user correctly guesses whole world, they win.
if @word.join == user_input.current_letter
arr = user_input.current_letter.split('')
arr.length.times do |i|
@underscore[i] = arr[i]
end

else
# find index(es) of letter(s) of random word
arr = @word.each_index.select{|n| @word[n] == user_input.current_letter}
# replace underscore with right letter
arr.each do |i|
@underscore[i] = user_input.current_letter
end
print @underscore
end

end

end
52 changes: 52 additions & 0 deletions user_input.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
class UserInput
attr_reader :current_letter, :wrong_letters
def initialize
@current_letter = ""
@wrong_letters = []
@right_letters = []
end

def check_letter(random_word, user_input, cake)
guess_display
@current_letter = gets.chomp.downcase
# checks that user input is actually a letter, makes them try again if not.
until @current_letter =~ /[[:alpha:]]/
puts "Invalid guess - please only guess one letter."
return
end
# if user correctly guesses whole word, they win.
if random_word.word.join == @current_letter
random_word.rewrite_underscore(user_input)
return
# if random word array includes @current_letter
elsif random_word.word.include?(@current_letter)
if @right_letters.include?(@current_letter)
puts "You've already tried that one, try something different!"
return
end
@right_letters << @current_letter
puts "Good job, keep guessin'"
# replace underscore at that index with user_input(@current_letter)
random_word.rewrite_underscore(user_input)
return
else
if @wrong_letters.include?(@current_letter)
puts "You've already tried that one, try something different!"
return
end
@wrong_letters << @current_letter
puts "WRONG, you loss a candle. Try Again".red
cake.take_away_candle
return
end
end

# prints the already guessed letters
def guess_display
already_guessed = @wrong_letters + @right_letters
already_guessed = already_guessed.join(', ')

puts "You've already guessed: #{already_guessed}".yellow
end

end