forked from AdaGold/word-guess
-
Notifications
You must be signed in to change notification settings - Fork 25
Tanja and Gale WordGuess #14
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
misstonbon
wants to merge
20
commits into
Ada-C8:master
Choose a base branch
from
misstonbon: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
20 commits
Select commit
Hold shift + click to select a range
a25aa26
Initial upload
misstonbon 31d1c7c
learning git
misstonbon 12393a0
method for underscores to appear in array works
misstonbon 5758c3e
adding reveal method but have to figure out how to scan each index
misstonbon 55b845c
Figured out how to replace element of the array from underscore to le…
misstonbon 86686bf
add def reveal and it works and replaces
misstonbon 95cc3e4
added game class that needs work
misstonbon 4f7fd93
reworked bad guesses added more functionality
misstonbon 1ca8485
small change in string
misstonbon 4709c9c
bad letter added
misstonbon c57c985
displays wrong letters
misstonbon 45a1177
added faker
misstonbon f8b5666
hipster complete
misstonbon cfe129a
Fixed number of guesses allowed and added hipster lingo
misstonbon 1c12fc0
cleaned up some comments
misstonbon 0cc1e90
some styling
misstonbon ba9b51e
changed attr and some wording
misstonbon 05c3d5a
change attr for Art class
misstonbon f3bdd2b
added quotes
misstonbon d277b43
final edit refactored and updated wording
misstonbon 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,247 @@ | ||
| require 'faker' | ||
| require 'colorize' | ||
|
|
||
| class Word | ||
| attr_reader :random_word, :word_display, :changed | ||
|
|
||
| def initialize(random_word) | ||
| @random_word = random_word.split("") | ||
| @word_display = Array.new(random_word.length, "_ ") | ||
| end | ||
|
|
||
| def reveal(guess) | ||
| counter = 0 #keeps track of random_word array index number | ||
| @changed = nil | ||
| @random_word.each do |char| | ||
| if char == guess | ||
| @word_display[counter] = guess | ||
| @changed = true | ||
| end | ||
| counter += 1 | ||
| end | ||
| return @word_display | ||
| end | ||
|
|
||
| def changed? #keeps track of whether word_display changed i.e. whether the guess was right | ||
| return @changed | ||
| end | ||
| end | ||
|
|
||
| class Art | ||
| attr_reader :part1, :part2, :part3, :part4, :part5, :part6, :part7 | ||
|
|
||
| def initialize | ||
| @part1 = " .... .... | ||
| ... . . ......... .. . .. . ......... .. . . | ||
| MMMMMMMMM8I~....:~7DMMMMMMMMMDDMMMMMMMMM$+~~~~~IOMMMMMMMMMM. | ||
| MMMMM=. ...MMMMMMMMMMN.. . . MMMMMM. " | ||
| @part2 = " .... .... | ||
| ... . . ......... .. . .. . ......... .. . . | ||
| MMMMMMMMM8I~....:~7DMMMMMMMMMDDMMMMMMMMM$+~~~~~IOMMMMMMMMMM. | ||
| MMMMM=. ...MMMMMMMMMMN.. . . MMMMMM. | ||
| .MMMM DMMMMMMM7 MMMM~ | ||
| MMN .~MM .:MM ..MMM | ||
| .MM .IM?...NM. ..MM . | ||
| :M .MM. ..M8 .,M. " | ||
| @part3 = " .... .... | ||
| ... . . ......... .. . .. . ......... .. . . | ||
| MMMMMMMMM8I~....:~7DMMMMMMMMMDDMMMMMMMMM$+~~~~~IOMMMMMMMMMM. | ||
| MMMMM=. ...MMMMMMMMMMN.. . . MMMMMM. | ||
| .MMMM DMMMMMMM7 MMMM~ | ||
| MMN .~MM .:MM ..MMM | ||
| .MM .IM?...NM. ..MM . | ||
| :M .MM. ..M8 .,M. | ||
| MM.. .M,. . 8M.. .MM. | ||
| .M$. ,MZ.. .MM. ..OM.. | ||
| MM.... ......,M?. MM.... .......MM | ||
| 8MM+.........MMM. . MM?... .....MM8.. " | ||
| @part4 = " .... .... | ||
| ... . . ......... .. . .. . ......... .. . . | ||
| MMMMMMMMM8I~....:~7DMMMMMMMMMDDMMMMMMMMM$+~~~~~IOMMMMMMMMMM. | ||
| MMMMM=. ...MMMMMMMMMMN.. . . MMMMMM. | ||
| .MMMM DMMMMMMM7 MMMM~ | ||
| MMN .~MM .:MM ..MMM | ||
| .MM .IM?...NM. ..MM . | ||
| :M .MM. ..M8 .,M. | ||
| MM.. .M,. . 8M.. .MM. | ||
| .M$. ,MZ.. .MM. ..OM.. | ||
| MM.... ......,M?. MM.... .......MM | ||
| 8MM+.........MMM. . MM?... .....MM8.. | ||
| ...ZMMMMN$..... ...?MMMMMMM=.... | ||
|
|
||
| . .. ... . . | ||
| MMMMMMM .MMMMMMM " | ||
| @part5 = " .... .... | ||
| ... . . ......... .. . .. . ......... .. . . | ||
| MMMMMMMMM8I~....:~7DMMMMMMMMMDDMMMMMMMMM$+~~~~~IOMMMMMMMMMM. | ||
| MMMMM=. ...MMMMMMMMMMN.. . . MMMMMM. | ||
| .MMMM DMMMMMMM7 MMMM~ | ||
| MMN .~MM .:MM ..MMM | ||
| .MM .IM?...NM. ..MM . | ||
| :M .MM. ..M8 .,M. | ||
| MM.. .M,. . 8M.. .MM. | ||
| .M$. ,MZ.. .MM. ..OM.. | ||
| MM.... ......,M?. MM.... .......MM | ||
| 8MM+.........MMM. . MM?... .....MM8.. | ||
| ...ZMMMMN$..... ...?MMMMMMM=.... | ||
|
|
||
| . .. ... . . | ||
| MMMMMMM .MMMMMMM | ||
| .... MMMMMMMMMMMMMMMMMMMMM .... | ||
| MM..?. ..,MMMMMMMMMMMMMMMMMMMMMMMMM. $..MM | ||
| .MM. . .NMMMMMMMMMMMMMMMMMMMMMMMMMMMM.. ....MM . | ||
| MMM. .?MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM~.....MM? " | ||
| @part6 = " .... .... | ||
| ... . . ......... .. . .. . ......... .. . . | ||
| MMMMMMMMM8I~....:~7DMMMMMMMMMDDMMMMMMMMM$+~~~~~IOMMMMMMMMMM. | ||
| MMMMM=. ...MMMMMMMMMMN.. . . MMMMMM. | ||
| .MMMM DMMMMMMM7 MMMM~ | ||
| MMN .~MM .:MM ..MMM | ||
| .MM .IM?...NM. ..MM . | ||
| :M .MM. ..M8 .,M. | ||
| MM.. .M,. . 8M.. .MM. | ||
| .M$. ,MZ.. .MM. ..OM.. | ||
| MM.... ......,M?. MM.... .......MM | ||
| 8MM+.........MMM. . MM?... .....MM8.. | ||
| ...ZMMMMN$..... ...?MMMMMMM=.... | ||
|
|
||
| . .. ... . . | ||
| MMMMMMM .MMMMMMM | ||
| .... MMMMMMMMMMMMMMMMMMMMM .... | ||
| MM..?. ..,MMMMMMMMMMMMMMMMMMMMMMMMM. $..MM | ||
| .MM. . .NMMMMMMMMMMMMMMMMMMMMMMMMMMMM.. ....MM . | ||
| MMM. .?MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM~.....MM? | ||
| .MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM . | ||
| .MMMMMMMMMMMMMMMMMMMMMM8 NMMMMMMMMMMMMMMMMMMMMMM | ||
| . 7MMMMMMMMMMMMMMMMM. . :MMMMMMMMMMMMMMMMM? | ||
| ...=I77?=, . .:=I77+~ " | ||
| @part7 = " .... .... | ||
| ... . . ......... .. . .. . ......... .. . . | ||
| MMMMMMMMM8I~....:~7DMMMMMMMMMDDMMMMMMMMM$+~~~~~IOMMMMMMMMMM. | ||
| MMMMM=. ...MMMMMMMMMMN.. . . MMMMMM. | ||
| .MMMM DMMMMMMM7 MMMM~ | ||
| MMN .~MM .:MM ..MMM | ||
| .MM .IM?...NM. ..MM . | ||
| :M .MM. ..M8 .,M. | ||
| MM.. .M,. . 8M.. .MM. | ||
| .M$. ,MZ.. .MM. ..OM.. | ||
| MM.... ......,M?. MM.... .......MM | ||
| 8MM+.........MMM. . MM?... .....MM8.. | ||
| ...ZMMMMN$..... ...?MMMMMMM=.... | ||
|
|
||
| . .. ... . . | ||
| MMMMMMM .MMMMMMM | ||
| .... MMMMMMMMMMMMMMMMMMMMM .... | ||
| MM..?. ..,MMMMMMMMMMMMMMMMMMMMMMMMM. $..MM | ||
| .MM. . .NMMMMMMMMMMMMMMMMMMMMMMMMMMMM.. ....MM . | ||
| MMM. .?MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM~.....MM? | ||
| .MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM . | ||
| .MMMMMMMMMMMMMMMMMMMMMM8 NMMMMMMMMMMMMMMMMMMMMMM | ||
| . 7MMMMMMMMMMMMMMMMM. . :MMMMMMMMMMMMMMMMM? | ||
| ...=I77?=, . .:=I77+~ | ||
| .. . . .... . . | ||
| .... | ||
| " | ||
| end | ||
|
|
||
| def display(num_good_guess) | ||
| case num_good_guess | ||
| when 1 | ||
| return @part1 | ||
| when 2 | ||
| return @part2 | ||
| when 3 | ||
| return @part3 | ||
| when 4 | ||
| return @part4 | ||
| when 5 | ||
| return @part5 | ||
| when 6 | ||
| return @part6 | ||
| when 7 | ||
| return @part7 | ||
| end | ||
| end | ||
|
|
||
| end | ||
|
|
||
| class Game | ||
|
|
||
| def initialize | ||
| @word = Word.new(Faker::Hipster.unique.word.downcase) | ||
| @bad_guess_allowed = 7 | ||
| @num_bad_guess = 0 | ||
| @num_good_guess = 0 | ||
| @bad_letters = [] | ||
| end | ||
|
|
||
| def count_bad_guess(guess) | ||
| unless guess == @word.random_word.join("") | ||
| if @changed == nil | ||
| @num_bad_guess += 1 | ||
| @bad_letters << guess | ||
| puts "\n\nFutile attempts: #{@num_bad_guess}" | ||
| puts "You’ve already tried: #{@bad_letters.join(", ")}" | ||
| end | ||
| return @num_bad_guess | ||
| end | ||
| end | ||
|
|
||
| def count_good_guess | ||
| if @changed == true | ||
| @num_good_guess += 1 #stores how many good guesses has taken so Art.display can show that many parts of the image | ||
| puts "\n\nGood guess! You're on a roll!" | ||
| puts "You’ve already tried: #{@bad_letters.join(", ")}" | ||
| end | ||
| return @num_good_guess | ||
| end | ||
|
|
||
| def play | ||
|
|
||
| while true | ||
| print "\nGo! " | ||
| print ">> ".blink | ||
| guess = gets.chomp.downcase | ||
| print @word.reveal(guess).join | ||
| @changed = @word.changed? | ||
| @num_bad_guess = count_bad_guess(guess) | ||
| @num_good_guess = count_good_guess | ||
| puts Art.new.display(@num_good_guess) | ||
| if @word.random_word == @word.word_display || guess == @word.random_word.join("") | ||
| #check for the ‘win condition’ | ||
| puts Art.new.display(7).blue.blink | ||
| puts "\nLook at you: you guessed the word and looked good doing it! They're vintage." | ||
| break | ||
| end | ||
| if @num_bad_guess == @bad_guess_allowed #if this happens before the win condition is satisfied, you lose :( | ||
| puts "\nUh-oh! You're out of guesses. The word was ‘#{@word.random_word.join("").capitalize}‘. I used this word for months before it was even cool." | ||
| puts Art.new.display(7).red.blink | ||
| break | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| let_me_help_you = [ | ||
| "Not to be a conformist, but there is only one right way to prep chai.", | ||
| "Nope! Hint: You can get a gallon of it at Trader Joe’s, but I doubt it’s organic.", | ||
| "That’s not niche enough." | ||
| ] | ||
| puts "This hang-man game is elite and invite-only (requires a password).\nHow do you take your vegan chai?" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I LOVE THIS. At first I didn't know the answer and typed "hot...?" |
||
| puts ">".blue.blink | ||
| password = gets.chomp.downcase | ||
| until password == "dirty" | ||
| puts "#{let_me_help_you.sample.red}" | ||
| password = gets.chomp.downcase | ||
| end | ||
| if password == "dirty" | ||
| puts "Righteous! | ||
| Welcome to the game! Every word is sourced locally and responsibly. | ||
| If we had to classify it, it would be Avant-garde. | ||
| You get 7 guesses, 7 just feels right. | ||
| You can also type the entire word. | ||
| This way you win the game, but the word immediately becomes too mainstream. | ||
| Please begin:".green | ||
|
|
||
| Game.new.play | ||
| 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.
It would probably be fine to set
@changedto false instead of nil