Pulizia repository
[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     attendiInputUtente=false;
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
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     attendiInputUtente=true;
39     emit enableInterface();
40
41     while(attendiInputUtente){
42         msleep(1);
43     }
44     }
45
46
47 }
48
49 void TestThread::updateCaption(int inputUser){
50
51     if(attendiInputUtente){
52
53         if(sequenza.at(index)==inputUser)
54         {
55             index++;
56             _score++;
57             emit score(_score);
58             if(index==sequenza.size()){
59                 sleep(1);
60                 attendiInputUtente=false;
61                 index=0;
62             }
63         }
64         else{
65             emit exit(_score);
66             _score=0;
67             sequenza.clear();
68             index=0;
69             attendiInputUtente=true;
70         }
71     }
72 }
73
74 void TestThread::genera()
75 {
76
77     attendiInputUtente=false;
78
79 }