QMainWindow(parent),
ui(new Ui::MainWindow)
{
- bestScore=0;
- readSettings();
+ bestScore=0;
+ readSettings();
ui->setupUi(this);
statusLed = new QLed(ui->verticalLayoutWidget);
ui->horizontalLayout_4->insertWidget(0,statusLed);
sscore.append("\n Best score: ");
sscore.append(QString::number(bestScore));
QMessageBox::warning(this, tr("End Game"),sscore,QMessageBox::Escape);
- //tread.genera();
- exit(0);
+ bestScore=0;
+ readSettings();
+ tread.genera();
+
+ //exit(0);
}
void MainWindow::disableAll(){
#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;
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)
{
emit score(_score);
if(index==sequenza.size()){
sleep(1);
- attendiInputUtente=false;
+ attendiInputUtente.wakeAll();
index=0;
}
}
_score=0;
sequenza.clear();
index=0;
- attendiInputUtente=true;
+ attendiInputUtente.wakeAll();
}
- }
+
}
void TestThread::genera()
{
- attendiInputUtente=false;
+ attendiInputUtente.wakeAll();
}
#define TESTTHREAD_H
#include <QThread>
+#include <QWaitCondition>
+#include <QMutex>
class TestThread : public QThread
private:
+ QWaitCondition attendiInputUtente;
int colore;
int index;
int _score;
- bool attendiInputUtente;
+ QMutex mutex;
QList<int> sequenza;
};
#endif // TESTTHREAD_H