From d9d083393abda0a28eb718de3000466513aa6b91 Mon Sep 17 00:00:00 2001 From: giersch Date: Wed, 21 Nov 2007 07:27:57 +0000 Subject: [PATCH] . --- DrawingWindow.cpp | 17 +++++++++++++++++ DrawingWindow.h | 2 ++ chateaux/chateaux.cpp | 33 +++++++++++++++++++++++++-------- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/DrawingWindow.cpp b/DrawingWindow.cpp index 4cbccc3..9af145f 100644 --- a/DrawingWindow.cpp +++ b/DrawingWindow.cpp @@ -163,6 +163,11 @@ bool DrawingWindow::sync(unsigned long time) return synced; } +void DrawingWindow::closeGraph() +{ + qApp->postEvent(this, new QCloseEvent()); +} + void DrawingWindow::sleep(unsigned long secs) { DrawingThread::sleep(secs); @@ -180,19 +185,31 @@ void DrawingWindow::usleep(unsigned long usecs) void DrawingWindow::closeEvent(QCloseEvent *ev) { + qDebug(">>>CLOSING<<<\n"); + char x = 'A'; + qDebug(">>> %c <<<\n", x++); timer.stop(); + qDebug(">>> %c <<<\n", x++); thread->terminate(); + qDebug(">>> %c <<<\n", x++); syncMutex.lock(); + qDebug(">>> %c <<<\n", x++); terminateThread = true; // this flag is needed for the case // where the following wakeAll() call // occurs between the // setTerminationEnable(false) and the // mutex lock in safeLock() called // from sync() + qDebug(">>> %c <<<\n", x++); syncCondition.wakeAll(); + qDebug(">>> %c <<<\n", x++); syncMutex.unlock(); + qDebug(">>> %c <<<\n", x++); QWidget::closeEvent(ev); + qDebug(">>> %c <<<\n", x++); thread->wait(); + qDebug(">>> %c <<<\n", x++); + qDebug(">>>CLOSED<<<\n"); } void DrawingWindow::customEvent(QEvent *) diff --git a/DrawingWindow.h b/DrawingWindow.h index 28dc14b..17253ba 100644 --- a/DrawingWindow.h +++ b/DrawingWindow.h @@ -52,6 +52,8 @@ public: bool sync(unsigned long time = ULONG_MAX); + void closeGraph(); + void sleep(unsigned long secs); void msleep(unsigned long msecs); void usleep(unsigned long usecs); diff --git a/chateaux/chateaux.cpp b/chateaux/chateaux.cpp index 8f802b2..7f4d093 100644 --- a/chateaux/chateaux.cpp +++ b/chateaux/chateaux.cpp @@ -258,7 +258,7 @@ int tir(DrawingWindow& w, return collision == 3 ? 0 : collision; } -void jeu1(DrawingWindow& w) +int jeu1(DrawingWindow& w) { initialise(w); int joueur = 2; @@ -267,19 +267,19 @@ void jeu1(DrawingWindow& w) do { joueur = 3 - joueur; - std::cout << "-=| Joueur " << joueur << " |=-\n"; + std::cout << "-=| Joueur " << joueur << " |=-"; float alpha; float v0; if (joueur <= nbJoueurs) { - std::cout << "angle ? "; + std::cout << "\nangle ? "; std::cin >> alpha; std::cout << "vitesse initiale ? "; std::cin >> v0; } else { alpha = frand(10, 90); v0 = frand(10, 100); - std::cout << "[ " << alpha << " ; " << v0 << " ]\n"; + std::cout << " [ " << alpha << " ; " << v0 << " ]\n"; } alpha = deg2rad(alpha); @@ -302,14 +302,31 @@ void jeu1(DrawingWindow& w) else std::cout << " a perdu"; std::cout << " !\n"; + return perdant; } void jeu(DrawingWindow& w) { - while (1) { - jeu1(w); - w.sleep(5); - } + int score1 = 0; + int score2 = 0; + bool rejouer = true; + do { + int perdant = jeu1(w); + if (perdant == 1) + score2++; + else if (perdant == 2) + score1++; + std::cout << "### SCORE : " << score1 << " / " << score2 << " ###\n"; + if (nbJoueurs == 0) + w.sleep(2); + else { + char r; + std::cout << "Recommencer (o/n) ? "; + std::cin >> r; + rejouer = r == 'o'; + } + } while (rejouer); + w.closeGraph(); } int main(int argc, char *argv[]) -- 2.20.1