Experience in application does not answer repeated random realization of ivx

In some cases, often by allowing users to answer a few questions to do some interactive effects, such as questionnaires, quizzes and other checkpoints, today share one such case in a way to extract the subject. This demo is a realization of a random sample not repeat function problems, namely the background altogether 10 topics, each time a user opens a case, it will start with the background allowing users to randomly pop star a question, if answered correctly from the rest of the title again a randomly selected until the user got the wrong answer or answer all the questions, Here to talk about specific ideas and methods to achieve it.

I. design ideas
1. Open the case when the background all the problems of question number output to a one-dimensional array in the foreground.
2. randomly selected a number of questions from a storage array, which is then removed from the question number one-dimensional array in a variable.
3. database to acquires the title of the title number as the first question.
4. When the user answer the step 2 is repeated until the user completely wrong answer or portion subject.

II. Implementation
1. Database
First, all questions are stored in the database, we need to design the structure of the database. Indispensable to have a problem, various options and answers field, and we also need to extract a title number, because the data ID is not repeated, so here we can directly use the data for each question ID as the title of Question number.
Here Insert Picture Description
2. Service
in accordance with design ideas, we have the operation of the database to obtain the title number and title extracting two kinds, so two corresponding service.
Acquiring the first question number database services all of the output, and then outputs the result acquired two-dimensional array pattern, since data ID is the first column in the database, i.e. in the two-dimensional array corresponding to the column number 0, so that the its return to service as a result.
Here Insert Picture Description
The extracted title services, we need to tell the back-end database to extract data in which the question number, so you need to add a parameter to receive "receives the title number", then the output data piece of ID with "receiving the title number" equal from the database , will return as a result of the service.
Here Insert Picture Description
3. foreground initialization
reception of a call initialization initializing operation group, the operation of the specific operation is the first group call to get the item number service, the value after completion of the variable "answer number and a score of" set to 1 in the acquisition, this variable is used to store a few questions to the first user but also can be used to calculate the user's answer fraction, is returned to service and assign the result to the front one-dimensional array "title number", a random element from the "question" is output to the variable value "extraction title number", and then remove the element from the "question" in case the number of elements "title number" is the remaining number in the subject, assign it to the variable value "remaining title", the last is the "extracting the title number" obtain title passed to the service, the service will return the results of an array of objects assigned to the front of the "title."
Here Insert Picture Description
To give the system some of the running time, we can first use a page banner will be covered when the user clicks the answer button start, let banner hide, show answer page.
Here Insert Picture Description
4. clicker assembly portion
Answer section with five titles and text components display the various options, respectively, where the front desk and an array of objects "title" directly do data binding, when acquiring title to get the service to return results can be displayed directly.
Here Insert Picture Description
Here Insert Picture Description
Then also uses a banner to show the final result of the answer, if the answer is all subject clearance text is displayed, if not the score displayed, the text component score data content has a binding value of the variable "answer number and a score of" Save value of 1, you can click another button to re-answer repeated answer.
Here Insert Picture Description
The event is part of the answer
four display options for text components are added click event, here to show options D text component as an example. When the user clicks to determine array of objects "title" is stored in the answer is D, if the problem is a pumping action group is executed, however, shows that is not the answer.

Title pumping action-group first determines whether the remaining entitled 0, it indicates that if the user has all the subject answer, then it will be set to clearance banner displayed state and, if not from the one-dimensional array "Question" re-randomized extracting a title number, service number and title passed to get to perform, and then delete the number from the title "question", the "remaining title" minus 1, then return to service assign the result to an array of objects "title" and finally value of the variable "answer number and a score of" plus 1.
Here Insert Picture Description
Here Insert Picture Description
Click the button to answer calls to re-initialize the action group and answer results in a popping box reset action group, the case status is fully initialized.
Here Insert Picture Description

Guess you like

Origin blog.51cto.com/14556317/2484778