Skip to content
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
26 changes: 26 additions & 0 deletions letter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# class Letter
# attr_accessor :letter
#
# def initialize(letter)
# @letter = letter
# end
#
# def add_to_word
#
# #compare to word, add to space if part of word check?
# end
#
# def limit_input
# # to ensure only word is added at a time
# end
#
# def ascii_change
# # draw art associated with wrong guess
# end
#
#
#
# end # end of letter class
#
# letter = Letter.new(guess)
# puts letter
36 changes: 36 additions & 0 deletions main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require_relative 'word'
require 'faker'
require 'colorize'

# User select level of difficulty
puts "

__ __ _
\\ \\ / / | |
\\ \\ /\\ / /__ _ __ __| |
\\ \\/ \\/ / _ \\| '__/ _` |
\\ /\\ / (_) | | | (_| |
\\/ \\/ \\___/|_| \\__,_|

______
|___ /
/ / ___ _ _ __
/ / / _ \\| __\\ / _ |
/ /__ (_) | | || __/
/_____\\___/|_| |_|\\ \\\n\n"


puts "Welcome to Word Zone! You have 6 tries to guess a word or be booted out of the game.\n To unlock the secret token, you will have to complete all three levels.\n Select difficulty level:\n 1: Easy: Color, 2: Intermediate: Starwars Characters, 3: Hard: Superhero power!\n"
level = gets.chomp.to_i

case level
when 1
word = Faker::Color.color_name
when 2
word = Faker::StarWars.character
when 3
word = Faker::Superhero.power
end


word_guess = Word.new(word)
128 changes: 128 additions & 0 deletions word.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
require 'colorize'
require 'faker'
#require 'letter'

class Word
attr_accessor :word

def initialize(word)
@word = word.upcase.split("")
@total_guesses = 0
@correct_guesses = 0 # compare to word length
@wrong_guesses = 0 # count down
#create array of all the blank spaces
@dash_array = []
@word.each do |char|
if char == " "
@dash_array.push(" ")
else
@dash_array.push("_ ")
end
end
puts "Can you guess this word?"
puts @dash_array.join
@previous_guesses = []
track_guesses
end

# user input
def track_guesses
until @wrong_guesses == 6 || @word == @dash_array
print "Guess a letter:"
@guess = gets.chomp.upcase!
#check if user enters the same guess more than once
if @previous_guesses.include?(@guess) == false
@previous_guesses.push(@guess)
puts "Previous guess #{@previous_guesses}"
check_guess(@guess)
else
puts "You already picked that letter."
end

if @wrong_guesses == 6
puts "GAME OVER."
puts "The words is #{@word.join}"
exit
end
if @word == @dash_array
puts "Way to go!! The word is #{@dash_array.join}!!"
ascii_win
exit
end
end
end

# track number of correct and wrong guesses
def check_guess(guess)
if @word.include?(guess)
if !@dash_array.include?(@guess)
puts "Great! #{guess} is a match!"
@correct_guesses += 1
replace_letter
end
else
puts "Try again"
@wrong_guesses += 1
ascii_change
end
@total_guesses += 1
puts @dash_array.join
end

def replace_letter
@word.length.times do |i|
if @guess == @word[i]
@dash_array[i] = @guess
end
end
end
end

def ascii_change
case @wrong_guesses
when 1
puts ("|").colorize(:blue)

when 2
puts ("
| | ").colorize(:blue)

when 3
puts ("
| |
| | ___ ___ ___ _ ").colorize(:blue)

when 4
puts ("
| |
| | ___ ___ ___ _ __
| | / _ \/ __|/ _ \ '__|").colorize(:blue)

when 5
puts ("
| |
| | ___ ___ ___ _ __
| | / _ \/ __|/ _ \ '__|
| |____ (_) \__ \ __/ |").colorize(:blue)

when 6
puts ("
| |
| | ___ ___ ___ _ __
| | / _ \/ __|/ _ \ '__|
| |____ (_) \__ \ __/ |
|______\___/|___/\___|_|").colorize(:red).blink
end

def ascii_win
puts "
/$$ /$$ /$$$$$$ /$$ /$$ /$$ /$$ /$$$$$$$$ /$$$$$$$
| $$ /$ | $$|_ $$_/| $$$ | $$| $$$ | $$| $$_____/| $$__ $$
| $$ /$$$| $$ | $$ | $$$$| $$| $$$$| $$| $$ | $$ \ $$
| $$/$$ $$ $$ | $$ | $$ $$ $$| $$ $$ $$| $$$$$ | $$$$$$$/
| $$$$_ $$$$ | $$ | $$ $$$$| $$ $$$$| $$__/ | $$__ $$
| $$$/ \ $$$$ | $$ | $$\ $$$| $$$\ $$$| $$ | $$ \ $$
| $$/ \ $$ /$$$$$$| $$ \ $$| $$$ \ $$| $$$$$$$$| $$ | $$
|__/ \__/|______/|__/ \__/|__/ \__/|________/|__/ |__/"
end
end