Skip to content

Conversation

@timomitchel
Copy link
Owner

No description provided.

@guesses = []
@number_correct = 0
@current_card = 0
@card_position = 0
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This naming better represents how this value is being used, which is as an index position.

@deck.cards[@card_position]
end

def delay_output(seconds)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More dynamic, better named, and testable.

end

def check_guess(guess)
@number_correct += 1 if guess.correct?
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less lines of code, testable, and more readable.


def percent_correct
(@number_correct.to_f / deck.cards.length * 100).to_i
(@number_correct.to_f / deck.count * 100).to_i
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing indentation is part of refactoring/cleanup.

end

def game
def start_game
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better method naming.

puts "Question: #{card.question}"
input = gets.chomp
record_guess(input)
puts "This is card number #{@card_position + 1} out of #{deck.count}"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation matters for readability.

round = Round.new(deck)

assert_equal 1, round.delay_output(1)
assert_equal 2, round.delay_output(2)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discovered quite a bit about the sleep method by writing these tests.

assert_equal 2, round.delay_output(2)
end

def test_check_guess
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whenever there are multiple scenarios based on a condition, we want to test both of them.

end

def input
# More on why I do this with the mocks and stubs lesson
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We always want to isolate user input.

def start
puts "Welcome! You're playing with #{deck.cards.count} cards"
sleep 1.5
puts "Welcome! You're playing with #{deck.count} cards"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I built a count method on the deck class, I should use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants