-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathterm_quiz.go
55 lines (46 loc) · 1.04 KB
/
term_quiz.go
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
package quiz
import (
"github.com/jroimartin/gocui"
"strconv"
)
//Init -- The Init function decides which sub Init function should be called
//ABCDInint, TFInit or FBInit
func Init(g *gocui.Gui) (err error) {
//Have we reached the question limit?
if Questions.Index >= QuestionLimit {
//Need to call End Screen
ESInit(g, UserAnswers)
return nil
}
//Have we ran out of questions?
if Questions.Index >= len(Questions.Questions) {
//Need to call End Screen
ESInit(g, UserAnswers)
return nil
}
//Get current question
q, err := Questions.Current()
if err != nil {
return err
}
//Use number of answers to figure out which Init function to use
numOfAnswers := len(q.Answers.Answers)
count := "Question " + strconv.Itoa(len(UserAnswers)+1)
if numOfAnswers == 4 {
err = ABCDInit(g, q, count)
if err != nil {
return err
}
} else if numOfAnswers == 2 {
err = TFInit(g, q, count)
if err != nil {
return err
}
} else if numOfAnswers == 1 {
err = FBInit(g, q, count)
if err != nil {
return err
}
}
return nil
}