#include <QDateTime>
TestThread::TestThread(QObject *parent):QThread(parent){
colore=0;
- attendiInputUtente=false;
+
index=0;
_score=0;
}
void TestThread::run(){
+ sleep(1);
while(true){
-
+ mutex.lock();
qsrand(QDateTime::currentDateTime().toTime_t());
sequenza.append(qrand()%9);
int i=0;
{
emit generate(sequenza.at(i));
qDebug()<<sequenza.at(i);
- msleep(500 - (_score*5));
+ msleep(500 - (_score*2));
emit generate(sequenza.at(i));
- msleep(500 - (_score*5));
+ msleep(500 - (_score*2));
i++;
}
i=0;
- attendiInputUtente=true;
emit enableInterface();
+ attendiInputUtente.wait(&mutex);
+
+ mutex.unlock();
- while(attendiInputUtente){
- msleep(1);
- }
}
void TestThread::updateCaption(int inputUser){
- if(attendiInputUtente){
+
if(sequenza.at(index)==inputUser)
{
_score++;
emit score(_score);
if(index==sequenza.size()){
- attendiInputUtente=false;
+ sleep(1);
+ attendiInputUtente.wakeAll();
index=0;
}
}
_score=0;
sequenza.clear();
index=0;
- attendiInputUtente=true;
+ attendiInputUtente.wakeAll();
}
- }
+
}
void TestThread::genera()
{
- attendiInputUtente=false;
+ attendiInputUtente.wakeAll();
}