Skip to content

Maia Bard #639

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
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions flashcard_runner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require './lib/card'
require './lib/turn'
require './lib/deck'
require './lib/round'


card_1 = Card.new("What is 5 + 5?", "10", :STEM)
card_2 = Card.new("What is Rachel's favorite animal?", "panda", :Turing_Staff)
card_3 = Card.new("What is Mike's middle name?", "nobody knows", :Turing_Staff)
card_4 = Card.new("What cardboard cutout lives at Turing?", "Justin Bieber", :Pop_Culture)

cards = [card_1, card_2, card_3, card_4]

deck = Deck.new(cards)

round = Round.new(deck)

round.start

10 changes: 10 additions & 0 deletions lib/card.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Card
attr_reader :question, :answer, :category

def initialize(question, answer, category)
@question = question
@answer = answer
@category = category
end

end
17 changes: 17 additions & 0 deletions lib/deck.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Deck
attr_reader :cards

def initialize(cards)
@cards = cards
end

def count
cards.length
end

def cards_in_category(category)
cards.find_all do |card|
card.category == category
end
end
end
84 changes: 84 additions & 0 deletions lib/round.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
require 'pry'
class Round
attr_reader :deck, :turns, :current_index

def initialize(deck)
@deck = deck
@turns = []
@current_index = 0
end

# current_card want it to be the first card in the deck
# then once the first card is answered we want it to move to the next card in the deck - move index spots
#accesses the array and returns the first card in the array
def current_card
@deck.cards[current_index]
end

# .take_turn accepts an argument of a guess
# new_turn needs to be of the Turn class to access the instance guess - guess needs to be an arguent to store the players answer and argument of current_card to regonize what card is being answered
#@turns << new_turn is storing the turns taken to keep track
# it needs to move to the next unaswered card while keeping all cards
#it needs to stop once the last card is answered
def take_turn(guess)
new_turn = Turn.new(guess, current_card)
@turns << new_turn

@current_index += 1
new_turn
end

def number_correct
@turns.count do |turn|
turn.correct?
end
end

def number_correct_by_category(category)
@turns.count do |turn|
turn.card.category == category && turn.correct?
end
end

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

def percent_correct_by_category(category)
total_in_category = @turns.count do |turn|
turn.card.category == category
end
return 0 if total_in_category.zero?

(number_correct_by_category(category).to_f/total_in_category) * 100

end

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

@deck.cards.each_with_index do |card, index|
puts "This is a card number #{index + 1} out of #{deck.count}"
puts "Question #{card.question}"

guess = gets.chomp
turn = take_turn(guess)

puts turn.feedback
puts "----------------------------------------------------------"
end

puts "****** Game over! ******"
puts "You had #{number_correct} correct guesses out of #{deck.count} for a total score of #{percent_correct}"

categories = @deck.cards.map do |card|
card.category
end
categories.each do |category|
puts "#{category} - #{percent_correct_by_category(category).to_i}% correct"
end
end

end

23 changes: 23 additions & 0 deletions lib/turn.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Turn
attr_reader :guess, :card

def initialize(guess, card)
@guess = guess
@card = card
end

def correct?
@guess == @card.answer
end

def feedback
if correct? == true
return "Correct!"

else
return "Incorrect."
end

end
end

1 change: 1 addition & 0 deletions spec/card_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require './lib/card'
require 'rspec'

RSpec.describe Card do
it 'exists' do
Expand Down
44 changes: 44 additions & 0 deletions spec/deck_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require './lib/card'
require './lib/deck'
require 'pry'

describe Deck do
it 'exist' do
card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography)
card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM)
card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM)
cards = ([card_1, card_2, card_3])
deck = Deck.new(cards)
expect(deck).to be_a Deck
end

it 'has cards' do
card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography)
card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM)
card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM)
cards = ([card_1, card_2, card_3])
deck = Deck.new(cards)
expect(deck.cards).to eq(cards)
end

it 'should count the cards' do
card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography)
card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM)
card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM)
cards = ([card_1, card_2, card_3])
deck = Deck.new(cards)
expect(deck.count).to eq(3)
end

it 'can identify cards in a category' do
card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography)
card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM)
card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM)
cards = ([card_1, card_2, card_3])
deck = Deck.new(cards)

expect(deck.cards_in_category(:STEM)).to eq([card_2, card_3])
expect(deck.cards_in_category(:Geography)).to eq([card_1])
expect(deck.cards_in_category(:Pop_Culture)).to eq([])
end
end
127 changes: 127 additions & 0 deletions spec/round_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
require './lib/card'
require './lib/turn'
require './lib/deck'
require './lib/round'
require 'pry'

describe Round do

it 'exists' do
card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography)
card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM)
card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM)
deck = Deck.new([card_1, card_2, card_3])
round = Round.new(deck)
expect(round).to be_a(Round)
end

it 'has a deck' do
card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography)
card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM)
card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM)
deck = Deck.new([card_1, card_2, card_3])
round = Round.new(deck)
expect(round.deck).to eq(deck)
end

it 'has turns' do
card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography)
card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM)
card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM)
deck = Deck.new([card_1, card_2, card_3])
round = Round.new(deck)
expect(round.turns).to eq([])
end

it 'has a current card' do
card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography)
card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM)
card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM)
deck = Deck.new([card_1, card_2, card_3])
round = Round.new(deck)
expect(round.current_card).to eq(card_1)
end

it 'can take a turn' do
card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography)
card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM)
card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM)
deck = Deck.new([card_1, card_2, card_3])
round = Round.new(deck)

new_turn = round.take_turn("Juneau")

expect(new_turn).to be_a(Turn)
expect(new_turn.correct?).to eq(true)
expect(round.turns).to eq([new_turn])
end

it 'can count how many are correct' do
card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography)
card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM)
card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM)
deck = Deck.new([card_1, card_2, card_3])
round = Round.new(deck)

round.take_turn("Juneau")
expect(round.number_correct).to eq(1)
end

it 'can switch cards' do
card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography)
card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM)
card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM)
deck = Deck.new([card_1, card_2, card_3])
round = Round.new(deck)

expect(round.current_card).to eq(card_1)
round.take_turn("Juneau")

expect(round.current_card).to eq(card_2)
round.take_turn("Venus")

expect(round.current_card).to eq(card_3)
end

it 'can count how many correct answers in a category' do
card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography)
card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM)
card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM)
deck = Deck.new([card_1, card_2, card_3])
round = Round.new(deck)

round.take_turn("Juneau")
round.take_turn("Venus")

expect(round.number_correct_by_category(:Geography)).to eq(1)

expect(round.number_correct_by_category(:STEM)).to eq(0)
end

it 'can evaluate percentage of correct answers' do
card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography)
card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM)
card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM)
deck = Deck.new([card_1, card_2, card_3])
round = Round.new(deck)

round.take_turn("Juneau")
round.take_turn("Venus")

expect(round.percent_correct).to eq(50.0)
end

it 'can round correct answers in category' do
card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography)
card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM)
card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM)
deck = Deck.new([card_1, card_2, card_3])
round = Round.new(deck)

round.take_turn("Juneau")
round.take_turn("Venus")

expect(round.percent_correct_by_category(:Geography)).to eq(100.0)
end

end
Loading