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

Brody Nichols #619

Open
wants to merge 19 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
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 :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
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)
@answer = answer
@question = question
@category = category
end
end
67 changes: 67 additions & 0 deletions lib/round.rb
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions lib/runner.rb
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions lib/turn.rb
Original file line number Diff line number Diff line change
@@ -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
122 changes: 122 additions & 0 deletions spec/Round_spec.rb
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions spec/deck_spec.rb
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions spec/turn_spec.rb
Original file line number Diff line number Diff line change
@@ -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