From: Constantin Date: Fri, 19 Jul 2013 13:41:43 +0000 (+0200) Subject: players get points now which are shown per word X-Git-Url: https://git.ralfj.de/multypo.git/commitdiff_plain/e6207dc52430a9fcbfd7df03f46c2876fc05154b?hp=e8b07da1c5251e412f80fdeb94fb327b641fc956 players get points now which are shown per word --- diff --git a/qt/multypo.cpp b/qt/multypo.cpp index e6befe2..973686b 100644 --- a/qt/multypo.cpp +++ b/qt/multypo.cpp @@ -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::Iterator it = players.begin(); it != players.end(); ++it) { diff --git a/qt/multypo.h b/qt/multypo.h index 9220df8..1a088bd 100644 --- a/qt/multypo.h +++ b/qt/multypo.h @@ -29,6 +29,7 @@ private: QLabel *mainLabel; QFile words; QMap players; + int typingPlayers; // how many are not ready yet }; #endif // MULTIKBD_H diff --git a/qt/player.cpp b/qt/player.cpp index 871ecb9..4c84eb7 100644 --- a/qt/player.cpp +++ b/qt/player.cpp @@ -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") { diff --git a/qt/player.h b/qt/player.h index 4674255..7b78283 100644 --- a/qt/player.h +++ b/qt/player.h @@ -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