Last active
December 12, 2015 08:49
-
-
Save kmandreza/4747166 to your computer and use it in GitHub Desktop.
flashcard and sherif's notes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Flashcard #data structure | |
attr_accessor :term, :definition | |
def initialize(term,definition) | |
@term=term | |
@definition=definition | |
end | |
end | |
class Text_File_Parser | |
attr_accessor :flashcards_box | |
def initialize(filename) | |
@flashcards_box = [] | |
File.readlines(filename).each_slice(2) do |arr| | |
@flashcards_box << Flashcard.new(arr[1].chomp, arr[0].chomp) | |
end | |
#enter code that parses text file into FlashC | |
#@flashcards_box << Flashcard.new | |
end | |
end | |
#entry point - code lacks it. I don't know. driver code determines entry point | |
class Game | |
attr_accessor :game_card, :definition, :first_flash_card | |
def initialize(flashcards_box) | |
@flashcards_box = flashcards_box | |
@first_flash_card = flashcards_box[-1] #2. one card will be randomly picked from the libary | |
#3. definition is shown to user, term is not. | |
end | |
def display_defition | |
end | |
def guess | |
loop do | |
if input != @game_card[1] | |
puts "Incorrect! Try Again" | |
else input == @game_card[1] | |
puts "Correct!" #4. If user guesses correct term, user is told "Correct!" | |
@game_card.delete | |
end | |
input = gets #when user enters an input, it calls gets, and assigns the string to variable input | |
end | |
end | |
def delete_flash_card | |
@flashcards_box.pop # behaviour delete from data structure | |
end | |
def game_over | |
input = gets | |
until input == "\n" | |
if @flashcards_box == 0 #Once card library is empty, user is told | |
puts "Game Over! Enter 1 to Start Over or Enter to exit game." | |
else input == 1 #how do I have the user enter 1? | |
#start new game | |
end | |
input = gets | |
end | |
end | |
end | |
# parse the file and return flash cards as an array | |
text_file_object= Text_File_Parser.new("flashcards.txt") | |
flashcards_array= text_file_object.flashcards_box | |
#puts flashcards_array.inspect | |
# start the game with the flash cards array | |
new_game = Game.new(flashcards_array) | |
#puts new_game | |
# the game will display the definition of the first flash card's | |
#def | |
flash_card_object = new_game.first_flash_card | |
#puts flash_card_object.definition | |
# the game will take the user's guess and compare their guess | |
# against the term associated with the definition | |
# the game will return whether the guess is correct or incorrect | |
# input = gets.chomp | |
# if input == flash_card_object.term | |
# puts "Correct!" | |
# else | |
# puts "Incorrect! Try Again" | |
# end | |
# if the user's input is correct, the game will inform the user | |
# "correct!" and then produce the next flash card and inputs | |
# definition | |
new_game.delete_flash_card | |
puts flashcards_array | |
# if the user's input is incorrect, the game will inform the user | |
# "incorrect" and the game will expect user input that will then: | |
# 1. let user guess Again | |
# 2. let user skip the question | |
# 3. let user see the answer | |
# the game will end once the user has viewed the entire | |
# flash card array | |
# once the game is over, the game will inform the user that they | |
# can start over or exit. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# filename = "data.txt" | |
# # - open the file | |
# # File.open(filename) | |
# # # - read the data | |
# # File.open(filename).read | |
# # p "hello world".split(//)s.each_slice(1) | |
# # [1,2,3,4,5].each_slice(3) do |v| | |
# # p v | |
# # end | |
# # # - reformat it to some useful format | |
# # arr = [] | |
# File.open(filename).readlines.each_slice(3) do |line| | |
# puts line[0] #definition | |
# puts | |
# puts line[1] #term | |
# puts "---" | |
# # - use it | |
# end | |
class Parser | |
attr_reader :definition, :term | |
def initialize(filename) | |
@definition = # get the defn | |
@term = # get the term | |
end | |
def load_file(filename) | |
end | |
end | |
parser = Parser.new("data.txt") | |
puts parser.definition | |
puts parser.term |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment