Trivia game analysis in Pygame 6-1

1 Trivia game introduction

       Trivia means "various knowledge in quiz competitions". The Trivia game is similar to a quiz. The computer sets the questions and the players answer the questions. The computer then judges the players' answers, gives the results and scores them. The interface of the game is shown in Figure 1.

Figure 1 Trivia game interface

2 Game flow

The game flow of Triavia is shown in Figure 2.

Figure 2 Game flow

3 Implementation of Trivia class

In the Trivia game, a class named Trivia is created. The function of this class is to read and display questions, determine whether the user's answers are right or wrong, and process them accordingly.

3.1 __init__() method of Trivia class

This method initializes the variables used in the game, reads the file that saves the question, and processes the content of the read file.

3.1.1 Variable initialization

self.data = []
self.current = 0
self.total = 0
self.correct = 0
self.score = 0
self.scored = False
self.failed = False
self.wronganswer = 0
self.colors = [white,white,white,white]

Among them, data saves the processed question information, which is in row units; current indicates which row in the data the currently displayed content is located; total indicates the total number of rows of data in the data; correct indicates the correct answer to the current question; score represents the current score; when scored is True, it means that the user answered the current question correctly; when failed is True, it means that the user answered the current question incorrectly; wronganswer represents the wrong answer entered by the user, and colors represents the colors of the four options of the question.

Guess you like

Origin blog.csdn.net/hou09tian/article/details/132640581