Modifiche al led
[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     while(true){
20
21     qsrand(QDateTime::currentDateTime().toTime_t());
22     sequenza.append(qrand()%9);
23     int i=0;
24     index=0;
25
26     emit disableInterface();
27     while(i<sequenza.size())
28     {
29       emit generate(sequenza.at(i));
30       qDebug()<<sequenza.at(i);
31       msleep(500 - (_score*5));
32       emit generate(sequenza.at(i));
33       msleep(500 - (_score*5));
34       i++;
35     }
36     i=0;
37     attendiInputUtente=true;
38     emit enableInterface();
39
40     while(attendiInputUtente){
41         msleep(1);
42     }
43     }
44
45
46 }
47
48 void TestThread::updateCaption(int inputUser){
49
50     if(attendiInputUtente){
51
52         if(sequenza.at(index)==inputUser)
53         {
54             index++;
55             _score++;
56             emit score(_score);
57             if(index==sequenza.size()){
58                 attendiInputUtente=false;
59                 index=0;
60             }
61         }
62         else{
63             emit exit(_score);
64             _score=0;
65             sequenza.clear();
66             index=0;
67             attendiInputUtente=true;
68         }
69     }
70 }
71
72 void TestThread::genera()
73 {
74
75     attendiInputUtente=false;
76
77 }