forked from AdaGold/word-guess
-
Notifications
You must be signed in to change notification settings - Fork 25
Create CanaanAndAmy #21
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
canaanwest
wants to merge
1
commit into
Ada-C8:master
Choose a base branch
from
canaanwest:patch-1
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
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,177 @@ | ||
|
|
||
| require "colorize" | ||
| require "faker" | ||
|
|
||
| class ASCII_display | ||
| attr_reader :ASCII_init, :displayed | ||
| def initialize | ||
| @ASCII_init = [" @ . . @".green, " ( --- )".green, " ( >__< )".green, " ^^ ~~ ^^".green, " ~~~~~~~~~~~".green, " ~~~~~~~~~".green] | ||
| @displayed = display_picture(@ASCII_init) | ||
| end | ||
|
|
||
| def display_picture(picture) | ||
| picture.each do |line| | ||
| puts "#{line} \n" | ||
| end | ||
| end | ||
|
|
||
| def update_ASCII_display | ||
| return @ASCII_init.delete(@ASCII_init[-1]) | ||
| end | ||
| end #End of ASCII_display class | ||
|
|
||
| class Game | ||
| attr_reader :word_array, :status, :letters, :attempts, :picture, :right_or_wrong_guess, :category | ||
| attr_accessor :word, :chosen_category | ||
|
|
||
| def initialize | ||
| @category= {"color" => Faker::Color.color_name, "dessert" => Faker::Dessert.variety, "pokemon" => Faker::Pokemon.name, "family guy" => Faker::FamilyGuy.character, "hipster" => Faker::Hipster.word} | ||
| @attempts= [] | ||
| @picture = ASCII_display.new | ||
| end | ||
|
|
||
| def make_word_array | ||
| @word.slice!(" ") | ||
| @word_array = @word.split("") | ||
| @letters = put_spaces(@word) | ||
| end | ||
|
|
||
| def show_display | ||
| puts "[Category: #{@chosen_category.upcase}] \n\n" | ||
| puts @picture.displayed | ||
| puts "#{@letters}\n\n" | ||
| puts "You've guessed: #{@attempts} \n" | ||
| end | ||
|
|
||
| def status_update(guess) | ||
| @attempts.push(guess) | ||
| if @letters.split(" ").join("") == @word || guess == @word | ||
| @status = "win" | ||
| elsif @picture.ASCII_init.length == 0 #we can change default later | ||
| @status = "lose" | ||
| else | ||
| @status = "in progress" | ||
| end | ||
| return @status | ||
| end | ||
|
|
||
| #### AL optional reorganization below + colorize texts below#### | ||
| def right_or_wrong_guess(guess) | ||
| flag = false | ||
| puts "\e[H\e[2J" #I like this edit | ||
|
|
||
| if guess == @word # new, special statement for if they guess the correct word | ||
| flag = true | ||
| puts "YOU GOT IT!".colorize(:color => :white, :background => :light_magenta) | ||
| elsif | ||
| @word_array.each_index do |index| | ||
| if @word_array[index] == guess | ||
| @letters[index*2] = guess | ||
| flag = true | ||
| end | ||
| end | ||
| end | ||
|
|
||
| if flag == false | ||
| puts "You guessed" + " wrong".red + ", sucker!" | ||
| @picture.update_ASCII_display | ||
| else | ||
| puts "Good job!".green + " You got one!" | ||
| end | ||
|
|
||
| status_update(guess) | ||
| show_display | ||
| end | ||
|
|
||
| private | ||
| def put_spaces(word) | ||
| spaces = [] | ||
| word.length.times do |space| | ||
| spaces.push("_") | ||
| end | ||
| return spaces.join(" ") | ||
| end | ||
| end # END GAME CLASS | ||
|
|
||
| #USER | ||
| def valid_guess(guess, game) | ||
| while guess == guess.to_i.to_s | ||
| puts "Please enter a letter or a word." | ||
| guess = gets.chomp.downcase | ||
| end | ||
| while game.attempts.include?(guess) | ||
| puts "You already guessed that! Try again!" | ||
| guess = gets.chomp.downcase | ||
| end | ||
| return guess | ||
| end | ||
|
|
||
| def valid_category(user_category, game) | ||
| until game.category.keys.include?(user_category) | ||
| puts "I'm sorry, that's not a valid category selection. Please choose one of the following categories: #{game.category.keys.join(", ")}" | ||
| user_category = gets.chomp.downcase | ||
| end | ||
| game.chosen_category = user_category | ||
| return user_category | ||
| end | ||
|
|
||
| def user_guesses(game) | ||
| puts "Pick a letter, dash, or apostrophe." | ||
| guess = gets.chomp.downcase | ||
| guess = valid_guess(guess, game) | ||
| return guess | ||
| end | ||
|
|
||
| def check(game, guess) | ||
| game.right_or_wrong_guess(guess) | ||
| end | ||
|
|
||
| def game_over?(status, game) | ||
| over = false | ||
| if status == "win" | ||
| puts "\n \u{1F438} \u{1F31F} \u{1F913} YOU WIN! \u{1F913} \u{1F31F} \u{1F438}".green.blink | ||
| over = true | ||
| $winning_streak += 1 #if they win, it goes up by one | ||
| elsif status == "lose" | ||
| puts "\n \u{2620} YOU LOSE!\u{2620} ".red.blink + "\nThe word was: " + "#{game.word}".red + "\n" | ||
| over = true | ||
| $winning_streak = 0 #if they lose, it resets to 0 | ||
| end | ||
| return over | ||
| end | ||
|
|
||
| #INTERFACE!!!! | ||
| $winning_streak = 0 #starts off at 0 | ||
| continue = nil | ||
| until continue == "no" | ||
| game1 = Game.new | ||
| puts "Welcome to Word Guess! Your category choices are: \n" | ||
| puts game1.category.keys | ||
|
|
||
| puts "\nWhich category would you like?" | ||
| user_category = gets.chomp.downcase | ||
| user_category = valid_category(user_category, game1) | ||
|
|
||
| puts "\e[H\e[2J" | ||
| game1.word = game1.category[user_category].downcase | ||
| game1.make_word_array | ||
| game1.show_display | ||
|
|
||
|
|
||
| until game_over?(game1.status, game1) | ||
| check(game1, user_guesses(game1)) | ||
| end | ||
|
|
||
| puts "Your winning streak is: #{$winning_streak}\n".yellow #displays here just before asking to play again | ||
| puts "Would you like to play again? (yes/no)" #ask user if they want to continue | ||
| continue = gets.chomp.downcase | ||
|
|
||
| until continue == "yes" || continue == "no" | ||
| puts "Please select 'yes' or 'no'" | ||
| continue = gets.chomp.downcase | ||
| end | ||
|
|
||
| puts "\e[H\e[2J" | ||
| end | ||
|
|
||
| puts "\u{1F438} \u{1F438} \u{1F438} Thanks for playing our word game! \u{1F438} \u{1F438} \u{1F438}" | ||
|
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. nice emoji! |
||
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.
probably not necessary to make
@displayed = display_picture()and just call.display_picture()instead of.displayedon line 41