Skip to content
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

Feat/command line interface #1

Merged
merged 7 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions flashcard_runner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'pry'
require './lib/card.rb'
require './lib/turn.rb'
require './lib/deck.rb'
require './lib/round.rb'

card_1 = Card.new("Who is leading the NBA in points per game?", "Luka Doncic", :"Basic Stats")
card_2 = Card.new("What team is leading the NBA in points per game?", "Indiana Pacers", :"Team Stats")
card_3 = Card.new("Who is leading the NBA in Box Plus/Minus?", "Nikola Jokic", :"Advanced Stats")
card_4 = Card.new("Who is leading the NBA in VORP?", "Nikola Jokic", :"Advanced Stats")
card_5 = Card.new("How many assists per game is Tyrese Halliburton averaging?", 12, :"Basic Stats")
card_6 = Card.new("What team has most wins in the NBA?", "Boston Celtics", :"Team Stats")
card_7 = Card.new("Who is the worst team in the NBA?", "Detroit Pistons", :"Team Stats")
card_8 = Card.new("Who is the reigning NBA champion?", "Denver Nuggets", :"Team Stats")
card_9 = Card.new("Who is the all time leader in points scored?", "Lebron James", :"Basic Stats")
card_10 = Card.new("Who has the highest effective field goal percentage?", "Dereck Lively", :"Advanced Stats")

cards = [card_1, card_2, card_3, card_4, card_5, card_6, card_7, card_8, card_9, card_10]

deck = Deck.new(cards)

round = Round.new(deck)

round.start
round.summary
2 changes: 1 addition & 1 deletion lib/deck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def initialize(cards)
end

def count
@card.count
@cards.count
end

def cards_in_category(category)
Expand Down
35 changes: 32 additions & 3 deletions lib/round.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ def current_card

def take_turn(guess)
current_turn = Turn.new(guess, current_card)
current_turn.feedback
@turns << current_turn
if current_turn.correct?
@number_correct += 1
else
end
@deck.cards.shift
# try to adjust below to reassign, rather than bang operator.
@deck.cards.rotate!
current_turn
end

Expand All @@ -27,12 +29,39 @@ def number_correct_by_category(category)
end

def percent_correct
(@number_correct.to_f / @turns.count) * 100
((@number_correct.to_f / @turns.count) * 100).round(2)
end

def percent_correct_by_category(category)
category_correct = @turns.count { |turn| turn.card.category == category && turn.correct?}
category_count = @turns.count { |turn| turn.card.category == category}
(category_count.to_f / category_correct) * 100
((category_correct.to_f / category_count) * 100).round(2)
end

def start
puts "Welcome! You're playing with #{deck.count} cards."
puts "-------------------------------------"

deck.cards.each do
puts "This is card number #{turns.count+1} out of #{deck.count}"
puts "Question: #{current_card.question}"

guess = gets.chomp
take_turn(guess)
end
end

def summary
puts "***** Game over! *****"

puts "You had #{number_correct} correct guesses out of #{deck.count} for a total score of #{percent_correct}%."
category_array = []
turns.each do |turn|
category = turn.card.category
category_array << category
end
category_array.uniq.each do |category|
puts "#{category} - #{percent_correct_by_category(category)}% correct"
end
end
end
4 changes: 2 additions & 2 deletions lib/turn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def correct?

def feedback
if correct? == true
"Correct!"
puts "Correct!"
else
"Incorrect."
puts "Incorrect."
end
end
end