forked from UWOneLaptop/Geography-Quiz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeographyQuiz.py
59 lines (44 loc) · 1.57 KB
/
GeographyQuiz.py
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
class QuestionInfo:
def __init__(self, qID, question, image):
self.qID = qID
self.question = question
self.image = image
class QuizMain:
# Returns the ID of the current question
def __currID(self):
return self.qDatabase[self.currDatabaseIndex]
# Retrieve the information for the current question.
# Returns a QuestionInfo object containing the information for the current question.
def getQuestionInfo(self):
qID = self.__currID()
question = getQuestionLabel( qID )
imageFile = getQuestionImage( qID )
return QuestionInfo( qID, question, imageFile)
# Increments the current question to the next in the database.
# Returns false if there is no next question.
def updateToNextQuestion(self):
self.currDatabaseIndex = self.currDatabaseIndex + 1
if self.currDatabaseIndex >= self.qDatabase.length:
return False
self.currQuestion = self.getQuestionInfo()
return True
# Accepts a user userGuess and compares it to the true answer.
# Returns true if they userGuess is right, false if not.
def submitAnswer(self, userGuess):
trueAnswer = getQuestionAnswer()
isCorrect = (trueAnswer == userGuess)
# handle whether trueAnswer is correct or not
if isCorrect:
self.updateToNextQuestion()
return isCorrect
# Start the operation of the game
# def main(self):
# initialize the GUI
# Initialize the internal state of the quiz game, drawing info from the database
def __init__(self):
self.qDatabase = getQuestions()
self.currDatabaseIndex = 0
self.currQuestion = self.getQuestionInfo()
if __name__ == "__main__":
quiz = QuizMain()
quiz.main()