forked from moevm/gui-1h2017-14
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestcards.cpp
91 lines (79 loc) · 1.74 KB
/
questcards.cpp
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "questcards.h"
QuestCards::QuestCards()
{
}
QuestCards::~QuestCards()
{
}
QString QuestCards::getRightAnswerId()
{
return QString::number(answerId);
}
QString QuestCards::getRightAnswerName()
{
QSqlQuery query("SELECT id, name FROM " + type + " WHERE id IS \"" + QString::number(answerId) + "\"");
QString id_str;
QString name_str;
while (query.next())
{
id_str = query.value(0).toString();
name_str = query.value(1).toString();
}
return name_str;
}
QString QuestCards::getUsedSize()
{
return QString::number(usedContent.size()-1);
}
int QuestCards::getNum()
{
int randomId = qrand() % N +1;
QListIterator <int> id(usedContent);
while(id.hasNext()){
if(randomId == id.next()){
return randomId = getNum();
}
}
return randomId;
}
void QuestCards::getRandomAns()
{
if (N > 3){
bool check = true;
randomId.clear();
for (int i = 0; i < 3; i++){
int id = qrand() % N +1;
QListIterator <int> id_iter(randomId);
if (id == answerId){
i--;
continue;
}
else
while(id_iter.hasNext()){
if(id == id_iter.next()){
i--;
check = false;
break;
}
}
if(check)
randomId.append(id);
else
check = true;
}
}
}
void QuestCards::erase()
{
usedContent.clear();
randomId.clear();
answerId = 0;
N = 0;
}
bool QuestCards::checkAnswer(int id)
{
if (randomId.at(id) == answerId)
return true;
else
return false;
}