forked from AdaGold/word-guess
-
Notifications
You must be signed in to change notification settings - Fork 25
Bear Bandit Word Guess #23
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
skwiens
wants to merge
14
commits into
Ada-C8:master
Choose a base branch
from
skwiens: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
14 commits
Select commit
Hold shift + click to select a range
9d12bae
[#JE/SW] Initial commit
skwiens 161faa9
[JE/SW] made initial classes
skwiens 18b8e8f
"[JE/SW] DAY 1: Introduction"
skwiens 94f7962
[JE/SW] Game Class completed, Working on Card Class
skwiens 4bedd01
[JE/SW] Completed Card Class basic methods, still needing loops and u…
skwiens 300a7b3
[JE/SW] We did a lot! Now it's late and we're going home. Tomorrow: h…
skwiens 5ace97b
[JE/SW] Combined classes to just one. Working on level choice.
skwiens 22c8a99
[JE/SW] Committing check_guess version where it compares @guess.length
skwiens 85c33ec
[JE/SW] working on running easy method through class
skwiens 42336f1
[JE/SW] wrote easy loop block of code
skwiens eebc267
[JE/SW] IT RUNS! IT RUNS! (We need Ascii art... and a table...)
skwiens 7e4132e
[JE/SW] now prompts user to enter a new answer if they put in a number
skwiens 8d0a87e
[JE/SW] Final version including word art, table and spacing
skwiens 15f77b1
[JE/SW] Ascii art file
skwiens 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,204 @@ | ||
| #This is the word-guess project | ||
|
|
||
| require 'colorize' | ||
| require './word_guess_asciiart.rb' | ||
| require 'terminal-table' | ||
|
|
||
| #One class to monitor the game | ||
| class WordGame | ||
|
|
||
| attr_reader :word, :word_showing, :letters_guessed, :words_guessed, :level_choice | ||
|
|
||
| attr_accessor :stop_guessing, :guesses_remaining | ||
|
|
||
| def initialize | ||
| @word_bank = %W[APPLE SANDWICH PICNIC BASKET ANTS BLANKET IDYLLIC MOUNTAINS LAKE SUMMER FRIENDS FAMILY FUN NATURE TREES SUN] | ||
| @level_choice = get_level | ||
| @word = @word_bank.sample #generates the word | ||
| @guess = nil #guess is the variable to store user input | ||
| @word_showing = build_blank_word_array | ||
| @word_array = @word.split("") #Check at end if this is used more than in the guess method... if not... delete! | ||
| @letters_guessed = [] | ||
| @words_guessed = [] | ||
| @stop_guessing = false | ||
|
|
||
| end | ||
|
|
||
| def get_level | ||
| puts "You have access to three levels: Easy, Medium, and Hard" | ||
| puts "\nNOTE: \n* Easy gives you 5 missed guesses \n* Medium gives you 4 guesses\n* Hard gives you only 3 guesses." | ||
| puts "\nREADY TO PLAY!?" | ||
| puts "\nPlease enter your level choice below:" | ||
|
|
||
| level_choice = gets.chomp.downcase | ||
|
|
||
| until level_choice == "easy" || level_choice == "medium" || level_choice == "hard" | ||
| puts "Please enter a level: Easy, Medium, or Hard" | ||
| level_choice = gets.chomp.downcase | ||
| end | ||
|
|
||
| case level_choice | ||
| when "easy" | ||
| @guesses_remaining = 5 | ||
| when "medium" | ||
| @guesses_remaining = 4 | ||
| when "hard" | ||
| @guesses_remaining = 3 | ||
| end | ||
| end | ||
|
|
||
| def build_blank_word_array | ||
| array = [] | ||
| @word.length.times do | ||
| array << "_" #currently does not have spaces | ||
| end | ||
| return array | ||
| end | ||
|
|
||
| def get_guess | ||
| puts "\nWhat would you like to guess?" | ||
| @guess = gets.chomp.upcase | ||
| while @guess[/^[a-zA-Z]+/] != @guess | ||
| puts "Please enter letters only!" | ||
| @guess = gets.chomp.upcase | ||
| end | ||
| while @letters_guessed.include?(@guess) | ||
| puts "You've already guessed that letter! Try again." | ||
| @guess = gets.chomp.upcase | ||
| end | ||
| end | ||
|
|
||
| #guess types: actual word, a letter, or invalid(guessing too many letters, guessing a number) | ||
| def check_guess | ||
| if @guess.length.to_i > 1 | ||
| @words_guessed << @guess | ||
| if @guess.upcase == @word | ||
| print "YAY! CONGRATS! #{@word.upcase} IS CORRECT!" | ||
| win | ||
| else | ||
| print "Sorry, that was incorrect!" | ||
| @guesses_remaining -= 1 | ||
| end | ||
| elsif @guess.length == 1 #IF USER GUESSES A LETTER | ||
| @letters_guessed << @guess | ||
|
|
||
| if @word.include?(@guess) #if guessed letter exists in generated word array, iterate over word array to check if letter matches | ||
| puts "YES! It DOES include #{@guess}!" | ||
|
|
||
| i = 0 | ||
| @word_array.each do |element| | ||
| if @guess == element #letter | ||
| @word_showing[i] = "#{element}" #resetting "__" element to guessed letter | ||
| end | ||
| i += 1 | ||
| end#of word_array loop | ||
|
|
||
| else #if guessed letter does not exist | ||
| puts "Sorry, that letter does not exist!" | ||
| @guesses_remaining -= 1 | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def print_guesses_art | ||
| case @guesses_remaining | ||
| when 5 | ||
| return ONLY_BASKET | ||
| when 4 | ||
| return MISSED_GUESS1_ALERT1.colorize(:red).blink + MISSED_GUESS1 | ||
| when 3 | ||
| return MISSED_GUESS1_ALERT2.colorize(:red).blink + MISSED_GUESS2 | ||
| when 2 | ||
| return MISSED_GUESS1_ALERT3.colorize(:red).blink + MISSED_GUESS3 | ||
| when 1 | ||
| return MISSED_GUESS_FINAL_ALERT.colorize(:red).blink + MISSED_GUESS_FINAL | ||
| end | ||
| end | ||
|
|
||
| def win | ||
| puts "\e[H\e[2J" | ||
| puts "YAY! YOU SAVED YOUR FAMILY'S PICNIC BASKET!!" | ||
| puts YOU_WIN #prints winner ascii art | ||
| @stop_guessing = true | ||
| end | ||
|
|
||
| def lose | ||
| puts "\e[H\e[2J" | ||
| puts "YOU LOSE! YOU LOSE! NO PICNIC FOR YOU!" | ||
| puts YOU_LOSE #prints loser ascii art | ||
| @stop_guessing = true | ||
| end | ||
| end #of WordGame class | ||
|
|
||
|
|
||
| #START OF GAME____________ | ||
|
|
||
| while true | ||
|
|
||
| introduction = <<YES | ||
|
|
||
| WELCOME TO WORD GUESS WITH BEAR BANDIT! | ||
|
|
||
| Guess the correct word to keep Bear Bandit from stealing your family's picnic basket. | ||
|
|
||
| ★ INSTRUCTIONS ★ | ||
| You'll be shown a series of blanks. | ||
| Each blank represents a letter in the word that you will be guessing! | ||
| You're' allowed to guess a single letter, or the whole word at once on each of your turns. | ||
| Just type in your guess and go! Good luck! | ||
|
|
||
| YES | ||
|
|
||
| puts INTRO_ART | ||
| puts introduction | ||
|
|
||
| game1 = WordGame.new #get user input for level | ||
|
|
||
| game1.level_choice | ||
|
|
||
| #WHEN EASY | ||
| puts "\n\n" | ||
| until game1.stop_guessing == true | ||
|
|
||
| puts "\e[H\e[2J" | ||
|
|
||
| puts game1.print_guesses_art | ||
| puts "\n" | ||
| puts "\nWORD: " + game1.word_showing.join(" ") | ||
| #puts #{level type} | ||
| puts "\n" | ||
| # puts "GUESSED LETTERS: #{game1.letters_guessed}" | ||
| # puts "GUESSED WORDS: #{game1.words_guessed}" | ||
| # puts "REMAINING GUESSES: #{game1.guesses_remaining}\n" | ||
|
|
||
|
|
||
| # headers = ["Guessed Letters", "Guessed Words", "Total Guesses Left"] | ||
| # rows = [game1.letters_guessed, game1.words_guessed, game1.guesses_remaining] | ||
| # table = Terminal::Table.new :title => "WORD-GUESS SUMMARY", :headings => headers, :rows => rows | ||
|
|
||
|
|
||
| table = Terminal::Table.new do |t| | ||
| t.add_row ["Guessed Letters", game1.letters_guessed.join( ", ").to_s] | ||
| t << :separator | ||
| t.add_row ["Guessed Words", game1.words_guessed.join(", ").to_s] | ||
| t << :separator | ||
| t.add_row ["Remaining Guesses", game1.guesses_remaining] | ||
| end | ||
|
|
||
| puts table | ||
|
|
||
| game1.get_guess | ||
| game1.check_guess | ||
| if game1.guesses_remaining <= 0 | ||
| game1.lose | ||
| elsif game1.word_showing.join == game1.word | ||
| game1.win | ||
| end | ||
| end | ||
|
|
||
| puts "Would you like to play again? (To exit, enter NO)" | ||
| replay_response = gets.chomp.upcase | ||
| if replay_response == "NO" | ||
| exit | ||
| end | ||
| end | ||
Oops, something went wrong.
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.
This table is so cool!