Inizio Progetto
[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
10     _score=0;
11     index=0;
12
13     qsrand(QDateTime::currentDateTime().toTime_t());
14
15 }
16 TestThread::~TestThread(){
17
18 }
19 void TestThread::run()
20 {
21     while(true){
22         //msleep(200);
23         qsrand(QDateTime::currentDateTime().toTime_t());
24         sequenza.append(qrand()%9);
25         int i=0;
26
27         qDebug()<<"Init Emission";
28         emit disableInterface();
29         while(i<sequenza.size())
30         {
31           qDebug()<<"Init Generate";
32           emit generate(sequenza.at(i));
33           qDebug()<<sequenza.at(i);
34           msleep(500 - (_score*5));
35           emit generate(sequenza.at(i));
36           msleep(500 - (_score*5));
37           i++;
38         }
39         i=0;
40         attendiInputUtente=true;
41         emit enableInterface();
42
43         while(attendiInputUtente){
44             msleep(1);
45         } ;
46     }
47
48
49 }
50
51 void TestThread::updateCaption(int inputUser)
52 {
53      qDebug()<<"Entro in update Caption ="<< inputUser<< " valore aspettato" << sequenza.at(index);
54      if (attendiInputUtente){
55
56         if(sequenza.at(index) == inputUser)
57         {
58             if(index == sequenza.size() - 1){
59                 qDebug()<<"Entro in if if ="<< inputUser<< " valore aspettato" << sequenza.at(index);
60                 attendiInputUtente=false;
61                 index=0;
62             }else
63             {
64                 index++;
65                 _score++;
66             }
67         }
68         else{
69             emit score(_score);
70             _score=0;
71             sequenza.clear();
72             index=0;
73             attendiInputUtente=true;
74         }
75     }
76 }
77
78 void TestThread::genera()
79 {
80     attendiInputUtente=false;
81
82 }