e3087e1ef0163ff8adc9b5fe3623552905c4a70a
[qmemory] / testThread.cpp
1 #include "testThread.h"
2 #include <QTimer>
3 #include <qdebug.h>
4 #include <QMessageBox>
5 #include <QDateTime>
6 TestThread::TestThread(QObject *parent):QThread(parent){
7     colore=0;
8
9     index=0;
10     _score=0;
11
12     qsrand(QDateTime::currentDateTime().toTime_t());
13
14 }
15 TestThread::~TestThread(){
16
17 }
18 void TestThread::run(){
19     sleep(1);
20     while(true){
21     mutex.lock();
22     qsrand(QDateTime::currentDateTime().toTime_t());
23     sequenza.append(qrand()%9);
24     int i=0;
25     index=0;
26
27     emit disableInterface();
28     while(i<sequenza.size())
29     {
30       emit generate(sequenza.at(i));
31       qDebug()<<sequenza.at(i);
32       msleep(500 - (_score*2));
33       emit generate(sequenza.at(i));
34       msleep(500 - (_score*2));
35       i++;
36     }
37     i=0;
38     emit enableInterface();
39     attendiInputUtente.wait(&mutex);
40
41     mutex.unlock();
42
43     }
44
45
46 }
47
48 void TestThread::updateCaption(int inputUser){
49
50
51
52         if(sequenza.at(index)==inputUser)
53         {
54             index++;
55             _score++;
56             emit score(_score);
57             if(index==sequenza.size()){
58                 sleep(1);
59                 attendiInputUtente.wakeAll();
60                 index=0;
61             }
62         }
63         else{
64             emit exit(_score);
65             _score=0;
66             sequenza.clear();
67             index=0;
68             attendiInputUtente.wakeAll();
69         }
70
71 }
72
73 void TestThread::genera()
74 {
75
76     attendiInputUtente.wakeAll();
77
78 }