-
Notifications
You must be signed in to change notification settings - Fork 25
Pipes - Kate Evans-Spitzer & Angela Wilson - Word-Guess #3
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
base: master
Are you sure you want to change the base?
Changes from all commits
4a9f3be
e3a847f
437b932
6ef2b81
7ead885
bae797f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| # Word Game | ||
|
|
||
|
|
||
| # Intro to user | ||
| # selects difficulty ? | ||
| # word bank - | ||
| # maybe in its own class maynot, | ||
| # maybe one word bank depending difficulty? | ||
| # Find word in word bank. | ||
|
|
||
|
|
||
| # Display game board to user | ||
| # Image/ASCII art | ||
| # Blank letter spaces | ||
| # Letters already guessed? | ||
| # Ask user to guess a letter | ||
| # Store the user input | ||
| # CHeck array for guessed | ||
| # If it's in array ask for another guess. | ||
| # If not then store in array. | ||
| # check if guess is in word. | ||
| # Update screen accordingly. | ||
| # Add letter | ||
| # take flower away (tries). | ||
| # Loop ends: | ||
| # If tries run out. | ||
| # Show a losing screed | ||
| # Or if whole word is guessed. | ||
| # Show a winning screen. | ||
|
|
||
| # Ask user if they want to play again. | ||
| # if yes then loop to begining of Game | ||
| # Or no then display a thank and goodbye. | ||
|
|
||
| ################################### | ||
| # Word Game | ||
| ################################### | ||
| # require "Faker" | ||
| require_relative "word_bank" | ||
|
|
||
| class Board | ||
|
|
||
| attr_accessor :letters_guessed, :tries_remaining | ||
| attr_reader :word, :blank | ||
|
|
||
| def initialize(word) | ||
| @word = word | ||
| @blank = "_" * @word.length | ||
| @letters_guessed = [] | ||
| @tries_remaining = 4 | ||
| @tries_pictures = [ | ||
| " | ||
| _, | ||
| .-'_| | ||
| _| (_| | ||
| (_| | ||
| ", | ||
| " | ||
| _, | ||
| .-'_| , | ||
| _| (_| _|\\ | ||
| (_| (_| | ||
| ", | ||
| " | ||
| _, _, | ||
| .-'_| , .-'_| | ||
| _| (_| _|\\ _| (_| | ||
| (_| (_| (_| | ||
| ", | ||
| " | ||
| _, _, | ||
| .-'_| , .-'_| , | ||
| _| (_| _|\\ _| (_| _|\\ | ||
| (_| (_| (_| (_| | ||
| " | ||
| ] | ||
| end | ||
|
|
||
| def puts_pictures | ||
| puts @tries_pictures | ||
| end | ||
|
|
||
| def display | ||
| output = "" | ||
| output += @tries_pictures[@tries_remaining-1] + "\n" | ||
| output += @blank + "\n" | ||
| output += "Letters Guessed: #{@letters_guessed.join(' ')}" | ||
| return output | ||
| end | ||
|
|
||
| # def add_letter(guess) | ||
| # letter_location = @word.index(guess) | ||
| # @blank[letter_location] = guess | ||
| # end | ||
|
|
||
| def add_letter(guess) | ||
| letter_location = [] | ||
| # word = "coffee" | ||
| @word.split('').each_with_index do |letter,index| | ||
| # puts "checking #{letter}, index is #{index}" | ||
| # puts "checking if letter: #{letter} is guess: #{guess}" | ||
| if letter == guess | ||
| # puts "#{letter} is #{guess} at index #{index}" | ||
| letter_location << index | ||
| # puts "letter_location is now #{letter_location}" | ||
| end | ||
| end | ||
| letter_location.each do |index| | ||
| @blank[index] = guess | ||
| end | ||
| end | ||
|
|
||
| end | ||
|
|
||
|
|
||
| # Intro to user | ||
| puts "Welcome to Kate and Angela's Word Game!" | ||
|
|
||
| # selects difficulty ? | ||
| # word bank - | ||
| word_bank = initialize_word_bank() | ||
| # maybe in its own class maynot, | ||
| # maybe one word bank depending difficulty? | ||
| # Find word in word bank. | ||
| # game_word = word_bank.sample | ||
|
|
||
| game_board = Board.new(word_bank.sample.upcase) | ||
|
|
||
| # Display game board to user | ||
| # Image/ASCII art - | ||
| # "/////////*" | ||
| # Blank letter spaces | ||
| # Letters already guessed? | ||
| # | ||
|
|
||
|
|
||
| user_has_won = !(game_board.blank.include?"_") | ||
| user_has_lost = game_board.tries_remaining == 0 | ||
|
|
||
| until (user_has_won || user_has_lost) | ||
|
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. Since you make these calculations for |
||
|
|
||
| puts game_board.display | ||
|
|
||
| # Ask user to guess a letter | ||
|
|
||
| puts "Please guess a letter: " | ||
| guess = gets.chomp.upcase | ||
| if game_board.letters_guessed.include?guess | ||
| puts "You've already guessed that!" | ||
|
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. This logic all looks good, but the code might be a little cleaner if it were all wrapped up into its own method. Maybe call it something like |
||
| else | ||
| game_board.letters_guessed << guess | ||
| game_board.letters_guessed.sort! | ||
| if game_board.word.include?guess | ||
| game_board.add_letter(guess) | ||
| else | ||
| puts "Wrong!" | ||
| game_board.tries_remaining -= 1 | ||
| end | ||
| end | ||
|
|
||
| user_has_won = !(game_board.blank.include?"_") | ||
| user_has_lost = game_board.tries_remaining == 0 | ||
| end | ||
|
|
||
| # Check if this is a letter???? | ||
|
|
||
| # Store the user input | ||
| # CHeck array for guessed | ||
| # If it's in array ask for another guess. | ||
| # If not then store in array. | ||
| # check if guess is in word. | ||
| # Update screen accordingly. | ||
| # Add letter | ||
| # take flower away (tries). | ||
|
|
||
| # Loop ends: | ||
| # If tries run out. | ||
| # Show a losing screed | ||
| # Or if whole word is guessed. | ||
| # Show a winning screen. | ||
|
|
||
| if user_has_won | ||
| puts game_board.display | ||
| puts "You win!!!!" | ||
| end | ||
|
|
||
| if user_has_lost | ||
| puts "Sorry! You lost :(" | ||
| puts "The word was #{game_board.word}!" | ||
| end | ||
|
|
||
| # Ask user if they want to play again. | ||
| # if yes then loop to begining of Game | ||
| # Or no then display a thank and goodbye. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| def initialize_word_bank | ||
| return ["ear", | ||
| "heart", | ||
| "irritate", | ||
|
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 that you've separated your words out into a separate file. This makes it very clear which part of the program is which, and the reader doesn't have to scroll through a hundred lines of words at the top of your file. |
||
| "lyrical", | ||
| "moor", | ||
| "copy", | ||
| "natural", | ||
| "sedate", | ||
| "dramatic", | ||
| "bruise", | ||
| "run", | ||
| "save", | ||
| "late", | ||
| "advise", | ||
| "subdued", | ||
| "class", | ||
| "release", | ||
| "protest", | ||
| "sleepy", | ||
| "dizzy", | ||
| "afraid", | ||
| "muddle", | ||
| "hissing", | ||
| "accurate", | ||
| "snake", | ||
| "doctor", | ||
| "film", | ||
| "humdrum", | ||
| "miscreant", | ||
| "damage", | ||
| "arch", | ||
| "grandiose", | ||
| "dusty", | ||
| "tan", | ||
| "include", | ||
| "bustling", | ||
| "inform", | ||
| "sofa", | ||
| "writer", | ||
| "sulky", | ||
| "strip", | ||
| "outstanding", | ||
| "subtract", | ||
| "boiling", | ||
| "shelf", | ||
| "suggest", | ||
| "wreck", | ||
| "brake", | ||
| "sprout", | ||
| "acid", | ||
| "attach", | ||
| "auspicious", | ||
| "hole", | ||
| "insect", | ||
| "excited", | ||
| "reproduce", | ||
| "encourage", | ||
| "grape", | ||
| "oceanic", | ||
| "drain", | ||
| "angry", | ||
| "ticket", | ||
| "glove", | ||
| "stick", | ||
| "winter", | ||
| "whip", | ||
| "lying", | ||
| "typical", | ||
| "ablaze", | ||
| "separate", | ||
| "shop", | ||
| "nine", | ||
| "craven", | ||
| "strengthen", | ||
| "coherent", | ||
| "rub", | ||
| "birthday", | ||
| "railway", | ||
| "ruin", | ||
| "separate", | ||
| "coat", | ||
| "verdant", | ||
| "warlike", | ||
| "puny", | ||
| "friend", | ||
| "elegant", | ||
| "quince", | ||
| "glass", | ||
| "courageous", | ||
| "cemetery", | ||
| "well-to-do", | ||
| "bump", | ||
| "store", | ||
| "thaw", | ||
| "abounding", | ||
| "press", | ||
| "liquid", | ||
| "own", | ||
| "dazzling", | ||
| "resonant", | ||
| "workable", | ||
| "unique", | ||
| "sloppy", | ||
| "tame", | ||
| "line", | ||
| "superficial", | ||
| "box", | ||
| "witty", | ||
| "alarm", | ||
| "faint", | ||
| "rebel", | ||
| "spurious", | ||
| "announce", | ||
| "murky", | ||
| "walk", | ||
| "sand", | ||
| "zoom", | ||
| "reaction", | ||
| "grass", | ||
| "knowing", | ||
| "reminiscent", | ||
| "overjoyed"] | ||
| end | ||
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.
I like that you've rolled all this up into an instance method. Very concise.