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

Chase Phillips - Flash Cards #626

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
71 changes: 71 additions & 0 deletions flashcard_runner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
require './lib/card'
require './lib/turn'
require './lib/deck'
require './lib/round'

card_1 = Card.new("What state was Chase born in?", "Oregon", :Geography)
card_2 = Card.new("Is Chase one of the greatest scientific minds of our lifetime?", "No", :STEM)
card_3 = Card.new("What is Chase's favorite piece of technological innovation? ONE WORD ANSWERS ONLY, Chase doesn't have unlimited talk,text, OR data", "Microwave", :STEM)

cards = [card_1, card_2, card_3]

deck = Deck.new(cards)
round = Round.new(deck)

def start_game(round)
initial_card_count = round.deck.cards.size

puts ""
puts ""
puts ""
puts "Welcome! Chase would like to play his favorite game, he even gave it a cool title... HOW WELL DO YOU KNOW CHASE, the Trivia Game!!!"
puts ""
puts "***FURIOUS CLAPPING CAN BE HEARD ALL AROUND YOU***"
puts ""
puts "Why aren't you clapping? You should absolutely be clapping..."
puts ""
puts "-------------------------------------"
puts ""

while !round.deck.cards.empty? do
puts "This is question number #{round.turns.count + 1} of #{initial_card_count}....DUN DUN DUNNNNNNNN!..."
puts round.current_card.question
guess = gets.chomp
round.take_turn(guess)

if round.turns.last.correct?
puts round.turns.last.feedback
else
puts round.turns.last.feedback
end



end

def provide_feedback(round)

puts "--------------------------"
puts "This Game is OVER, do you really know Chase?!!"
puts "You answered #{round.percent_correct.round(1)} % of these questions correctly. That's okay I guess."
puts "-------------------------"
puts "You answered #{round.percent_correct_by_category(:Geography)} % of Chase's Geographical Mystery questions correctly."
puts "You answered #{round.percent_correct_by_category(:STEM)} % of the Chase In Stem questions correctly. Chase doesn't read books,especially cookbooks, reading is for NERDS."
puts "Thank you for being another lukewarm contestant on....HOW WELL DO YOU KNOW CHASE!!!"
puts ""
puts ""
puts " THIS GAME IS OVER WHY ARE YOU STILL LINGERING? Chase really doesn't appreciate LINGERERS!"






end

end

start_game(round)
provide_feedback(round)


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

def initialize(question, answer, category)
@question = question
@answer = answer
@category = category
end
end
21 changes: 21 additions & 0 deletions lib/deck.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Deck
attr_accessor :cards

def initialize(cards)
@cards = cards
end

def count
@cards.count
end

def cards_in_category(category)
category_array = []
@cards.each do |card|
if card.category == category
category_array << card
end
end
category_array
end
end
48 changes: 48 additions & 0 deletions lib/round.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
class Round
attr_reader :deck, :turns, :number_correct

def initialize(deck)
@deck = deck
@turns = []
@number_correct = 0

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
@number_correct += 1 if new_turn.correct?
new_turn
end

def number_correct_by_category(category)
number_correct = 0
turns.each do |turn|
if turn.card.category == category && turn.correct?
number_correct += 1
end
end
number_correct
end
def percent_correct
@number_correct / @turns.count.to_f * 100
end

def percent_correct_by_category(category)
number_correct_by_category(category) / number_by_category(category).to_f * 100
end
def number_by_category(category)
number = 0
turns.each do |turn|
if turn.card.category == category
number += 1
end
end
number
end
end
22 changes: 22 additions & 0 deletions lib/turn.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Turn
attr_reader :guess, :card

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

def correct?
# require "pry"; binding.pry VERY HELPFUL
@card.answer.strip.upcase == @guess.strip.upcase
end

def feedback
if correct?
"Correct"
else
"Incorrect"
end
end

end
1 change: 1 addition & 0 deletions spec/card_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
expect(card.category).to eq(:Geography)
end
end
#new changes
65 changes: 65 additions & 0 deletions spec/deck_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
require './lib/card'
require './lib/deck'

RSpec.describe Deck do
describe "#initialize" 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)

cards = [card_1, card_2, card_3]
deck = Deck.new(cards)
expect(deck).to be_instance_of(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
end


describe "#count" do
it "counts cards in 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)

cards = [card_1, card_2, card_3]
deck = Deck.new(cards)
expect(deck.count).to eq(3)
end
end

describe "cards_in_category" do
it "takes an argument of category and returns array of elements that match 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
end

Loading