diff --git a/lib/Deck.rb b/lib/Deck.rb new file mode 100644 index 000000000..790adf9c9 --- /dev/null +++ b/lib/Deck.rb @@ -0,0 +1,17 @@ +class Deck + + attr_reader :card, :counts + + def initialize(card, count) + @count = count + @card = card + end + + def count + @card.count + end + + def cards_in_category(catagory) + @card.select {|card| card.caregory == catagory} + end +end \ No newline at end of file diff --git a/lib/card.rb b/lib/card.rb index e69de29bb..52bc52b56 100644 --- a/lib/card.rb +++ b/lib/card.rb @@ -0,0 +1,10 @@ +class Card + + attr_reader :question, :answer, :category + + def initialize(question, answer, category) + @answer = answer + @question = question + @category = category + end +end \ No newline at end of file diff --git a/lib/round.rb b/lib/round.rb new file mode 100644 index 000000000..b7e828729 --- /dev/null +++ b/lib/round.rb @@ -0,0 +1,67 @@ +class Round + + attr_reader :deck, :turns, :current_card + + def initialize(guess, turns) + @deck = deck + @turns = [] + @current_card = current_card + end + + def new_turn(guess) + new_turn = Turn.new(guess, current_card) + @turns << new_turn + @current_card = deck.card[@turns.count] + end + + def current_card(card) + @card.current_card + end + + def take_turn(card) + take_turn == @current_card + end + + def number_correct + if @turns.correct? + 1 + else + 0 + end + end + + def turns_count + @turns.count == 2 + end + + def turns_last_feedback(turns) + last_turn = turns.last + last_turn.feedback + end + + def number_of_catagorys_correct_in(deck) + geography_catagory = catagory.correct + geography_catagory.feedback + end + + def number_of_catagorys_correct_in(deck) + stem_catagory = catagory.correct + stem_catagory.feedback + end + + def percent_correct(deck) + deck = @deck.size + @deck.count do |deck| + end + percent = (deck.correct / deck) + perecent.round(2) + end + + def perecent_correct_by_category(deck) + deck = @deck.size + catagory_correct = @deck.count do |game| + end + percent = (catagory_correct / catagory) + percent.round(2) + end +end \ No newline at end of file diff --git a/lib/runner.rb b/lib/runner.rb new file mode 100644 index 000000000..fb0890981 --- /dev/null +++ b/lib/runner.rb @@ -0,0 +1,24 @@ +require './lib/card.rb' +require './lib/deck.rb' +require './lib/round.rb' +require './lib/turn.rb' + +puts "Welcome to Brody's flashcard game!" +puts "--------------------------------------" +puts "press P to start or Q to quit!" + +def play + deck.cards.each do |card| + puts "Question #{card.question}" + + + +input = gets.chomp.upcase + +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) + +game.play \ No newline at end of file diff --git a/lib/turn.rb b/lib/turn.rb new file mode 100644 index 000000000..db3d3faee --- /dev/null +++ b/lib/turn.rb @@ -0,0 +1,19 @@ +class Turn + + attr_reader :card, :guess + + def initialize(card, guess) + @card = card + @guess = guess + end + + def correct? + @guess.downcase == @card.answer.downcase + else + false + end + + def feedback(guess) + @guess.correct == false + end +end \ No newline at end of file diff --git a/spec/Round_spec.rb b/spec/Round_spec.rb new file mode 100644 index 000000000..b11400762 --- /dev/null +++ b/spec/Round_spec.rb @@ -0,0 +1,122 @@ +require './lib/card' +require './lib/turn' +require './lib/deck' +require './lib/round' + +Respec.describe Round do + it 'describes Round class' 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(Round) + expect(round.turns).to eq([]) + expect(round.current_card).to eq(card_1) + end + + it + + it 'starts a new round' 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 = Turn.new(guess, current_card) + + expect(round.new_turn). to eq([]) + end + + it 'number of correct scores' 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.number_correct).to eq(1) + end + + it 'shows correct cards at play' 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 'takes 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.take_turn("Venus")).to eq(turn) + end + + it 'current counts at play' 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.count).to eq(2) + end + + it 'displays last turn feedback' 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.last.feedback).to eq("Incorrect") + end + + it 'shows catagorys correct in (:Geography)' 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.number_correct_by_category(:Geography)). to eq(1) + end + + it 'shows catagorys correct in (:STEM)' 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.number_correct_by_category(:STEM)).to eq(0) + end + + it 'calculates percent of 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) + + expect(round.percent_correct).to eq(50.0) + end + + it 'calculates percent by 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) + + expect(round.percent_correct_by_category(:Geography)).to eq(100.0) + end +end \ No newline at end of file diff --git a/spec/deck_spec.rb b/spec/deck_spec.rb new file mode 100644 index 000000000..deba12453 --- /dev/null +++ b/spec/deck_spec.rb @@ -0,0 +1,36 @@ +require './lib/card' +require './lib/deck' + +Respec.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) + deck = Deck.new(cards) + + expect(deck.card).to eq ([card_1, card_2, card_3]) + end + + it 'counts 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(cards) + + expect(deck.count).to eq(3) + end + + it 'has categorys' 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]) + + 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([]) + expect(deck.cards_in_category(:STEM)).to be_a(Array) + expect(deck.cards_in_category(:Geography)).to be_a(Array) + expect(deck.cards_in_category(:Pop_Culture)).to be_a(Array) + end +end diff --git a/spec/turn_spec.rb b/spec/turn_spec.rb new file mode 100644 index 000000000..d39931f8a --- /dev/null +++ b/spec/turn_spec.rb @@ -0,0 +1,34 @@ +require './lib/turn' +require './lib/card' + +Respec.describe Turn do + it 'describes turn class' do + turn = Turn.new("Saturn", card) + + expect(turn).to be_instance_of(Turn) + end + + it 'has an answer' do + turn = Turn.new("Saturn", card) + + expect(turn.answer).to eq("Mercury") + end + + it 'has a question' do + turn = Turn.new("Saturn", card) + + expect(turn.question).to eq("Which planest is closest to the sun?") + end + + it 'has a catagory' do + turn = Turn.new("Saturn", card) + + expect(turn.catagory).to eq(:STEM) + end + + it 'gives feedback' do + turn = Turn.new("Saturn", card) + + expect(@guess.correct).to be false + end +end \ No newline at end of file