Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
.
authorgiersch <giersch>
Wed, 21 Nov 2007 07:27:57 +0000 (07:27 +0000)
committergiersch <giersch>
Wed, 21 Nov 2007 07:27:57 +0000 (07:27 +0000)
DrawingWindow.cpp
DrawingWindow.h
chateaux/chateaux.cpp

index 4cbccc3..9af145f 100644 (file)
@@ -163,6 +163,11 @@ bool DrawingWindow::sync(unsigned long time)
     return synced;
 }
 
     return synced;
 }
 
+void DrawingWindow::closeGraph()
+{
+    qApp->postEvent(this, new QCloseEvent());
+}
+
 void DrawingWindow::sleep(unsigned long secs)
 {
     DrawingThread::sleep(secs);
 void DrawingWindow::sleep(unsigned long secs)
 {
     DrawingThread::sleep(secs);
@@ -180,19 +185,31 @@ void DrawingWindow::usleep(unsigned long usecs)
 
 void DrawingWindow::closeEvent(QCloseEvent *ev)
 {
 
 void DrawingWindow::closeEvent(QCloseEvent *ev)
 {
+    qDebug(">>>CLOSING<<<\n");
+    char x = 'A';
+    qDebug(">>> %c <<<\n", x++);
     timer.stop();
     timer.stop();
+    qDebug(">>> %c <<<\n", x++);
     thread->terminate();
     thread->terminate();
+    qDebug(">>> %c <<<\n", x++);
     syncMutex.lock();
     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()
     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();
     syncCondition.wakeAll();
+    qDebug(">>> %c <<<\n", x++);
     syncMutex.unlock();
     syncMutex.unlock();
+    qDebug(">>> %c <<<\n", x++);
     QWidget::closeEvent(ev);
     QWidget::closeEvent(ev);
+    qDebug(">>> %c <<<\n", x++);
     thread->wait();
     thread->wait();
+    qDebug(">>> %c <<<\n", x++);
+    qDebug(">>>CLOSED<<<\n");
 }
 
 void DrawingWindow::customEvent(QEvent *)
 }
 
 void DrawingWindow::customEvent(QEvent *)
index 28dc14b..17253ba 100644 (file)
@@ -52,6 +52,8 @@ public:
 
     bool sync(unsigned long time = ULONG_MAX);
 
 
     bool sync(unsigned long time = ULONG_MAX);
 
+    void closeGraph();
+
     void sleep(unsigned long secs);
     void msleep(unsigned long msecs);
     void usleep(unsigned long usecs);
     void sleep(unsigned long secs);
     void msleep(unsigned long msecs);
     void usleep(unsigned long usecs);
index 8f802b2..7f4d093 100644 (file)
@@ -258,7 +258,7 @@ int tir(DrawingWindow& w,
     return collision == 3 ? 0 : collision;
 }
 
     return collision == 3 ? 0 : collision;
 }
 
-void jeu1(DrawingWindow& w)
+int jeu1(DrawingWindow& w)
 {
     initialise(w);
     int joueur = 2;
 {
     initialise(w);
     int joueur = 2;
@@ -267,19 +267,19 @@ void jeu1(DrawingWindow& w)
     do {
         joueur = 3 - joueur;
 
     do {
         joueur = 3 - joueur;
 
-        std::cout << "-=| Joueur " << joueur << " |=-\n";
+        std::cout << "-=| Joueur " << joueur << " |=-";
 
         float alpha;
         float v0;
         if (joueur <= nbJoueurs) {
 
         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::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);
         }
 
         alpha = deg2rad(alpha);
@@ -302,14 +302,31 @@ void jeu1(DrawingWindow& w)
     else
         std::cout << " a perdu";
     std::cout << " !\n";
     else
         std::cout << " a perdu";
     std::cout << " !\n";
+    return perdant;
 }
 
 void jeu(DrawingWindow& w)
 {
 }
 
 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[])
 }
 
 int main(int argc, char *argv[])