forked from harrysboileau/ruby_flashcards_1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.rb
More file actions
72 lines (59 loc) · 1.36 KB
/
Copy pathcontroller.rb
File metadata and controls
72 lines (59 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require_relative 'view.rb'
require_relative 'model.rb'
class Controller
def initialize
@deck_object = Deck.new
@view = View.new
@input = nil
@question_count = 0
@guess_counter = 1
@deck_array_index = 0
end
def play!
send_intro_to_view
until @question_count >= deck_object.deck_array.length
pull_question
show_a_question
get_input
pull_answer
check_guess
end
end
private
attr_reader :view, :deck_object
def send_intro_to_view
view.display_prompt
end
def get_input
@input = view.get_typing
end
def show_a_question
view.display_question(@pulled_question)
end
def check_guess
if @input == @pulled_answer
view.display_correct_answer
next_card
@question_count += 1
elsif @input != @pulled_answer && @guess_counter == 3
view.display_incorrect_next_card
next_card
@question_count += 1
@guess_counter = 1
else
view.display_incorrect_answer
@guess_counter += 1
end
end
def pull_question
@pulled_question = deck_object.deck_array[@deck_array_index].question
end
def pull_answer
@pulled_answer = deck_object.deck_array[@deck_array_index].answer
end
def next_card
@deck_array_index += 1
end
end
supernintendo_chalmers = Controller.new
supernintendo_chalmers.play!