forked from AdaGold/word-guess
-
Notifications
You must be signed in to change notification settings - Fork 25
Kimberley M & Isabel S - Carets #17
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
Open
kimberleyamackenzie
wants to merge
13
commits into
Ada-C8:master
Choose a base branch
from
kimberleyamackenzie:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5be406f
Initial file with Word & Game classes -KM
kimberleyamackenzie 130eada
I forgot to save last commit! -KM
kimberleyamackenzie 8683c70
Added more methods to Game and Word classes [IS]
kimberleyamackenzie fa6ffba
The blanks work.
kimberleyamackenzie 2751625
Added whole word functionality.
kimberleyamackenzie 668f09a
Added ascii art functionality reading from file and decomposing based…
kimberleyamackenzie 90e9417
UI changes and finished ascii art -KM
kimberleyamackenzie 57d76c9
Difficulty functionality, loss ascii -KM
kimberleyamackenzie 81f02ec
ascii art file that the main program reads from.
kimberleyamackenzie 2d95dcf
Fixed bug where two word strings were generated.
kimberleyamackenzie b723883
Added colorize to initial image & added picture print out for a corre…
kimberleyamackenzie be565f2
Spacing.
kimberleyamackenzie f6aadca
Added colorize to partial image print and print out word even when gu…
kimberleyamackenzie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| ,`', . | ||
| . . -` - .+ | ||
| . . + ~,(.~ .* . | ||
| . . . ).._ . . | ||
| * .:::::%% . | ||
| . :::;;%%%$ | ||
| :::::;%%$ . | ||
| :%::%:;%$ | ||
| .:%::::;%$ | ||
| `"%:::;;$$ | ||
| ___ %:::;%%$ ___ | ||
| .--~'^ %:;:%%$$ ^`~--. | ||
| .:' `^""""^' `. | ||
| ( `~ - ,. _ _ _ _ . ,- ~`:. | ||
| `: `~~~~' : | ||
| |:_.'`: .. ) | ||
| `|%%%%`; .-,. ,-'##`._.' | ||
| |:%%%%$`:.,/'$$$`: ,;#######| | ||
| `|:%%%%%%$$$%$$$$$`~'$#######|' | ||
| ___,--`|%%%%$%%%$$$$$#$$#$#######|'---,___ | ||
| __,~~~ |:%%%%%$%$%$$$$$$$########| ~~~-.. | ||
| .-~^ `|%%%%$%%%$$$$$#$########|' ~-,_ | ||
| ( `^^-%%%$$%$$$$$####-^^' :. | ||
| :; | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| require 'faker' | ||
| require 'artii' | ||
| require 'colorize' | ||
|
|
||
| class Word | ||
|
|
||
| attr_reader :word, :letters, :blanks | ||
|
|
||
| def initialize(word: Faker::Dessert.variety.downcase.sub(" ", "")) | ||
| @word = word | ||
| @letters = word.split("") | ||
| @letters << @word | ||
| @blanks = "-" * (@letters.length - 1) | ||
| end | ||
|
|
||
| def contains?(letter_guess) | ||
| return @letters.include?(letter_guess) | ||
| end | ||
|
|
||
| def replace_blanks(letter_guess) | ||
| indices = find_indices(letter_guess) | ||
| indices.each do |index| | ||
| @blanks[index] = letter_guess | ||
| end | ||
| puts @blanks | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def find_indices(letter_guess) | ||
| indices = [] | ||
|
|
||
| (0..@letters.length).each do |index| | ||
| if letter_guess == @letters[index] | ||
| indices << index | ||
| end | ||
| end | ||
|
|
||
| return indices | ||
| end | ||
|
|
||
| end #end of class | ||
|
|
||
| class Game | ||
|
|
||
| attr_reader :game_word, :guesses, :turns | ||
| attr_writer :game_word | ||
|
|
||
| def initialize | ||
| #@art = newart | ||
| @game_word = Word.new | ||
| @guesses = [] | ||
| @turns = 0 | ||
| end | ||
|
|
||
| def difficulty | ||
| user_level = "" | ||
| until user_level == "high" || user_level == "medium" || user_level == "easy" | ||
| puts "What level of challenge do you want? You may choose high, medium, or easy." | ||
| user_level = gets.chomp.downcase | ||
| end | ||
|
|
||
| difficulty = "" | ||
|
|
||
| until difficulty == user_level | ||
| @game_word = Word.new | ||
| word = @game_word | ||
|
|
||
| if word.word.length > 8 | ||
| difficulty = "high" | ||
| elsif word.word.length <=8 && word.word.length > 5 | ||
| difficulty = "medium" | ||
| else | ||
| difficulty = "easy" | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def guess(user_guess) | ||
| while user_guess.match(/[^a-z]/) | ||
| puts "\nPlease return a valid letters from A to Z.\n" | ||
| user_guess = gets.chomp.downcase | ||
| end | ||
| if @guesses.include?(user_guess) | ||
| puts "\nYou guessed that letter already!" | ||
| return | ||
| end | ||
| if @game_word.word == user_guess | ||
| you_won | ||
| end | ||
| if @game_word.contains?(user_guess) | ||
| reveal(user_guess) | ||
| win? | ||
| else | ||
| puts "\nSorry, that letter is not in your word.\nThere goes some delicious cupcake...\n\n" | ||
| @turns += 1 | ||
| lose? | ||
| puts "Here's your word so far: \n #{@game_word.blanks}" | ||
| end | ||
| decompose_image | ||
| @guesses << user_guess | ||
| end | ||
|
|
||
| def print_guesses | ||
| if @guesses.length > 0 | ||
| guess_string = "" | ||
| @guesses.each do |guess| | ||
| guess_string += guess.upcase + " " | ||
| end | ||
| puts "\nHere's what you have guessed so far: #{guess_string}" | ||
| end | ||
| end | ||
|
|
||
| def reveal(user_guess) | ||
| puts "\nYes! Here's your word so far:\n" | ||
| @game_word.replace_blanks(user_guess) | ||
| @game_word.blanks | ||
| end | ||
|
|
||
| def lose? | ||
| if @turns == 5 | ||
| artii = Artii::Base.new :font => 'slant' | ||
| artii = artii.asciify("You LOST!") | ||
| puts artii.colorize(:red) | ||
| puts "Your word was #{@game_word.word}" | ||
| exit | ||
| end | ||
| end | ||
|
|
||
| def win? | ||
| if !@game_word.blanks.include?("-") | ||
| you_won | ||
| end | ||
| end | ||
|
|
||
| def you_won | ||
| artii = Artii::Base.new :font => 'slant' | ||
| artii = artii.asciify("You WIN!") | ||
| puts artii.colorize(:blue).blink | ||
| exit | ||
| end | ||
| end # end of class | ||
|
|
||
| # Ascii Art Methods | ||
| def ascii | ||
| file = File.open("/Users/kimberley/Desktop/asciiartfile.txt", "r") | ||
| contents = file.read | ||
| puts contents.colorize(:magenta) | ||
| end | ||
|
|
||
| def decompose_image | ||
| line_limit = [25, 20, 15, 10, 5] | ||
| index = (@turns) | ||
| partial_image = IO.readlines("/Users/kimberley/Desktop/asciiartfile.txt")[1...line_limit[index]].join | ||
| puts partial_image.colorize(:magenta) | ||
| end | ||
|
|
||
| # Begin game play | ||
| game = Game.new | ||
|
|
||
| # Explain rules to players | ||
| puts "Welcome to FILL IN THE BLANKS, an extra sweet word guess game!" | ||
| puts "\nRULES: \n--Each blank represents one letter of the word \n--Your guess can be one letter or the whole word \n--If you're right, those letters will be revealed \n--If you're wrong, your cupcake will start to melt \n--When your cupcake is a puddle of sugar, you lose.\n\n" | ||
|
|
||
| # Find out & assign difficult level of user's choice | ||
| game.difficulty | ||
|
|
||
| # Print ascii image and begin game play | ||
| ascii | ||
| puts "Your mystery word is (drumroll, please...)\n #{game.game_word.blanks}" | ||
|
|
||
| until game.win? || game.lose? | ||
| game.print_guesses | ||
| puts "What's your guess?" | ||
| guess = gets.chomp.downcase | ||
| game.guess(guess) | ||
| end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can place a relative path to this file with just
file = File.open("asciiartfile.txt", "r")and it assumes that the file is in the same directory as this (word-guess.rb). Same as line 154