forked from AdaGold/word-guess
-
Notifications
You must be signed in to change notification settings - Fork 24
Queues - Cara Comfort & Laura Melgarejo - Word-Guess #8
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
cecomfort
wants to merge
3
commits into
Ada-C7:master
Choose a base branch
from
cecomfort: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
3 commits
Select commit
Hold shift + click to select a range
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,3 @@ | ||
| .;:;:. | ||
| ::;:;: | ||
| ';:;;' |
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,3 @@ | ||
| .;:; `::` | ||
| ::;:': / | ||
| ';:;;' ` |
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,3 @@ | ||
| .;: `::` | ||
| ::;: / | ||
| ';:;;' ` |
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,3 @@ | ||
| . `::` | ||
| :: / | ||
| ';:; ` |
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,3 @@ | ||
| `::` | ||
| : / | ||
| '; ` |
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,3 @@ | ||
| `::` | ||
| / | ||
| ' ` |
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,6 @@ | ||
| _ || | ||
| >'. || _ | ||
| `> ||.'< | ||
| `>|/ <` | ||
| `||/` | ||
| ^^^^^^^^^^^^^^^^^ |
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,131 @@ | ||
| require "colorize" | ||
| require 'random_word_generator' | ||
|
|
||
| class Word | ||
| attr_reader :current_status, :complete_word | ||
|
|
||
| def initialize (word) | ||
| @complete_word = word | ||
| @current_status = generate_dashes | ||
|
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. Watch your indentation here. |
||
| end | ||
|
|
||
| def generate_dashes | ||
| number_of_dashes = "" | ||
| @complete_word.length.times do | ||
| number_of_dashes += "_" | ||
| end | ||
| return number_of_dashes | ||
| end | ||
|
|
||
| def letter_sentinel(guess) | ||
| # check to see if letter matches (.chars would be like .to_a for a string.) | ||
| @complete_word.chars.each_with_index do |letter, index| | ||
| if guess == letter | ||
| @current_status[index] = letter | ||
| end | ||
| end | ||
| # check to see if whole word matches | ||
| if @complete_word == guess | ||
| @current_status = @complete_word | ||
| end | ||
| @current_status | ||
| end | ||
|
|
||
| def correct_guess?(guess) | ||
| @complete_word.include?(guess) || @complete_word == guess | ||
| end | ||
|
|
||
| end | ||
|
|
||
| class Game | ||
| def initialize (difficulty) | ||
|
|
||
| if difficulty == "low" | ||
| @word = Word.new(RandomWordGenerator.of_length(rand (10..14))) | ||
| elsif difficulty == "medium" | ||
| @word = Word.new(RandomWordGenerator.of_length(rand (6..9))) | ||
| elsif difficulty == "high" | ||
| @word = Word.new(RandomWordGenerator.of_length(rand (3..5))) | ||
| else | ||
| puts "Hmm I don't recognize #{difficulty}. I'll just generate a random word" + | ||
| " for you." | ||
| @word = Word.new(RandomWordGenerator.word) | ||
| end | ||
|
|
||
| @number_of_guesses = 6 | ||
| @guesses = [] | ||
| end | ||
|
|
||
| def play | ||
| until @number_of_guesses == 0 || @word.current_status == @word.complete_word | ||
| #puts @word.complete_word | ||
| puts "\nGuesses so far: #{@guesses.join(", ")}" | ||
| draw_top(@number_of_guesses -1) | ||
| draw_stem | ||
| puts @word.current_status | ||
| print "Guess a letter: " | ||
|
|
||
| guess = gets.chomp.downcase | ||
| if !@guesses.include?(guess) && (guess.length == 1 || guess.length == @word.complete_word.length) | ||
| @guesses << guess | ||
| make_a_guess | ||
| elsif @guesses.include?(guess) | ||
| puts "\nYou have already guessed #{guess}." | ||
| else | ||
| puts "\nPlease guess a letter or the entire word." | ||
| end | ||
| end | ||
| end_game | ||
| end | ||
|
|
||
| def make_a_guess | ||
|
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. Again, watch indentation. I would expect this method to be at the same level as the one above. |
||
| @word.letter_sentinel(@guesses.last) | ||
| if !@word.correct_guess?(@guesses.last) | ||
| @number_of_guesses -= 1 | ||
| end | ||
| end | ||
|
|
||
| def draw_stem | ||
| x = ["./stem.txt"] | ||
| File.open(x[0]) do |f| | ||
| f.each_line do |line| | ||
| print line.colorize(:green) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def draw_top(index) | ||
| tops = ["./dandelions6.txt", "./dandelions5.txt", "./dandelions4.txt", "./dandelions3.txt", "./dandelions2.txt", "./dandelions1.txt"] | ||
| File.open(tops[index]) do |f| | ||
| f.each_line do |line| | ||
| print line.colorize(:magenta) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # finish | ||
| def end_game | ||
| if @number_of_guesses == 0 | ||
| puts | ||
| draw_stem | ||
| puts "Ou! You lost :(\n" | ||
| "The word was '#{@word.complete_word}'" | ||
| else | ||
| puts "\nYOU WON!" | ||
| end | ||
| puts "The word was '#{@word.complete_word}'" | ||
| end | ||
| end | ||
|
|
||
| # Play the game until the user wants to quit | ||
| while true | ||
| puts "Chose your difficulty level. Low, medium or high: " | ||
| game = Game.new(gets.chomp.downcase) | ||
| game.play | ||
|
|
||
| print "\nWould you like to play again? Enter 'Yes' or 'No': " | ||
| anwser = gets.chomp.downcase | ||
| if anwser == "no" | ||
| break | ||
| end | ||
| 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.
I like that you've split
Wordout into a separate class here. This does a good job of separating game logic from the code to display a word, making the whole program more clear.