works
[multypo.git] / qt / multypo.cpp
index e6befe2535fd113b0ecaceb798ea04d7befda7c6..8dea3e025abeea2b8ca1aa2aaa25dbd7d64d741e 100644 (file)
@@ -41,9 +41,19 @@ void MultypoWindow::resetPlayerText() {
 }
 
 void MultypoWindow::nextWord() {
-       QByteArray tmp = words.readLine();
+       QByteArray tmp = words.readLine().trimmed();
        QString word = QString::fromUtf8(tmp);
-       mainLabel->setText(word);
+       if (word.isEmpty()) { // game over
+               mainLabel->setText("GAME OVER");
+               for (QMap<int, Player*>::Iterator it = players.begin(); it != players.end(); ++it) {
+                       QString tmp = QString ("Spieler %1 hat %2 Punkte.").arg(it.value()->getName()).arg(it.value()->score);
+                       it.value()->setWaiting(tmp);
+               }
+       } else {
+               resetPlayerText();
+               mainLabel->setText(word);
+               typingPlayers = players.size();
+       }
 }
 
 void MultypoWindow::handleKeyPress(int device, QString string)
@@ -61,7 +71,19 @@ void MultypoWindow::handleKeyPress(int device, QString string)
        players[device]->handleKey(string);
 
        if (gameStarted) { // ingame
-
+               qDebug() << players[device]->getCurrentLine();
+               qDebug() << mainLabel->text();
+               if (players[device]->getCurrentLine() == mainLabel->text()) {
+                       players[device]->score += typingPlayers;
+                       QString readyString = QString("READY: %1 points").arg(typingPlayers);
+                       players[device]->setWaiting(readyString);
+                       qDebug() << "typingPlayers " << typingPlayers;
+                       typingPlayers--;
+                       qDebug() << "typingPlayers " << typingPlayers;
+                       if (typingPlayers <= 0) {
+                               nextWord();
+                       }
+               }
        } else { // name entering phase
                bool allHaveNames = true;
                for (QMap<int, Player*>::Iterator it = players.begin(); it != players.end(); ++it) {
@@ -113,7 +135,7 @@ bool MultypoWindow::handleX11Event(XEvent *event)
                for (int i = 0; i < ndevices; ++i) {
                        if (devices[i].use != XIMasterKeyboard) continue;
                        qDebug() << "Found master keyboard with ID" << devices[i].deviceid;
-                       //XISetFocus(dpy, devices[i].deviceid, winId(), CurrentTime);
+                       XISetFocus(dpy, devices[i].deviceid, winId(), CurrentTime);
                }
                XIFreeDeviceInfo(devices);