-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaraton.rb
71 lines (63 loc) · 1.28 KB
/
maraton.rb
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
require_relative 'view'
require_relative 'model'
class Maraton
def initialize
@view = View.new
@deck = Deck.new
@res_correctas = 0
@res_incorrectas = 0
@view.pantalla_dinamica
@view.welcome()
theme_choice()
@view.pantalla_dinamica
interface()
end
def theme_choice
@view.theme
choice = gets.to_i
check = Integer(choice) rescue 0
if check.between?(1, 3)
case check
when 1
file = "history.csv"
when 2
file = "science.csv"
when 3
file = "pop.csv"
end
@deck.read_csv(file)
else
@view.pantalla_dinamica
@view.error
theme_choice()
end
end
def interface
while @deck.questions.length != 0
qa = get_question()
@view.question(qa)
user_answer = gets.chomp
check(user_answer,qa)
sleep(1)
@view.pantalla_dinamica
end
@view.final(@res_correctas, @res_incorrectas)
end
def get_question
max = @deck.questions.length - 1
num = rand(0..max)
qa = @deck.select(num)
end
def check(answer,qa)
answer.downcase!
qa[1].downcase!
if answer == qa[1]
@view.correcto()
@res_correctas += 1
else
@view.incorrecto()
@res_incorrectas += 1
end
end
end
Maraton.new