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

Dikla and Brenda - Word_Guess - Octos #18

Open
wants to merge 5 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
37 changes: 37 additions & 0 deletions method of level selection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

# This method will select the level of the game and according to the level, the program
# will select an arrays of words.
# The user will have 4 trials to enter a level. We did this to have an end of the program
# in case the user keeps entering the wrong level input.
def selection_level

levels = %w[low medium high]
puts "Please enter a level: low, medium or high?"
level = nil
until level == "low" || level == "medium" || level == "high"
level = gets.chomp.downcase
if level == "low"
@word_array = @words_low
elsif level == "medium"
@word_array = @words_medium
elsif level == "high"
@word_array = @words_high
elsif level != "low" && level != "hard" && level != "medium"
puts "Invalid level. Please enter again"
level = gets.chomp.downcase
end

attempt = 0
while !levels.include?(level)
if attempt < 3
attempt += 1
puts "Please enter a valid level. You have #{(-attempt + 3) + 1} more attempts.\n"
level = gets.chomp
else
puts "Too many attempts..start the program again"
exit
end
end
end

end
9 changes: 9 additions & 0 deletions validate_input.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This method hanbles inappropriate user input.
# This method validates that the input of letter from the user is a letter and not any other character.
# We did this to don't count inputs as wrong guesses if the user inputs numbers, symbols etc.
def validate_input_letter(input)
until !input.match(/[^a-z]/)
puts "\nPlease return a valid letters from A to Z.\n"
input = gets.chomp.downcase
end
end
22 changes: 22 additions & 0 deletions word_guess.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# We color the program in certain messages and use features like blink and bold in them also.
require 'colorize'


puts "WELCOME TO DISNEY WORD GUESS"
puts "Words Theme: Walt Disney".colorize(:blue)

# one class contain different methods for the game
class WordGuess

def initialize
@words_low = %w[minnie mickey donald daisy pluto goofy alice olaf anna ariel]
@words_medium = %w[tigger cinderella bambi pocahontas eeyor rabbit mulan belle dumbo]
@words_high = %w[esmeralda quasimodo anastasia mowgli anastasia drizella kocoum maleficent]
@letters_guessed = []
@guesses_counter = 0
selection_level
@word = @word_array.sample
@letters_correct = Array.new(@word.length, "_" )
ascii_image
letters_input
end
308 changes: 308 additions & 0 deletions word_guess_game.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,308 @@

# We color the program in certain messages and use features like blink and bold in them also.
require 'colorize'


puts "WELCOME TO DISNEY WORD GUESS"
puts "Words Theme: Walt Disney".colorize(:blue)

# one class contain different methods for the game
class WordGuess

def initialize
@words_low = %w[minnie mickey donald daisy pluto goofy alice olaf anna ariel]
@words_medium = %w[tigger cinderella bambi pocahontas eeyor rabbit mulan belle dumbo]
@words_high = %w[esmeralda quasimodo anastasia mowgli anastasia drizella kocoum maleficent]
@letters_guessed = []
@guesses_counter = 0
selection_level
@word = @word_array.sample
@letters_correct = Array.new(@word.length, "_" )
ascii_image
letters_input
end

# This method will select the level of the game and according to the level, the program
# will select an arrays of words.
# The user will have 4 trials to enter a level. We did this to have an end of the program
# in case the user keeps entering the wrong level input.
def selection_level

levels = %w[low medium high]
puts "Please enter a level: low, medium or high?"
level = nil
until level == "low" || level == "medium" || level == "high"
level = gets.chomp.downcase
if level == "low"
@word_array = @words_low
elsif level == "medium"
@word_array = @words_medium
elsif level == "high"
@word_array = @words_high
elsif level != "low" && level != "hard" && level != "medium"
puts "Invalid level. Please enter again"
level = gets.chomp.downcase
end

attempt = 0
while !levels.include?(level)
if attempt < 3
attempt += 1
puts "Please enter a valid level. You have #{(-attempt + 3) + 1} more attempts.\n"
level = gets.chomp
else
puts "Too many attempts..start the program again"
exit
end
end
end

end

# This method hanbles inappropriate user input.
# This method validates that the input of letter from the user is a letter and not any other character.
# We did this to don't count inputs as wrong guesses if the user inputs numbers, symbols etc.
def validate_input_letter(input)
until !input.match(/[^a-z]/)
puts "\nPlease return a valid letters from A to Z.\n"
input = gets.chomp.downcase
end
end

# In this method, the user inputs a letter. The method can validate input is a letter,
# and also can tell if the letter has been already used.
def letters_input
@guesses_counter = 0
while @guesses_counter < 5
puts "Guess a letter!"
puts "Word: #{@letters_correct.join("")}"
letter = gets.chomp

validate_input_letter(letter)

if letter.length > 1
if letter == @word
you_win
exit
end
end

#This loop helps the user to don't be penalized for guessing the same letter more than once.
while @letters_guessed.include? letter do
puts "You have already tried this letter, try another one: "
letter = gets.chomp

validate_input_letter(letter)
end

@letters_guessed << letter

if @word.include? letter
@word.split(//).each_index do |i|
if @word[i] == letter
@letters_correct[i] = letter
end
end
ascii_image
else
@guesses_counter += 1
puts "Keep trying!!".colorize(:orange).blink
ascii_image
end
if @word.split(//) == @letters_correct
you_win
exit
end
puts "Letters you have tried --> #{@letters_guessed.join("")}".colorize(:purple)
end

end


def ascii_image
if @guesses_counter == 1

puts "

_____________________________________________
_________________¶¶¶¶¶¶¶¶¶¶¶_________________
____________¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶____________
__________¶¶¶¶¶¶_____________¶¶¶¶¶¶__________
________¶¶¶¶¶___________________¶¶¶¶¶________
_______¶¶¶¶_______________________¶¶¶¶_______
______¶¶¶___________________________¶¶¶______
_____¶¶¶______¶¶¶¶¶_______¶¶¶¶¶______¶¶¶_____
____¶¶¶______¶¶¶¶¶¶_______¶¶¶¶¶¶______¶¶¶____
"
elsif @guesses_counter == 2
puts "

_____________________________________________
_________________¶¶¶¶¶¶¶¶¶¶¶_________________
____________¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶____________
__________¶¶¶¶¶¶_____________¶¶¶¶¶¶__________
________¶¶¶¶¶___________________¶¶¶¶¶________
_______¶¶¶¶_______________________¶¶¶¶_______
______¶¶¶___________________________¶¶¶______
_____¶¶¶______¶¶¶¶¶_______¶¶¶¶¶______¶¶¶_____
____¶¶¶______¶¶¶¶¶¶_______¶¶¶¶¶¶______¶¶¶____
___¶¶¶_______¶¶¶¶¶¶_______¶¶¶¶¶¶_______¶¶¶___
___¶¶¶________¶¶¶¶_________¶¶¶¶________¶¶¶___
___¶¶___________________________________¶¶___
___¶¶___________________________________¶¶___
___¶¶______¶¶___________________¶¶______¶¶___
___¶¶¶_____¶¶___________________¶¶_____¶¶¶___
___¶¶¶______¶¶_________________¶¶______¶¶¶___
____¶¶¶______¶¶¶_____________¶¶¶______¶¶¶____
"

elsif @guesses_counter == 3
puts "
_____________________________________________
_________________¶¶¶¶¶¶¶¶¶¶¶_________________
____________¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶____________
__________¶¶¶¶¶¶_____________¶¶¶¶¶¶__________
________¶¶¶¶¶___________________¶¶¶¶¶________
_______¶¶¶¶_______________________¶¶¶¶_______
______¶¶¶___________________________¶¶¶______
_____¶¶¶______¶¶¶¶¶_______¶¶¶¶¶______¶¶¶_____
____¶¶¶______¶¶¶¶¶¶_______¶¶¶¶¶¶______¶¶¶____
___¶¶¶_______¶¶¶¶¶¶_______¶¶¶¶¶¶_______¶¶¶___
___¶¶¶________¶¶¶¶_________¶¶¶¶________¶¶¶___
___¶¶___________________________________¶¶___
___¶¶___________________________________¶¶___
___¶¶______¶¶___________________¶¶______¶¶___
___¶¶¶_____¶¶___________________¶¶_____¶¶¶___
___¶¶¶______¶¶_________________¶¶______¶¶¶___
____¶¶¶______¶¶¶_____________¶¶¶______¶¶¶____
_____¶¶¶______¶¶¶¶¶¶_____¶¶¶¶¶¶______¶¶¶_____
______¶¶¶______¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶______¶¶¶______
_______¶¶¶¶________¶¶¶¶¶¶¶________¶¶¶¶_______
________¶¶¶¶¶___________________¶¶¶¶¶________
___¶¶¶¶___¶¶¶¶¶¶_____________¶¶¶¶¶¶___¶¶¶¶___
__¶¶¶¶¶¶¶____¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶____¶¶¶¶¶¶¶¶_
__¶¶¶___¶¶¶______¶¶¶¶¶¶¶¶¶¶¶______¶¶¶¶___¶¶¶_
__¶¶_____¶¶¶¶___________________¶¶¶¶______¶¶_
You are loosing! "

elsif @guesses_counter == 4
puts "
_____________________________________________
_________________¶¶¶¶¶¶¶¶¶¶¶_________________
____________¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶____________
__________¶¶¶¶¶¶_____________¶¶¶¶¶¶__________
________¶¶¶¶¶___________________¶¶¶¶¶________
_______¶¶¶¶_______________________¶¶¶¶_______
______¶¶¶___________________________¶¶¶______
_____¶¶¶______¶¶¶¶¶_______¶¶¶¶¶______¶¶¶_____
____¶¶¶______¶¶¶¶¶¶_______¶¶¶¶¶¶______¶¶¶____
___¶¶¶_______¶¶¶¶¶¶_______¶¶¶¶¶¶_______¶¶¶___
___¶¶¶________¶¶¶¶_________¶¶¶¶________¶¶¶___
___¶¶___________________________________¶¶___
___¶¶___________________________________¶¶___
___¶¶______¶¶___________________¶¶______¶¶___
___¶¶¶_____¶¶___________________¶¶_____¶¶¶___
___¶¶¶______¶¶_________________¶¶______¶¶¶___
____¶¶¶______¶¶¶_____________¶¶¶______¶¶¶____
_____¶¶¶______¶¶¶¶¶¶_____¶¶¶¶¶¶______¶¶¶_____
______¶¶¶______¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶______¶¶¶______
_______¶¶¶¶________¶¶¶¶¶¶¶________¶¶¶¶_______
________¶¶¶¶¶___________________¶¶¶¶¶________
___¶¶¶¶___¶¶¶¶¶¶_____________¶¶¶¶¶¶___¶¶¶¶___
__¶¶¶¶¶¶¶____¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶____¶¶¶¶¶¶¶¶_
__¶¶¶___¶¶¶______¶¶¶¶¶¶¶¶¶¶¶______¶¶¶¶___¶¶¶_
__¶¶_____¶¶¶¶___________________¶¶¶¶______¶¶_
___¶¶¶_____¶¶¶¶¶____________¶¶¶¶¶¶______¶¶¶__
__¶¶¶________¶¶¶¶¶¶¶____¶¶¶¶¶¶¶¶_________¶¶¶_
¶¶¶______________¶¶¶¶¶¶¶¶¶¶¶______________¶¶¶
¶¶¶___¶¶¶¶¶¶________¶¶¶¶________¶¶¶¶¶¶¶___¶¶¶
_¶¶¶¶¶¶____¶¶¶¶¶¶___________¶¶¶¶¶____¶¶¶¶¶¶¶_
_____________¶¶¶¶¶¶_______¶¶¶¶¶¶_____________
___________¶¶¶¶¶¶___________¶¶¶¶¶____________
_______¶¶¶¶¶¶¶______¶¶¶¶¶_______¶¶¶¶¶________
------>> You will loose!"

elsif @guesses_counter == 5
puts "
_____________________________________________
_________________¶¶¶¶¶¶¶¶¶¶¶_________________
____________¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶____________
__________¶¶¶¶¶¶_____________¶¶¶¶¶¶__________
________¶¶¶¶¶___________________¶¶¶¶¶________
_______¶¶¶¶_______________________¶¶¶¶_______
______¶¶¶___________________________¶¶¶______
_____¶¶¶______¶¶¶¶¶_______¶¶¶¶¶______¶¶¶_____
____¶¶¶______¶¶¶¶¶¶_______¶¶¶¶¶¶______¶¶¶____
___¶¶¶_______¶¶¶¶¶¶_______¶¶¶¶¶¶_______¶¶¶___
___¶¶¶________¶¶¶¶_________¶¶¶¶________¶¶¶___
___¶¶___________________________________¶¶___
___¶¶___________________________________¶¶___
___¶¶______¶¶___________________¶¶______¶¶___
___¶¶¶_____¶¶____________________¶¶_____¶¶¶___
___¶¶¶______¶¶_________________¶¶______¶¶¶___
____¶¶¶______¶¶¶_____________¶¶¶______¶¶¶____
_____¶¶¶______¶¶¶¶¶¶_____¶¶¶¶¶¶______¶¶¶_____
______¶¶¶______¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶______¶¶¶______
_______¶¶¶¶________¶¶¶¶¶¶¶________¶¶¶¶_______
________¶¶¶¶¶___________________¶¶¶¶¶________
___¶¶¶¶___¶¶¶¶¶¶_____________¶¶¶¶¶¶___¶¶¶¶___
__¶¶¶¶¶¶¶____¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶____¶¶¶¶¶¶¶¶_
__¶¶¶___¶¶¶______¶¶¶¶¶¶¶¶¶¶¶______¶¶¶¶___¶¶¶_
__¶¶_____¶¶¶¶___________________¶¶¶¶______¶¶_
___¶¶¶_____¶¶¶¶¶____________¶¶¶¶¶¶______¶¶¶__
__¶¶¶________¶¶¶¶¶¶¶____¶¶¶¶¶¶¶¶_________¶¶¶_
¶¶¶______________¶¶¶¶¶¶¶¶¶¶¶______________¶¶¶
¶¶¶___¶¶¶¶¶¶________¶¶¶¶________¶¶¶¶¶¶¶___¶¶¶
_¶¶¶¶¶¶____¶¶¶¶¶¶___________¶¶¶¶¶____¶¶¶¶¶¶¶_
_____________¶¶¶¶¶¶_______¶¶¶¶¶¶_____________
___________¶¶¶¶¶¶___________¶¶¶¶¶____________
_______¶¶¶¶¶¶¶______¶¶¶¶¶_______¶¶¶¶¶________
__¶¶¶¶¶¶¶¶¶______¶¶¶¶¶¶¶¶¶¶¶______¶¶¶¶¶¶¶¶¶__
¶¶¶¶¶¶_________¶¶¶¶¶_____¶¶¶¶¶__________¶¶¶¶¶
¶¶¶__________¶¶¶¶__________¶¶¶¶¶__________¶¶¶
¶¶_________¶¶¶¶______________¶¶¶¶¶________¶¶¶
¶¶¶¶¶______¶¶__________________¶¶¶_______¶¶¶¶
_¶¶¶¶¶____¶¶¶___________________¶¶¶____¶¶¶¶¶_
_____¶¶¶¶¶¶¶_____________________¶¶¶¶¶¶¶¶____

--------->>>> Game Over!!!
".colorize(:red).bold.blink
puts "THE WORD WAS: #{@word}".bold.colorize(:blue)
end
end

# This method displays the image and win message when the user wins.S
def you_win
puts "
_____________________________________________
_________________¶¶¶¶¶¶¶¶¶¶¶_________________
____________¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶____________
__________¶¶¶¶¶¶_____________¶¶¶¶¶¶__________
________¶¶¶¶¶___________________¶¶¶¶¶________
_______¶¶¶¶_______________________¶¶¶¶_______
______¶¶¶___________________________¶¶¶______
_____¶¶¶______¶¶¶¶¶_______¶¶¶¶¶______¶¶¶_____
____¶¶¶______¶¶¶¶¶¶_______¶¶¶¶¶¶______¶¶¶____
___¶¶¶_______¶¶¶¶¶¶_______¶¶¶¶¶¶_______¶¶¶___
___¶¶¶________¶¶¶¶_________¶¶¶¶________¶¶¶___
___¶¶___________________________________¶¶___
___¶¶___________________________________¶¶___
___¶¶______¶¶___________________¶¶______¶¶___
___¶¶¶_____¶¶___________________¶¶_____¶¶¶___
___¶¶¶______¶¶_________________¶¶______¶¶¶___
____¶¶¶______¶¶¶_____________¶¶¶______¶¶¶____
_____¶¶¶______¶¶¶¶¶¶_____¶¶¶¶¶¶______¶¶¶_____
______¶¶¶______¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶______¶¶¶______
_______¶¶¶¶________¶¶¶¶¶¶¶________¶¶¶¶_______
________¶¶¶¶¶___________________¶¶¶¶¶________
__________¶¶¶¶¶¶_____________¶¶¶¶¶¶__________
____________¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶______________


----->> You WIN!!!".colorize(:green).blink

end
end


WordGuess.new
Loading