From 418a09bb7e9413f49ffc4e0c514c9b7c4a55afdc Mon Sep 17 00:00:00 2001 From: Will Fox Date: Tue, 3 Dec 2024 18:18:31 -0500 Subject: [PATCH 01/47] test: added require pry to card_spec file for inspection --- spec/card_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/card_spec.rb b/spec/card_spec.rb index 84a45a7a6..cfba72093 100644 --- a/spec/card_spec.rb +++ b/spec/card_spec.rb @@ -1,3 +1,4 @@ +require 'pry' require './lib/card' RSpec.describe Card do @@ -9,7 +10,7 @@ it 'has a question' do card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - + binding.pry expect(card.question).to eq("What is the capital of Alaska?") end From 5b77410798e7aafd2dc59ff7d6e79877d3d331be Mon Sep 17 00:00:00 2001 From: Will Fox Date: Tue, 3 Dec 2024 18:19:36 -0500 Subject: [PATCH 02/47] feat: add card class with attrs --- lib/card.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/card.rb b/lib/card.rb index e69de29bb..2a4981165 100644 --- a/lib/card.rb +++ b/lib/card.rb @@ -0,0 +1,9 @@ +class Card + attr_reader :question, :answer, :category + + def initialize(question, answer, category) + @question = question + @answer = answer + @category = category + end +end \ No newline at end of file From 632ae7a7c457b2aa5e22fe73d677d1494633355c Mon Sep 17 00:00:00 2001 From: Will Fox Date: Tue, 3 Dec 2024 19:15:56 -0500 Subject: [PATCH 03/47] feat: create runner files for inspection and eventual gameplay --- dev_runner.rb | 0 flash_cards_runner.rb | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 dev_runner.rb create mode 100644 flash_cards_runner.rb diff --git a/dev_runner.rb b/dev_runner.rb new file mode 100644 index 000000000..e69de29bb diff --git a/flash_cards_runner.rb b/flash_cards_runner.rb new file mode 100644 index 000000000..e69de29bb From 0f14e6653b45b5868a4ab6244ea4479409a56aa6 Mon Sep 17 00:00:00 2001 From: Will Fox Date: Tue, 3 Dec 2024 19:16:51 -0500 Subject: [PATCH 04/47] feat: add turn class with attrs --- lib/turn.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 lib/turn.rb diff --git a/lib/turn.rb b/lib/turn.rb new file mode 100644 index 000000000..48e62f2b7 --- /dev/null +++ b/lib/turn.rb @@ -0,0 +1,12 @@ +class Turn + attr_reader :guess, :card + + def initialize(guess, card) + @guess = guess + @card = card + end + + def correct? + @guess == @card.answer + end +end \ No newline at end of file From d21b32b72a12cdd9248cb313d42261344f67830e Mon Sep 17 00:00:00 2001 From: Will Fox Date: Tue, 3 Dec 2024 19:17:47 -0500 Subject: [PATCH 05/47] test: write initial tests for turn class, all tests passing --- spec/turn_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 spec/turn_spec.rb diff --git a/spec/turn_spec.rb b/spec/turn_spec.rb new file mode 100644 index 000000000..c54151070 --- /dev/null +++ b/spec/turn_spec.rb @@ -0,0 +1,25 @@ +require 'pry' +require './lib/turn' +require './lib/card' + +RSpec.describe Turn do + before(:each) do + @card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + @turn = Turn.new("Juneau", @card) + end + + it 'exists' do + expect(@turn).to be_a(Turn) + end + + it 'holds a card object' do # redundant, unnecessary? + expect(@turn.card).to eq(@card) + end + + describe 'instance methods' do + + it 'can check if a turns guess is correct' do + expect(@turn.correct?).to eq(true) + end + end +end From 4c66b400195d96e166cc292e3e15a177167606bf Mon Sep 17 00:00:00 2001 From: Will Fox Date: Tue, 3 Dec 2024 19:52:48 -0500 Subject: [PATCH 06/47] feat: refactored feedback method, updated turn class --- lib/turn.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/turn.rb b/lib/turn.rb index 48e62f2b7..ae58245f1 100644 --- a/lib/turn.rb +++ b/lib/turn.rb @@ -7,6 +7,14 @@ def initialize(guess, card) end def correct? - @guess == @card.answer + @guess == @card.answer + end + + def feedback + if correct? + "Correct!" + else + "Incorrect." + end end end \ No newline at end of file From bd8b6c9a63dccda599fb7b85a89280399c598b8d Mon Sep 17 00:00:00 2001 From: Will Fox Date: Tue, 3 Dec 2024 19:53:32 -0500 Subject: [PATCH 07/47] test: updated tests, all tests passing, iteration 1 complete --- spec/turn_spec.rb | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/spec/turn_spec.rb b/spec/turn_spec.rb index c54151070..fad3c9df0 100644 --- a/spec/turn_spec.rb +++ b/spec/turn_spec.rb @@ -4,22 +4,32 @@ RSpec.describe Turn do before(:each) do - @card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - @turn = Turn.new("Juneau", @card) - end + @card1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + @card2 = Card.new("Which planet is closest to the sun?", "Mercury", :STEM) + @turn1 = Turn.new("Juneau", @card1) + @turn2 = Turn.new("Saturn", @card2) + end it 'exists' do - expect(@turn).to be_a(Turn) + expect(@turn1).to be_a(Turn) end - it 'holds a card object' do # redundant, unnecessary? - expect(@turn.card).to eq(@card) + it 'holds a card object' do + expect(@turn1.card).to eq(@card1) end describe 'instance methods' do + it 'can check if the guess is correct' do + expect(@turn1.correct?).to eq(true) + end + + it 'can check if the guess is incorrect' do + expect(@turn2.correct?).to eq(false) + end - it 'can check if a turns guess is correct' do - expect(@turn.correct?).to eq(true) + it 'can give feedback on both correct and incorrect guesses' do + expect(@turn1.feedback).to eq("Correct!") + expect(@turn2.feedback).to eq("Incorrect.") end end end From 3eaa08c787881e6a1fe9e063699286e578212a46 Mon Sep 17 00:00:00 2001 From: Will Fox Date: Tue, 3 Dec 2024 22:11:49 -0500 Subject: [PATCH 08/47] feat: add deck class with methods --- lib/deck.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 lib/deck.rb diff --git a/lib/deck.rb b/lib/deck.rb new file mode 100644 index 000000000..3f5510b4a --- /dev/null +++ b/lib/deck.rb @@ -0,0 +1,17 @@ +class Deck + attr_reader :cards + + def initialize(cards) + @cards = cards + end + + def cards_in_category(category) + @cards.select do |card| + card.category == category + end + end + + def count + @cards.count + end +end \ No newline at end of file From 33a640d2b03f557c513c1682385e18cde7f67fc0 Mon Sep 17 00:00:00 2001 From: Will Fox Date: Tue, 3 Dec 2024 22:12:44 -0500 Subject: [PATCH 09/47] test: add tests for deck class, all tests passing --- spec/deck_spec.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 spec/deck_spec.rb diff --git a/spec/deck_spec.rb b/spec/deck_spec.rb new file mode 100644 index 000000000..049a70d5f --- /dev/null +++ b/spec/deck_spec.rb @@ -0,0 +1,29 @@ +require 'pry' +require './lib/card' +require './lib/deck' + +RSpec.describe Deck do + before(:each) do + @card1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + @card2 = Card.new("Which planet is closest to the sun?", "Mercury", :STEM) + @card3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) + @cards = [@card1, @card2, @card3] + @deck1 = Deck.new(@cards) + end + + it 'exists' do + expect(@deck1).to be_a(Deck) + end + + it 'holds a collection of cards' do + expect(@deck1.cards).to eq([@card1, @card2, @card3]) + end + + it 'can check what category a card belongs to' do + expect(@deck1.cards_in_category(:STEM)).to eq([@card2, @card3]) + end + + it 'can count how many cards are in the deck' do + expect(@deck1.count).to eq(3) + end +end \ No newline at end of file From 08257b951195584041a576082e9cc4e31c3f8e1e Mon Sep 17 00:00:00 2001 From: Will Fox Date: Tue, 3 Dec 2024 22:45:09 -0500 Subject: [PATCH 10/47] feat: add the round class with attrs, no methods yet --- lib/round.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 lib/round.rb diff --git a/lib/round.rb b/lib/round.rb new file mode 100644 index 000000000..fe3563479 --- /dev/null +++ b/lib/round.rb @@ -0,0 +1,10 @@ +require 'pry' + +class Round + attr_reader :deck, :turn + + def initialize(deck) + @deck = deck + @turn = [] + end +end \ No newline at end of file From bd6f7903f12882c7f8c03c8e864429fee33202f0 Mon Sep 17 00:00:00 2001 From: Will Fox Date: Tue, 3 Dec 2024 22:46:29 -0500 Subject: [PATCH 11/47] test: add initialization set-up and tests for round class --- spec/round_spec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 spec/round_spec.rb diff --git a/spec/round_spec.rb b/spec/round_spec.rb new file mode 100644 index 000000000..14af34495 --- /dev/null +++ b/spec/round_spec.rb @@ -0,0 +1,20 @@ +require 'pry' +require './lib/card' +require './lib/deck' +require './lib/round' + +RSpec.describe Round do + before(:each) do + @card1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + @card2 = Card.new("Which planet is closest to the sun?", "Mercury", :STEM) + @card3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) + @cards = [@card1, @card2, @card3] + @deck = Deck.new(@cards) + @round = Round.new(@deck) + end + + it 'exists' do + expect(@round).to be_a(Round) + binding.pry + end +end \ No newline at end of file From b16cd2d29b11190aab35e940d06637062de81f3d Mon Sep 17 00:00:00 2001 From: Will Fox Date: Tue, 3 Dec 2024 22:59:30 -0500 Subject: [PATCH 12/47] feat: add current_card method --- lib/round.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/round.rb b/lib/round.rb index fe3563479..c46a7dbb6 100644 --- a/lib/round.rb +++ b/lib/round.rb @@ -7,4 +7,8 @@ def initialize(deck) @deck = deck @turn = [] end + + def current_card + @deck.cards.first + end end \ No newline at end of file From e3cd5c478d6ffee719a339cc8af76ae7ba614638 Mon Sep 17 00:00:00 2001 From: Will Fox Date: Tue, 3 Dec 2024 22:59:46 -0500 Subject: [PATCH 13/47] test: add current_card test --- spec/round_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/round_spec.rb b/spec/round_spec.rb index 14af34495..24080034c 100644 --- a/spec/round_spec.rb +++ b/spec/round_spec.rb @@ -15,6 +15,10 @@ it 'exists' do expect(@round).to be_a(Round) + end + + it 'can check for the current card at the front of the array' do + expect(@round.current_card).to eq(@card1) binding.pry end end \ No newline at end of file From a3b1a99fcecfe80079d1b27d26b08ef9b5b9860e Mon Sep 17 00:00:00 2001 From: Will Fox Date: Wed, 4 Dec 2024 10:09:12 -0500 Subject: [PATCH 14/47] feat: add take_turn method to round class --- lib/round.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/round.rb b/lib/round.rb index c46a7dbb6..8a0e3d3a7 100644 --- a/lib/round.rb +++ b/lib/round.rb @@ -1,14 +1,21 @@ require 'pry' class Round - attr_reader :deck, :turn + attr_reader :deck, :turns def initialize(deck) @deck = deck - @turn = [] + @turns = [] end def current_card @deck.cards.first end + + def take_turn(guess) + new_turn = Turn.new(guess, current_card) + @turns << new_turn + @deck.cards.shift + new_turn + end end \ No newline at end of file From 52cc2c3a3c432b5d41519631c11ddfbc5aae1681 Mon Sep 17 00:00:00 2001 From: Will Fox Date: Wed, 4 Dec 2024 10:09:48 -0500 Subject: [PATCH 15/47] test: add test for take_turn, test passing --- spec/round_spec.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/spec/round_spec.rb b/spec/round_spec.rb index 24080034c..7868fdecb 100644 --- a/spec/round_spec.rb +++ b/spec/round_spec.rb @@ -1,5 +1,6 @@ require 'pry' require './lib/card' +require './lib/turn' require './lib/deck' require './lib/round' @@ -19,6 +20,12 @@ it 'can check for the current card at the front of the array' do expect(@round.current_card).to eq(@card1) - binding.pry + end + + it 'creates a new instance of turn' do + new_turn = @round.take_turn("Juneau") + + expect(new_turn.class).to eq(Turn) + expect(new_turn.correct?).to eq(true) end end \ No newline at end of file From 35ccb96fae6cbc2a9ba484a351ccf6c15c7f1b9a Mon Sep 17 00:00:00 2001 From: Will Fox Date: Wed, 4 Dec 2024 10:11:36 -0500 Subject: [PATCH 16/47] fix: updated title for take_turn method test --- spec/round_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/round_spec.rb b/spec/round_spec.rb index 7868fdecb..1548c97e6 100644 --- a/spec/round_spec.rb +++ b/spec/round_spec.rb @@ -22,7 +22,7 @@ expect(@round.current_card).to eq(@card1) end - it 'creates a new instance of turn' do + it 'creates and records a new turn for the round' do new_turn = @round.take_turn("Juneau") expect(new_turn.class).to eq(Turn) From 839fadc8df13140993ee3778a926f327088aac9f Mon Sep 17 00:00:00 2001 From: Will Fox Date: Wed, 4 Dec 2024 13:59:35 -0500 Subject: [PATCH 17/47] feat: add correct_count method --- lib/round.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/round.rb b/lib/round.rb index 8a0e3d3a7..55b7b5c98 100644 --- a/lib/round.rb +++ b/lib/round.rb @@ -18,4 +18,19 @@ def take_turn(guess) @deck.cards.shift new_turn end + + def number_correct + correct_count = 0 + + @turns.each do |turn| + if turn.correct? + correct_count += 1 + end + end + correct_count + end + + # def number_correct_by_category + + # end end \ No newline at end of file From ce9751f0675d93e93abdbe3ab67aa617d4eb8f55 Mon Sep 17 00:00:00 2001 From: Will Fox Date: Wed, 4 Dec 2024 13:59:52 -0500 Subject: [PATCH 18/47] test: add correct_count test --- spec/round_spec.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/spec/round_spec.rb b/spec/round_spec.rb index 1548c97e6..21de79421 100644 --- a/spec/round_spec.rb +++ b/spec/round_spec.rb @@ -18,7 +18,7 @@ expect(@round).to be_a(Round) end - it 'can check for the current card at the front of the array' do + it 'checks for the current card at the front of the array' do expect(@round.current_card).to eq(@card1) end @@ -28,4 +28,12 @@ expect(new_turn.class).to eq(Turn) expect(new_turn.correct?).to eq(true) end + + it 'records the number of correct answers in the turns array' do + new_turn = @round.take_turn("Juneau") + expect(@round.number_correct).to eq(1) + + new_turn = @round.take_turn("Venus") + expect(@round.number_correct).to eq(1) + end end \ No newline at end of file From 13f4d7fa460baa645509059ebe8069f59dd1ea0f Mon Sep 17 00:00:00 2001 From: Will Fox Date: Wed, 4 Dec 2024 14:52:48 -0500 Subject: [PATCH 19/47] fix: refactored method names for clarity and consistency --- lib/deck.rb | 2 +- lib/round.rb | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/deck.rb b/lib/deck.rb index 3f5510b4a..9c476313e 100644 --- a/lib/deck.rb +++ b/lib/deck.rb @@ -11,7 +11,7 @@ def cards_in_category(category) end end - def count + def card_count @cards.count end end \ No newline at end of file diff --git a/lib/round.rb b/lib/round.rb index 55b7b5c98..5972cd35d 100644 --- a/lib/round.rb +++ b/lib/round.rb @@ -30,7 +30,11 @@ def number_correct correct_count end - # def number_correct_by_category + def turn_count #refactored these names for clarity and consistency, I believe this is an example of Law of Demeter + @turns.count + end - # end + def last_turn + @turns.last + end end \ No newline at end of file From 28ee5185deb289b87ce7c9448e06a7f05521669e Mon Sep 17 00:00:00 2001 From: Will Fox Date: Wed, 4 Dec 2024 14:53:25 -0500 Subject: [PATCH 20/47] fix: updated test description for clarity --- spec/deck_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/deck_spec.rb b/spec/deck_spec.rb index 049a70d5f..c345a5024 100644 --- a/spec/deck_spec.rb +++ b/spec/deck_spec.rb @@ -19,11 +19,11 @@ expect(@deck1.cards).to eq([@card1, @card2, @card3]) end - it 'can check what category a card belongs to' do + it 'checks what category a card belongs to' do expect(@deck1.cards_in_category(:STEM)).to eq([@card2, @card3]) end - it 'can count how many cards are in the deck' do - expect(@deck1.count).to eq(3) + it 'counts how many cards are in the deck' do + expect(@deck1.card_count).to eq(3) end end \ No newline at end of file From f7e0721c5b408f01e9ba666297b1dec39e2280b6 Mon Sep 17 00:00:00 2001 From: Will Fox Date: Wed, 4 Dec 2024 14:56:11 -0500 Subject: [PATCH 21/47] fix: refactored the set-up for last_turn method to isolate a turn object in the assertion --- spec/round_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spec/round_spec.rb b/spec/round_spec.rb index 21de79421..fa529b4c2 100644 --- a/spec/round_spec.rb +++ b/spec/round_spec.rb @@ -29,6 +29,15 @@ expect(new_turn.correct?).to eq(true) end + it 'counts the amount of turns taken' do + expect(@round.turn_count).to eq(0) + + new_turn = @round.take_turn("Juneau") + new_turn = @round.take_turn("Venus") + + expect(@round.turns.count).to eq(2) + end + it 'records the number of correct answers in the turns array' do new_turn = @round.take_turn("Juneau") expect(@round.number_correct).to eq(1) @@ -36,4 +45,13 @@ new_turn = @round.take_turn("Venus") expect(@round.number_correct).to eq(1) end + + it 'determines the last turn taken' do + turn1 = @round.take_turn("Juneau") + turn2 = @round.take_turn("Venus") + + expect(@round.last_turn).to eq(turn2) + expect(@round.last_turn.guess).to eq("Venus") + expect(@round.last_turn.feedback).to eq("Incorrect.") + end end \ No newline at end of file From 291e5bb044c23655b5879fc17ae234f403f3a07f Mon Sep 17 00:00:00 2001 From: Will Fox Date: Wed, 4 Dec 2024 15:44:29 -0500 Subject: [PATCH 22/47] feat: add a few annotations for my presentation --- lib/round.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/round.rb b/lib/round.rb index 5972cd35d..7b7b28ce2 100644 --- a/lib/round.rb +++ b/lib/round.rb @@ -31,10 +31,10 @@ def number_correct end def turn_count #refactored these names for clarity and consistency, I believe this is an example of Law of Demeter - @turns.count + @turns.count #previously was def count, @rounds.turns.count (in spec file) end - def last_turn + def last_turn #previously was def last, @round.turns.last (in spec file) @turns.last end end \ No newline at end of file From df1fff684be1cd610ee661980bb5818735eb3ace Mon Sep 17 00:00:00 2001 From: Will Fox Date: Wed, 4 Dec 2024 15:45:35 -0500 Subject: [PATCH 23/47] fix: refactored tests, added # to instance methods, updated descriptions --- spec/card_spec.rb | 28 +++++++++++++----------- spec/deck_spec.rb | 12 +++++++---- spec/round_spec.rb | 54 +++++++++++++++++++++++++++------------------- spec/turn_spec.rb | 20 +++++++++-------- 4 files changed, 66 insertions(+), 48 deletions(-) diff --git a/spec/card_spec.rb b/spec/card_spec.rb index cfba72093..8056796d6 100644 --- a/spec/card_spec.rb +++ b/spec/card_spec.rb @@ -4,25 +4,27 @@ RSpec.describe Card do it 'exists' do card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - expect(card).to be_instance_of(Card) end - it 'has a question' do - card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - binding.pry - expect(card.question).to eq("What is the capital of Alaska?") + describe '#question' do + it 'has a question' do + card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + expect(card.question).to eq("What is the capital of Alaska?") + end end - it 'has an answer' do - card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - - expect(card.answer).to eq("Juneau") + describe '#answer' do + it 'has an answer' do + card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + expect(card.answer).to eq("Juneau") + end end - it 'has a category' do - card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - - expect(card.category).to eq(:Geography) + describe '#category' do + it 'has a category' do + card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + expect(card.category).to eq(:Geography) + end end end diff --git a/spec/deck_spec.rb b/spec/deck_spec.rb index c345a5024..719488960 100644 --- a/spec/deck_spec.rb +++ b/spec/deck_spec.rb @@ -15,15 +15,19 @@ expect(@deck1).to be_a(Deck) end - it 'holds a collection of cards' do + it '#cards returns the collection of cards' do expect(@deck1.cards).to eq([@card1, @card2, @card3]) end - it 'checks what category a card belongs to' do - expect(@deck1.cards_in_category(:STEM)).to eq([@card2, @card3]) + describe '#cards_in_category' do + it 'checks what category a card belongs to' do + expect(@deck1.cards_in_category(:STEM)).to eq([@card2, @card3]) + expect(@deck1.cards_in_category(:Geography)).to eq([@card1]) + expect(@deck1.cards_in_category("Pop Culture")).to eq([]) + end end - it 'counts how many cards are in the deck' do + it '#card_count returns the number of cards in the deck' do expect(@deck1.card_count).to eq(3) end end \ No newline at end of file diff --git a/spec/round_spec.rb b/spec/round_spec.rb index fa529b4c2..46e31224b 100644 --- a/spec/round_spec.rb +++ b/spec/round_spec.rb @@ -18,40 +18,50 @@ expect(@round).to be_a(Round) end - it 'checks for the current card at the front of the array' do - expect(@round.current_card).to eq(@card1) + describe '#current_card' do + it 'checks for the current card at the front of the deck' do + expect(@round.current_card).to eq(@card1) + end end - it 'creates and records a new turn for the round' do - new_turn = @round.take_turn("Juneau") + describe '#take_turn' do + it 'creates and records a new turn for the round' do + new_turn = @round.take_turn("Juneau") - expect(new_turn.class).to eq(Turn) - expect(new_turn.correct?).to eq(true) + expect(new_turn.class).to eq(Turn) + expect(new_turn.correct?).to eq(true) + end end - it 'counts the amount of turns taken' do - expect(@round.turn_count).to eq(0) + describe '#turns and #turn_count' do + it 'counts the number of turns taken' do + expect(@round.turn_count).to eq(0) - new_turn = @round.take_turn("Juneau") - new_turn = @round.take_turn("Venus") + @round.take_turn("Juneau") + @round.take_turn("Venus") - expect(@round.turns.count).to eq(2) + expect(@round.turns.count).to eq(2) + end end - it 'records the number of correct answers in the turns array' do - new_turn = @round.take_turn("Juneau") - expect(@round.number_correct).to eq(1) + describe '#number_correct' do + it 'records the number of correct answers in the turns array' do + @round.take_turn("Juneau") + expect(@round.number_correct).to eq(1) - new_turn = @round.take_turn("Venus") - expect(@round.number_correct).to eq(1) + @round.take_turn("Venus") + expect(@round.number_correct).to eq(1) + end end - it 'determines the last turn taken' do - turn1 = @round.take_turn("Juneau") - turn2 = @round.take_turn("Venus") + describe '#last_turn' do + it 'determines the last turn taken' do + turn1 = @round.take_turn("Juneau") + turn2 = @round.take_turn("Venus") - expect(@round.last_turn).to eq(turn2) - expect(@round.last_turn.guess).to eq("Venus") - expect(@round.last_turn.feedback).to eq("Incorrect.") + expect(@round.last_turn).to eq(turn2) + expect(@round.last_turn.guess).to eq("Venus") + expect(@round.last_turn.feedback).to eq("Incorrect.") + end end end \ No newline at end of file diff --git a/spec/turn_spec.rb b/spec/turn_spec.rb index fad3c9df0..ed612d974 100644 --- a/spec/turn_spec.rb +++ b/spec/turn_spec.rb @@ -14,22 +14,24 @@ expect(@turn1).to be_a(Turn) end - it 'holds a card object' do + it '#card returns the card object associated with the turn' do expect(@turn1.card).to eq(@card1) end - describe 'instance methods' do - it 'can check if the guess is correct' do - expect(@turn1.correct?).to eq(true) + describe '#correct?' do + it 'can check if the guess is correct' do + expect(@turn1.correct?).to eq(true) end - it 'can check if the guess is incorrect' do - expect(@turn2.correct?).to eq(false) + it 'can check if the guess is incorrect' do + expect(@turn2.correct?).to eq(false) end + end - it 'can give feedback on both correct and incorrect guesses' do - expect(@turn1.feedback).to eq("Correct!") - expect(@turn2.feedback).to eq("Incorrect.") + describe '#feedback' do + it 'can give feedback on both correct and incorrect guesses' do + expect(@turn1.feedback).to eq("Correct!") + expect(@turn2.feedback).to eq("Incorrect.") end end end From ded87f7749ece7cf4e321cc629c970957cade782 Mon Sep 17 00:00:00 2001 From: Will Fox Date: Wed, 4 Dec 2024 17:34:18 -0500 Subject: [PATCH 24/47] feat: add percentage methods, complete iteration 2, may go back to refactor --- lib/round.rb | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/lib/round.rb b/lib/round.rb index 7b7b28ce2..1ec22d75c 100644 --- a/lib/round.rb +++ b/lib/round.rb @@ -19,6 +19,14 @@ def take_turn(guess) new_turn end + def turn_count #refactored these names for clarity and consistency, I believe this is an example of Law of Demeter + @turns.count #previously was def count, @rounds.turns.count (in spec file) + end + + def last_turn #previously was def last, @round.turns.last (in spec file) + @turns.last + end + def number_correct correct_count = 0 @@ -30,11 +38,28 @@ def number_correct correct_count end - def turn_count #refactored these names for clarity and consistency, I believe this is an example of Law of Demeter - @turns.count #previously was def count, @rounds.turns.count (in spec file) + def correct_by_category(category) + correct_by_cat_count = 0 + + @turns.each do |turn| + if turn.correct? && turn.card.category == category + correct_by_cat_count += 1 + end + end + correct_by_cat_count end - def last_turn #previously was def last, @round.turns.last (in spec file) - @turns.last + def percent_correct + (number_correct / turn_count.to_f) * 100 + end + + def percent_correct_by_category(category) + count_by_cat = 0 + @turns.each do |turn| + if turn.card.category == category + count_by_cat += 1 + end + end + (correct_by_category(category) / count_by_cat.to_f) * 100 end end \ No newline at end of file From bd95401c18d3e17f335d20722ade745d1665d3fd Mon Sep 17 00:00:00 2001 From: Will Fox Date: Wed, 4 Dec 2024 17:35:06 -0500 Subject: [PATCH 25/47] test: add percentage tests, all tests passing, may need to test for more edge cases or opposites, will return to refactor --- spec/round_spec.rb | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/spec/round_spec.rb b/spec/round_spec.rb index 46e31224b..9aa233ab8 100644 --- a/spec/round_spec.rb +++ b/spec/round_spec.rb @@ -44,6 +44,17 @@ end end + describe '#last_turn' do + it 'determines the last turn taken' do + turn1 = @round.take_turn("Juneau") + turn2 = @round.take_turn("Venus") + + expect(@round.last_turn).to eq(turn2) + expect(@round.last_turn.guess).to eq("Venus") + expect(@round.last_turn.feedback).to eq("Incorrect.") + end + end + describe '#number_correct' do it 'records the number of correct answers in the turns array' do @round.take_turn("Juneau") @@ -54,14 +65,32 @@ end end - describe '#last_turn' do - it 'determines the last turn taken' do - turn1 = @round.take_turn("Juneau") - turn2 = @round.take_turn("Venus") + describe '#correct_by_category' do + it 'records the number of correct answers for each category' do + @round.take_turn("Juneau") - expect(@round.last_turn).to eq(turn2) - expect(@round.last_turn.guess).to eq("Venus") - expect(@round.last_turn.feedback).to eq("Incorrect.") + expect(@round.correct_by_category(:Geography)).to eq(1) + expect(@round.correct_by_category(:STEM)).to eq(0) end end + + describe '#percent_correct' do + it 'returns the current percentage of correct answers' do + @round.take_turn("Juneau") + @round.take_turn("Venus") + + expect(@round.number_correct).to eq(1) + expect(@round.percent_correct).to eq(50.0) + end + end + + describe '#percent_correct_by_category' do + it 'returns the current percentage of correct answers by category' do + @round.take_turn("Juneau") + @round.take_turn("Venus") + + expect(@round.correct_by_category(:Geography)).to eq(1) + expect(@round.percent_correct_by_category(:Geography)).to eq(100.0) + end + end end \ No newline at end of file From a735bf62c92fc00400f9f39b16ffefc76bf1c02a Mon Sep 17 00:00:00 2001 From: Will Fox Date: Thu, 5 Dec 2024 20:38:00 -0500 Subject: [PATCH 26/47] fix: changed name of runner file --- flash_cards_runner.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 flash_cards_runner.rb diff --git a/flash_cards_runner.rb b/flash_cards_runner.rb deleted file mode 100644 index e69de29bb..000000000 From 8f6f8e6f0c0b3059e8306c2faaa6777bfce20e07 Mon Sep 17 00:00:00 2001 From: Will Fox Date: Thu, 5 Dec 2024 20:38:35 -0500 Subject: [PATCH 27/47] feat: write set-up for runner file --- flashcard_runner.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 flashcard_runner.rb diff --git a/flashcard_runner.rb b/flashcard_runner.rb new file mode 100644 index 000000000..69d62bbf1 --- /dev/null +++ b/flashcard_runner.rb @@ -0,0 +1,31 @@ +require 'pry' +require './lib/card' +require './lib/turn' +require './lib/deck' +require './lib/round' + +card1 = Card.new("What is the name of the island in Jurassic Park?", "Isla Nublar", :Movies) +card2 = Card.new("What is the name of the Beatles' final album?", "Let it Be", :Music) +card3 = Card.new("Who played the hit-man Jules in Pulp Fiction?", "Samuel L. Jackson", :Movies) +card4 = Card.new("What is the capital city of Brazil?", "Brasilia", :Geography) +card5 = Card.new("What is the smallest US State?", "Rhode Island", :Geography) +card6 = Card.new("Who wrote the 1971 hit song, What's Going On?", "Marvin Gaye", :Music) + +cards = [card1, card2, card3, card4, card5, card6] + +deck = Deck.new(cards) + +round = Round.new(deck) + +def start_game + puts "Welcome! You're playing with 6 cards.\n + --------------------------------------\n + This is card number 1 out of 6.\n + Question: What is the name of the island in Jurassic Park?" + gets.chomp + if gets.chomp == "Isla Nublar" + puts + end +end + +start_game \ No newline at end of file From 343785bf1b555a4fdef97c16acdf0ccd3f8cc32c Mon Sep 17 00:00:00 2001 From: Will Fox Date: Thu, 5 Dec 2024 22:58:03 -0500 Subject: [PATCH 28/47] feat: implement game-play, not yet tested --- flashcard_runner.rb | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/flashcard_runner.rb b/flashcard_runner.rb index 69d62bbf1..c6ff5c6de 100644 --- a/flashcard_runner.rb +++ b/flashcard_runner.rb @@ -18,14 +18,25 @@ round = Round.new(deck) def start_game - puts "Welcome! You're playing with 6 cards.\n - --------------------------------------\n - This is card number 1 out of 6.\n - Question: What is the name of the island in Jurassic Park?" - gets.chomp - if gets.chomp == "Isla Nublar" - puts + puts "Welcome! You're playing with #{round.deck.cards.size} cards.\n + --------------------------------------\n" + + round.deck.cards.each do |card| + puts "This is card number #{round.turns.count + 1} out of #{round.deck.cards.size}.\n" + puts card.question + guess = gets.chomp + round.take_turn(guess) + puts round.turns.last.feedback + end + puts percent_correct + puts percent_correct_by_category end + + puts "****** Game Over! ******\n" + puts "You had #{round.number_correct} correct guesses out of #{round.deck.cards.size} for a total score of #{percent_correct}." + puts "#{category} - #{percent_by_category_correct} correct\n + #{category} - #{percent_by_category_correct} correct\n + #{category} - #{percent_by_category_correct} correct\n" end start_game \ No newline at end of file From f77741ad361157dc7066dfc1b491e5e66df6dca1 Mon Sep 17 00:00:00 2001 From: Will Fox Date: Thu, 5 Dec 2024 23:20:43 -0500 Subject: [PATCH 29/47] feat: game running, start_game method not functioning correctly, needs work --- flashcard_runner.rb | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/flashcard_runner.rb b/flashcard_runner.rb index c6ff5c6de..ce1e391f3 100644 --- a/flashcard_runner.rb +++ b/flashcard_runner.rb @@ -17,26 +17,25 @@ round = Round.new(deck) -def start_game - puts "Welcome! You're playing with #{round.deck.cards.size} cards.\n +def start_game(round) + + initial_card_count = round.deck.cards.size + + puts "Welcome! You're playing with #{initial_card_count} cards.\n --------------------------------------\n" round.deck.cards.each do |card| - puts "This is card number #{round.turns.count + 1} out of #{round.deck.cards.size}.\n" + puts "This is card number #{round.turns.count + 1} out of #{initial_card_count}.\n" puts card.question guess = gets.chomp round.take_turn(guess) puts round.turns.last.feedback end - puts percent_correct - puts percent_correct_by_category - end - puts "****** Game Over! ******\n" - puts "You had #{round.number_correct} correct guesses out of #{round.deck.cards.size} for a total score of #{percent_correct}." - puts "#{category} - #{percent_by_category_correct} correct\n - #{category} - #{percent_by_category_correct} correct\n - #{category} - #{percent_by_category_correct} correct\n" + puts "You had #{round.number_correct} correct guesses out of #{round.deck.cards.size} for a total score of #{round.percent_correct}." + puts "#{category} - #{round.percent_correct_by_category(category)} correct\n + #{category} - #{round.percent_correct_by_category(category)} correct\n + #{category} - #{percent_correct_by_category(category)} correct\n" end -start_game \ No newline at end of file +start_game(round) \ No newline at end of file From 801aee06550c6a813a3c08ad0f735a0852ea54dc Mon Sep 17 00:00:00 2001 From: Will Fox Date: Thu, 5 Dec 2024 23:50:40 -0500 Subject: [PATCH 30/47] fix: changed the .each method to a 'while' loop to fix the card order, game running well up until the results --- flashcard_runner.rb | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/flashcard_runner.rb b/flashcard_runner.rb index ce1e391f3..1fa3f0fa4 100644 --- a/flashcard_runner.rb +++ b/flashcard_runner.rb @@ -21,21 +21,30 @@ def start_game(round) initial_card_count = round.deck.cards.size - puts "Welcome! You're playing with #{initial_card_count} cards.\n - --------------------------------------\n" - - round.deck.cards.each do |card| - puts "This is card number #{round.turns.count + 1} out of #{initial_card_count}.\n" - puts card.question - guess = gets.chomp - round.take_turn(guess) - puts round.turns.last.feedback - end + puts "" + puts "Welcome! You're playing Will's Trivia with #{initial_card_count} cards." + puts "" + puts ">>>---- Game On! ----<<<" + puts "" + # round.deck.cards.each do |card| + while !round.deck.cards.empty? do + puts "This is card number #{round.turns.count + 1} out of #{initial_card_count}... 'cue Jeopardy theme song'..." + puts "" + puts round.current_card.question + puts "" + guess = gets.chomp + round.take_turn(guess) + puts "" + puts round.turns.last.feedback + puts "" + end puts "****** Game Over! ******\n" - puts "You had #{round.number_correct} correct guesses out of #{round.deck.cards.size} for a total score of #{round.percent_correct}." - puts "#{category} - #{round.percent_correct_by_category(category)} correct\n - #{category} - #{round.percent_correct_by_category(category)} correct\n - #{category} - #{percent_correct_by_category(category)} correct\n" + puts "" + puts "You had #{round.number_correct} correct guesses out of #{round.deck.cards.size} for a total score of #{round.percent_correct}%." + puts "" + puts "#{category} - #{round.percent_correct_by_category(category)}% correct\n + #{category} - #{round.percent_correct_by_category(category)}% correct\n + #{category} - #{percent_correct_by_category(category)}% correct\n" end start_game(round) \ No newline at end of file From 5e376fe0f1c74d1e82b109ac6a06c6fdddb70f42 Mon Sep 17 00:00:00 2001 From: Will Fox Date: Fri, 6 Dec 2024 00:27:15 -0500 Subject: [PATCH 31/47] fix: customized feedback messages to be specific to each category, not functioning yet --- flashcard_runner.rb | 19 ++++++++++++++++--- lib/turn.rb | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/flashcard_runner.rb b/flashcard_runner.rb index 1fa3f0fa4..83934e833 100644 --- a/flashcard_runner.rb +++ b/flashcard_runner.rb @@ -35,12 +35,25 @@ def start_game(round) guess = gets.chomp round.take_turn(guess) puts "" - puts round.turns.last.feedback + # puts round.turns.last.feedback + if turn.guess.correct? && turn.card.category == :Movies + puts "Film buff huh? I bet you have a Criterion Collection subscription don't you?" + elsif turn.guess.correct? && turn.card.category == :Music + puts "Yep, wow, you must have an exquisite vinyl collection..." + elsif turn.guess.correct? && turn.card.category == :Geography + puts "I'm truly jealous of how worldly you are, take me with you next time?" + elsif !turn.guess.correct? && turn.card.category == :Movies + puts "Nope. You can use my Netflix password if you want" + elsif !turn.guess.correct? && turn.card.category == :Music + puts "Uh oh, we've got some serious work to do!" + elsif !turn.guess.correct? && turn.card.category == :Geography + puts "Welp! Time to invest in a globe!" + end puts "" end - puts "****** Game Over! ******\n" + puts "****** Game Over! ******" puts "" - puts "You had #{round.number_correct} correct guesses out of #{round.deck.cards.size} for a total score of #{round.percent_correct}%." + puts "You had #{round.number_correct} correct guesses out of #{initial_card_count} for a total score of #{round.percent_correct}%." puts "" puts "#{category} - #{round.percent_correct_by_category(category)}% correct\n #{category} - #{round.percent_correct_by_category(category)}% correct\n diff --git a/lib/turn.rb b/lib/turn.rb index ae58245f1..a766b246e 100644 --- a/lib/turn.rb +++ b/lib/turn.rb @@ -11,7 +11,7 @@ def correct? end def feedback - if correct? + if correct? "Correct!" else "Incorrect." From a9266ea312420f60574db66078b1b1bdaeb5c5da Mon Sep 17 00:00:00 2001 From: Will Fox Date: Sat, 7 Dec 2024 16:09:56 -0500 Subject: [PATCH 32/47] feat: fix the percent_correct_by_category method to output the results --- flashcard_runner.rb | 54 +++++++++++++++++++++++++++++---------------- lib/round.rb | 2 +- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/flashcard_runner.rb b/flashcard_runner.rb index 83934e833..3c91672c7 100644 --- a/flashcard_runner.rb +++ b/flashcard_runner.rb @@ -5,8 +5,8 @@ require './lib/round' card1 = Card.new("What is the name of the island in Jurassic Park?", "Isla Nublar", :Movies) -card2 = Card.new("What is the name of the Beatles' final album?", "Let it Be", :Music) -card3 = Card.new("Who played the hit-man Jules in Pulp Fiction?", "Samuel L. Jackson", :Movies) +card2 = Card.new("What is the title of the Beatles' final album?", "Let it Be", :Music) +card3 = Card.new("Who played the hit-man Jules in Pulp Fiction?", "Samuel L Jackson", :Movies) card4 = Card.new("What is the capital city of Brazil?", "Brasilia", :Geography) card5 = Card.new("What is the smallest US State?", "Rhode Island", :Geography) card6 = Card.new("Who wrote the 1971 hit song, What's Going On?", "Marvin Gaye", :Music) @@ -30,34 +30,50 @@ def start_game(round) while !round.deck.cards.empty? do puts "This is card number #{round.turns.count + 1} out of #{initial_card_count}... 'cue Jeopardy theme song'..." puts "" - puts round.current_card.question + p round.current_card.question + puts "" + puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" puts "" guess = gets.chomp round.take_turn(guess) puts "" # puts round.turns.last.feedback - if turn.guess.correct? && turn.card.category == :Movies - puts "Film buff huh? I bet you have a Criterion Collection subscription don't you?" - elsif turn.guess.correct? && turn.card.category == :Music - puts "Yep, wow, you must have an exquisite vinyl collection..." - elsif turn.guess.correct? && turn.card.category == :Geography - puts "I'm truly jealous of how worldly you are, take me with you next time?" - elsif !turn.guess.correct? && turn.card.category == :Movies - puts "Nope. You can use my Netflix password if you want" - elsif !turn.guess.correct? && turn.card.category == :Music - puts "Uh oh, we've got some serious work to do!" - elsif !turn.guess.correct? && turn.card.category == :Geography - puts "Welp! Time to invest in a globe!" + case [round.last_turn.correct?, round.last_turn.card.category] + when [true, :Movies] + p "Film buff huh? I bet you have a Criterion Collection subscription don't you?" + when [true, :Music] + p "Yep, wow, you must have an exquisite vinyl collection..." + when [true, :Geography] + p "I'm truly jealous of how worldly you are, take me with you next time?" + when [false, :Movies] + p "Nope. You can use my Netflix password if you want." + when [false, :Music] + p "Uh oh, we've got to get you some better headphones!" + when[false, :Geography] + p "Welp! Time to invest in a globe!" end puts "" end puts "****** Game Over! ******" puts "" - puts "You had #{round.number_correct} correct guesses out of #{initial_card_count} for a total score of #{round.percent_correct}%." + puts "You had #{round.number_correct} correct guesses out of #{initial_card_count} for a total score of #{round.percent_correct.round(0)}%" + puts "" + + cards_played = round.turns.map do |turn| + turn.card + end + + categories = cards_played.map do |card| + card.category + end + + unique_categories = categories.uniq + + unique_categories.each do |category| + puts "#{category} - #{round.percent_correct_by_category(category).round(0)}% correct" + end puts "" - puts "#{category} - #{round.percent_correct_by_category(category)}% correct\n - #{category} - #{round.percent_correct_by_category(category)}% correct\n - #{category} - #{percent_correct_by_category(category)}% correct\n" end + start_game(round) \ No newline at end of file diff --git a/lib/round.rb b/lib/round.rb index 1ec22d75c..f6b23c027 100644 --- a/lib/round.rb +++ b/lib/round.rb @@ -27,7 +27,7 @@ def last_turn #previously was def last, @round.turns.last (in spec file) @turns.last end - def number_correct + def number_correct #need to test for more options, even if it's working in runner correct_count = 0 @turns.each do |turn| From f147158dcd8b0034e7c7b948eeae23db3d51fe41 Mon Sep 17 00:00:00 2001 From: Will Fox Date: Sat, 7 Dec 2024 16:23:42 -0500 Subject: [PATCH 33/47] fix: refactored the correct? method to make user-input case-insensitive, working correctly --- lib/turn.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/turn.rb b/lib/turn.rb index a766b246e..bc651dd90 100644 --- a/lib/turn.rb +++ b/lib/turn.rb @@ -7,7 +7,7 @@ def initialize(guess, card) end def correct? - @guess == @card.answer + @guess.upcase == @card.answer.upcase end def feedback From fd98b973f4385f3caef83aec7bcda3dac9606cf1 Mon Sep 17 00:00:00 2001 From: Will Fox Date: Sat, 7 Dec 2024 16:24:30 -0500 Subject: [PATCH 34/47] fix: updated card object spelling --- flashcard_runner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flashcard_runner.rb b/flashcard_runner.rb index 3c91672c7..55a655f1f 100644 --- a/flashcard_runner.rb +++ b/flashcard_runner.rb @@ -59,7 +59,7 @@ def start_game(round) puts "You had #{round.number_correct} correct guesses out of #{initial_card_count} for a total score of #{round.percent_correct.round(0)}%" puts "" - cards_played = round.turns.map do |turn| + cards_played = round.turns.map do |turn| #must use turns to access card objects, deck is depleted turn.card end From 09cb79dafa8ec0f81357af09672b72fd1adc3802 Mon Sep 17 00:00:00 2001 From: Will Fox Date: Sat, 7 Dec 2024 17:22:15 -0500 Subject: [PATCH 35/47] feat: install colorize gem and colorize implementation code in set-up, not working yet --- flashcard_runner.rb | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/flashcard_runner.rb b/flashcard_runner.rb index 55a655f1f..5e5de4f6f 100644 --- a/flashcard_runner.rb +++ b/flashcard_runner.rb @@ -3,6 +3,17 @@ require './lib/turn' require './lib/deck' require './lib/round' +require 'colorize' + +colors = [:red, :green, :yellow, :blue, :magenta, :cyan] + +def cputs(message, colors) + puts message.colorize(colors.sample) +end + +def cp(message, colors) + puts message.inspect.colorize(colors.sample) + end card1 = Card.new("What is the name of the island in Jurassic Park?", "Isla Nublar", :Movies) card2 = Card.new("What is the title of the Beatles' final album?", "Let it Be", :Music) @@ -17,22 +28,22 @@ round = Round.new(deck) -def start_game(round) +def start_game(round, colors) - initial_card_count = round.deck.cards.size + initial_card_count = round.deck.cards.size # added this variable for correct interpolation in Game Over message puts "" - puts "Welcome! You're playing Will's Trivia with #{initial_card_count} cards." + cputs("Welcome! You're playing Will's Trivia with #{initial_card_count} cards.", colors) puts "" - puts ">>>---- Game On! ----<<<" + cputs(">>>---- Game On! ----<<<", colors) puts "" # round.deck.cards.each do |card| while !round.deck.cards.empty? do - puts "This is card number #{round.turns.count + 1} out of #{initial_card_count}... 'cue Jeopardy theme song'..." + cputs("This is card number #{round.turns.count + 1} out of #{initial_card_count}... 'cue Jeopardy theme song'...", colors) puts "" p round.current_card.question puts "" - puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" + cputs("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", colors) puts "" guess = gets.chomp round.take_turn(guess) @@ -40,23 +51,23 @@ def start_game(round) # puts round.turns.last.feedback case [round.last_turn.correct?, round.last_turn.card.category] when [true, :Movies] - p "Film buff huh? I bet you have a Criterion Collection subscription don't you?" + cp("Film buff huh? I bet you have a Criterion Collection subscription don't you?", colors) when [true, :Music] - p "Yep, wow, you must have an exquisite vinyl collection..." + cp("Yep, wow, you must have an exquisite vinyl collection...", colors) when [true, :Geography] - p "I'm truly jealous of how worldly you are, take me with you next time?" + cp("I'm truly jealous of how worldly you are, take me with you next time?", colors) when [false, :Movies] - p "Nope. You can use my Netflix password if you want." + cp("Nope. You can use my Netflix password if you want.", colors) when [false, :Music] - p "Uh oh, we've got to get you some better headphones!" + cp("Uh oh, we've got to get you some better headphones!", colors) when[false, :Geography] - p "Welp! Time to invest in a globe!" + cp("Welp! Time to invest in a globe!", colors) end puts "" end - puts "****** Game Over! ******" + cputs("****** Game Over! ******", colors) puts "" - puts "You had #{round.number_correct} correct guesses out of #{initial_card_count} for a total score of #{round.percent_correct.round(0)}%" + cputs("You had #{round.number_correct} correct guesses out of #{initial_card_count} for a total score of #{round.percent_correct.round(0)}%", colors) puts "" cards_played = round.turns.map do |turn| #must use turns to access card objects, deck is depleted @@ -70,10 +81,10 @@ def start_game(round) unique_categories = categories.uniq unique_categories.each do |category| - puts "#{category} - #{round.percent_correct_by_category(category).round(0)}% correct" + cputs ("#{category} - #{round.percent_correct_by_category(category).round(0)}% correct", colors) end puts "" end -start_game(round) \ No newline at end of file +start_game(round, colors) \ No newline at end of file From 2cf336246436942d49e4213a7fcb58548a8892ff Mon Sep 17 00:00:00 2001 From: Will Fox Date: Sat, 7 Dec 2024 17:25:45 -0500 Subject: [PATCH 36/47] fix: deleted space character after the very last cp method that was causing the file to crash, colorizer is working now, but not when fetching questions through instance methods --- flashcard_runner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flashcard_runner.rb b/flashcard_runner.rb index 5e5de4f6f..bd0cdf8fd 100644 --- a/flashcard_runner.rb +++ b/flashcard_runner.rb @@ -81,7 +81,7 @@ def start_game(round, colors) unique_categories = categories.uniq unique_categories.each do |category| - cputs ("#{category} - #{round.percent_correct_by_category(category).round(0)}% correct", colors) + cputs("#{category} - #{round.percent_correct_by_category(category).round(0)}% correct", colors) end puts "" end From 7dcf5afc403d1e911260a091e9377010b706e50f Mon Sep 17 00:00:00 2001 From: Will Fox Date: Sat, 7 Dec 2024 17:51:29 -0500 Subject: [PATCH 37/47] fix: colorizer is working on the questions and throughout the game, may edit the colors available to make it readable --- flashcard_runner.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flashcard_runner.rb b/flashcard_runner.rb index bd0cdf8fd..708561713 100644 --- a/flashcard_runner.rb +++ b/flashcard_runner.rb @@ -5,7 +5,7 @@ require './lib/round' require 'colorize' -colors = [:red, :green, :yellow, :blue, :magenta, :cyan] +colors = [:light_red, :light_green, :yellow, :light_blue, :light_magenta, :light_cyan] def cputs(message, colors) puts message.colorize(colors.sample) @@ -41,7 +41,7 @@ def start_game(round, colors) while !round.deck.cards.empty? do cputs("This is card number #{round.turns.count + 1} out of #{initial_card_count}... 'cue Jeopardy theme song'...", colors) puts "" - p round.current_card.question + cp(round.current_card.question, colors) puts "" cputs("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", colors) puts "" From 7151967a853c79a34f2136289513f3cbf3d6ea46 Mon Sep 17 00:00:00 2001 From: Will Fox Date: Sun, 8 Dec 2024 22:30:44 -0500 Subject: [PATCH 38/47] fix: deleted dev_runner file, never ended up using it as a sandbox, just used pry instead --- dev_runner.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 dev_runner.rb diff --git a/dev_runner.rb b/dev_runner.rb deleted file mode 100644 index e69de29bb..000000000 From c9091cda952185e988565d58cd9600027c35570a Mon Sep 17 00:00:00 2001 From: Will Fox Date: Mon, 9 Dec 2024 10:22:07 -0500 Subject: [PATCH 39/47] fix: updated correct? method with .strip to account for any trailing whitespace from the user input, this was a bug in my game-play --- flashcard_runner.rb | 1 + lib/turn.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/flashcard_runner.rb b/flashcard_runner.rb index 708561713..bef9186ba 100644 --- a/flashcard_runner.rb +++ b/flashcard_runner.rb @@ -65,6 +65,7 @@ def start_game(round, colors) end puts "" end + cputs("****** Game Over! ******", colors) puts "" cputs("You had #{round.number_correct} correct guesses out of #{initial_card_count} for a total score of #{round.percent_correct.round(0)}%", colors) diff --git a/lib/turn.rb b/lib/turn.rb index bc651dd90..4515fdeab 100644 --- a/lib/turn.rb +++ b/lib/turn.rb @@ -7,7 +7,7 @@ def initialize(guess, card) end def correct? - @guess.upcase == @card.answer.upcase + @guess.strip.upcase == @card.answer.strip.upcase end def feedback From 875aaa7fc94d0fed2e3e19cfa82a10736b179a42 Mon Sep 17 00:00:00 2001 From: Will Fox Date: Mon, 9 Dec 2024 17:48:33 -0500 Subject: [PATCH 40/47] fix: edited some annotations --- lib/round.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/round.rb b/lib/round.rb index f6b23c027..fd7de19ba 100644 --- a/lib/round.rb +++ b/lib/round.rb @@ -20,7 +20,7 @@ def take_turn(guess) end def turn_count #refactored these names for clarity and consistency, I believe this is an example of Law of Demeter - @turns.count #previously was def count, @rounds.turns.count (in spec file) + @turns.count # was def count, @rounds.turns.count (in spec file) end def last_turn #previously was def last, @round.turns.last (in spec file) From 68aa42528e753378d6208c409f57a1034f56d6bf Mon Sep 17 00:00:00 2001 From: Will Fox Date: Tue, 10 Dec 2024 10:29:57 -0500 Subject: [PATCH 41/47] fix: added annotation explaining why I don't use the feedback method --- lib/turn.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/turn.rb b/lib/turn.rb index 4515fdeab..c08f5112d 100644 --- a/lib/turn.rb +++ b/lib/turn.rb @@ -10,7 +10,7 @@ def correct? @guess.strip.upcase == @card.answer.strip.upcase end - def feedback + def feedback # technically not using this method in game because I wanted to customize the feedback based on category if correct? "Correct!" else From 41206a281a724229ca976b77880bd21b0182d59c Mon Sep 17 00:00:00 2001 From: Will Fox Date: Tue, 10 Dec 2024 10:30:37 -0500 Subject: [PATCH 42/47] fix: updated title of number_correct method to be more precise --- spec/round_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/round_spec.rb b/spec/round_spec.rb index 9aa233ab8..e64419b99 100644 --- a/spec/round_spec.rb +++ b/spec/round_spec.rb @@ -56,7 +56,7 @@ end describe '#number_correct' do - it 'records the number of correct answers in the turns array' do + it 'records the total number of correct answers in the turns array' do @round.take_turn("Juneau") expect(@round.number_correct).to eq(1) From 51b0cd0cef35b6a2db2dad6afa88633a7828715e Mon Sep 17 00:00:00 2001 From: Will Fox Date: Tue, 10 Dec 2024 10:44:08 -0500 Subject: [PATCH 43/47] test: added tests for case insensitivity and trailing whitespace in the user input, all tests passing --- lib/turn.rb | 2 +- spec/turn_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/turn.rb b/lib/turn.rb index c08f5112d..8effd2366 100644 --- a/lib/turn.rb +++ b/lib/turn.rb @@ -7,7 +7,7 @@ def initialize(guess, card) end def correct? - @guess.strip.upcase == @card.answer.strip.upcase + @guess.strip.upcase == @card.answer.strip.upcase end def feedback # technically not using this method in game because I wanted to customize the feedback based on category diff --git a/spec/turn_spec.rb b/spec/turn_spec.rb index ed612d974..e75feea09 100644 --- a/spec/turn_spec.rb +++ b/spec/turn_spec.rb @@ -26,6 +26,16 @@ it 'can check if the guess is incorrect' do expect(@turn2.correct?).to eq(false) end + + it 'is case insensitive when checking guesses' do + turn = Turn.new("juneau", @card1) + expect(turn.correct?).to eq(true) + end + + it 'ignores leading and trailing whitespace when checking guesses' do + turn = Turn.new(" Juneau ", @card1) + expect(turn.correct?).to eq(true) + end end describe '#feedback' do From 407ed9c16b57d6408d7bd57cda071d735a20d4c5 Mon Sep 17 00:00:00 2001 From: Will Fox Date: Tue, 10 Dec 2024 10:51:53 -0500 Subject: [PATCH 44/47] fix: updated edge case tests for round class, all tests passing --- spec/round_spec.rb | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/spec/round_spec.rb b/spec/round_spec.rb index e64419b99..e5940e103 100644 --- a/spec/round_spec.rb +++ b/spec/round_spec.rb @@ -22,6 +22,24 @@ it 'checks for the current card at the front of the deck' do expect(@round.current_card).to eq(@card1) end + + it 'updates the current card after a turn is taken' do + expect(@round.current_card).to eq(@card1) + + @round.take_turn("Juneau") + expect(@round.current_card).to eq(@card2) + + @round.take_turn("Mercury") + expect(@round.current_card).to eq(@card3) + end + + it 'returns nil for current_card when all cards have been used' do + @round.take_turn("Juneau") + @round.take_turn("Mercury") + @round.take_turn("North north west") + + expect(@round.current_card).to eq(nil) + end end describe '#take_turn' do @@ -45,7 +63,7 @@ end describe '#last_turn' do - it 'determines the last turn taken' do + it 'determines the last turn taken' do turn1 = @round.take_turn("Juneau") turn2 = @round.take_turn("Venus") @@ -72,6 +90,15 @@ expect(@round.correct_by_category(:Geography)).to eq(1) expect(@round.correct_by_category(:STEM)).to eq(0) end + + it 'calculates correct answers for multiple questions in the same category' do + @round.take_turn("Juneau") + @round.take_turn("Mercury") + @round.take_turn("North north west") + + expect(@round.correct_by_category(:STEM)).to eq(2) + expect(@round.percent_correct_by_category(:STEM)).to eq(100.0) + end end describe '#percent_correct' do From 13796e3ea8fafb26894508d530778e551eeff58b Mon Sep 17 00:00:00 2001 From: Will Fox Date: Tue, 10 Dec 2024 10:53:06 -0500 Subject: [PATCH 45/47] fix: added annotation for case and whitespace insensitivity --- lib/turn.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/turn.rb b/lib/turn.rb index 8effd2366..e39956399 100644 --- a/lib/turn.rb +++ b/lib/turn.rb @@ -7,7 +7,7 @@ def initialize(guess, card) end def correct? - @guess.strip.upcase == @card.answer.strip.upcase + @guess.strip.upcase == @card.answer.strip.upcase #case and whitespace insensitivity end def feedback # technically not using this method in game because I wanted to customize the feedback based on category From feaa1df44e546f0a99f1c0a760b9e263fbc00228 Mon Sep 17 00:00:00 2001 From: Will Fox Date: Tue, 10 Dec 2024 12:29:22 -0500 Subject: [PATCH 46/47] feat: added 2 more card objects to my runner file, one for Megan specifically! --- flashcard_runner.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/flashcard_runner.rb b/flashcard_runner.rb index bef9186ba..0e83670e7 100644 --- a/flashcard_runner.rb +++ b/flashcard_runner.rb @@ -16,13 +16,15 @@ def cp(message, colors) end card1 = Card.new("What is the name of the island in Jurassic Park?", "Isla Nublar", :Movies) -card2 = Card.new("What is the title of the Beatles' final album?", "Let it Be", :Music) -card3 = Card.new("Who played the hit-man Jules in Pulp Fiction?", "Samuel L Jackson", :Movies) -card4 = Card.new("What is the capital city of Brazil?", "Brasilia", :Geography) +card2 = Card.new("What is the title of the Beatles' final album release?", "Let it Be", :Music) +card3 = Card.new("What is the capital city of Brazil?", "Brasilia", :Geography) +card4 = Card.new("Who played the hit-man, Jules in the film Pulp Fiction?", "Samuel L Jackson", :Movies) card5 = Card.new("What is the smallest US State?", "Rhode Island", :Geography) card6 = Card.new("Who wrote the 1971 hit song, What's Going On?", "Marvin Gaye", :Music) +card7 = Card.new("Who played the character Will, in the film Good Will Hunting?", "Matt Damon", :Movies) +card8 = Card.new("What is the largest ski area in Colorado?", "Vail", :Geography) -cards = [card1, card2, card3, card4, card5, card6] +cards = [card1, card2, card3, card4, card5, card6, card7, card8] deck = Deck.new(cards) @@ -87,5 +89,4 @@ def start_game(round, colors) puts "" end - start_game(round, colors) \ No newline at end of file From b47031b006f4656d33b4a1229b2b489e1477059f Mon Sep 17 00:00:00 2001 From: Will Fox Date: Tue, 10 Dec 2024 13:06:55 -0500 Subject: [PATCH 47/47] fix: updated a couple of the questions to be a tad easier! --- flashcard_runner.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flashcard_runner.rb b/flashcard_runner.rb index 0e83670e7..07e0ed824 100644 --- a/flashcard_runner.rb +++ b/flashcard_runner.rb @@ -15,13 +15,13 @@ def cp(message, colors) puts message.inspect.colorize(colors.sample) end -card1 = Card.new("What is the name of the island in Jurassic Park?", "Isla Nublar", :Movies) +card1 = Card.new("What is the name of the island in the film Jurassic Park?", "Isla Nublar", :Movies) card2 = Card.new("What is the title of the Beatles' final album release?", "Let it Be", :Music) -card3 = Card.new("What is the capital city of Brazil?", "Brasilia", :Geography) +card3 = Card.new("What is the capital city of Spain?", "Madrid", :Geography) card4 = Card.new("Who played the hit-man, Jules in the film Pulp Fiction?", "Samuel L Jackson", :Movies) card5 = Card.new("What is the smallest US State?", "Rhode Island", :Geography) card6 = Card.new("Who wrote the 1971 hit song, What's Going On?", "Marvin Gaye", :Music) -card7 = Card.new("Who played the character Will, in the film Good Will Hunting?", "Matt Damon", :Movies) +card7 = Card.new("Who played Elizabeth, in the film Pirates of the Caribbean?", "Keira Knightley", :Movies) card8 = Card.new("What is the largest ski area in Colorado?", "Vail", :Geography) cards = [card1, card2, card3, card4, card5, card6, card7, card8]