players get points now which are shown per word
authorConstantin <constantin@exxxtremesys.lu>
Fri, 19 Jul 2013 13:41:43 +0000 (15:41 +0200)
committerConstantin <constantin@exxxtremesys.lu>
Fri, 19 Jul 2013 13:41:43 +0000 (15:41 +0200)
qt/multypo.cpp
qt/multypo.h
qt/player.cpp
qt/player.h

index e6befe2535fd113b0ecaceb798ea04d7befda7c6..973686bf411edb33d7fc3e1aaa2c5ddfb9225628 100644 (file)
@@ -41,9 +41,10 @@ void MultypoWindow::resetPlayerText() {
 }
 
 void MultypoWindow::nextWord() {
-       QByteArray tmp = words.readLine();
+       QByteArray tmp = words.readLine().trimmed();
        QString word = QString::fromUtf8(tmp);
        mainLabel->setText(word);
+       typingPlayers = players.size();
 }
 
 void MultypoWindow::handleKeyPress(int device, QString string)
@@ -61,7 +62,13 @@ 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);
+               }
        } else { // name entering phase
                bool allHaveNames = true;
                for (QMap<int, Player*>::Iterator it = players.begin(); it != players.end(); ++it) {
index 9220df841240d0602427d1b481e551b079aede51..1a088bd30692295858291e2e3d748c8e134f4fb5 100644 (file)
@@ -29,6 +29,7 @@ private:
        QLabel *mainLabel;
        QFile words;
        QMap<int, Player*> players;
+       int typingPlayers; // how many are not ready yet
 };
 
 #endif // MULTIKBD_H
index 871ecb9d474182fd1ad50ddd6790fff4a4d71d42..4c84eb74a182ba66b2ef472b0d58ae07e8fcbe88 100644 (file)
@@ -12,6 +12,7 @@ static QString colorToString(QColor col)
 Player::Player(QWidget* parent) {
        theLabel = new QLabel (parent);
        parent->layout()->addWidget(theLabel);
+       modifyable = true;
 }
 
 
@@ -27,12 +28,20 @@ QString Player::getCurrentLine() {
        return currentLine;
 }
 
+void Player::setWaiting(QString labeltext) {
+       theLabel->setText(labeltext);
+       modifyable = false;
+}
+
 void Player::resetText() {
        currentLine.clear();
        theLabel->setText(currentLine);
+       modifyable = true;
 }
 
 void Player::handleKey(QString str) {
+       if (!modifyable)
+               return;
        if (str.length() == 1) {
                currentLine += str;
        } else if (!hasName() && str == "Return") {
index 4674255dabdf7fd9bfabe4d2b249761872e94b10..7b782839457f777f03543d7702965ae2a3db6443 100644 (file)
@@ -10,6 +10,7 @@ private:
        QString name;
        QString currentLine;
        QLabel* theLabel;
+       bool modifyable;
 public:
        Player(QWidget* parent);
        void handleKey(QString);
@@ -17,6 +18,8 @@ public:
        bool hasName();
        QString getName();
        QString getCurrentLine();
+       int score;
+       void setWaiting(QString labeltext);
 };
 
 #endif // PLAYER_H