From: Constantin Date: Fri, 19 Jul 2013 13:19:53 +0000 (+0200) Subject: name input and game start works X-Git-Url: https://git.ralfj.de/multypo.git/commitdiff_plain/e8b07da1c5251e412f80fdeb94fb327b641fc956?ds=sidebyside name input and game start works --- diff --git a/qt/multypo.cpp b/qt/multypo.cpp index 0c5451e..e6befe2 100644 --- a/qt/multypo.cpp +++ b/qt/multypo.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -25,12 +26,26 @@ MultypoWindow::MultypoWindow(QWidget *parent) : /* Fullscreen, no cursor */ setWindowState(Qt::WindowFullScreen); setCursor(QCursor(Qt::BlankCursor)); + + words.open(stdin,QIODevice::ReadOnly); } MultypoWindow::~MultypoWindow() { } +void MultypoWindow::resetPlayerText() { + for (QMap::Iterator it = players.begin(); it != players.end(); ++it) { + it.value()->resetText(); + } +} + +void MultypoWindow::nextWord() { + QByteArray tmp = words.readLine(); + QString word = QString::fromUtf8(tmp); + mainLabel->setText(word); +} + void MultypoWindow::handleKeyPress(int device, QString string) { qDebug() << "Device" << device << "String" << string; @@ -44,6 +59,22 @@ void MultypoWindow::handleKeyPress(int device, QString string) players[device] = new Player(this); } players[device]->handleKey(string); + + if (gameStarted) { // ingame + + } else { // name entering phase + bool allHaveNames = true; + for (QMap::Iterator it = players.begin(); it != players.end(); ++it) { + if (! it.value()->hasName()) { + allHaveNames = false; + break; + } + } + if (!players.empty() && allHaveNames) { + gameStarted = true; + nextWord(); + } + } } bool MultypoWindow::handleX11Event(XEvent *event) diff --git a/qt/multypo.h b/qt/multypo.h index de0898f..9220df8 100644 --- a/qt/multypo.h +++ b/qt/multypo.h @@ -3,6 +3,7 @@ #include #include +#include #include "player.h" @@ -18,12 +19,15 @@ public: private: void handleKeyPress(int device, QString string); + void nextWord(); + void resetPlayerText(); private: bool xiInited; int xiOpcode; + bool gameStarted; QLabel *mainLabel; - + QFile words; QMap players; }; diff --git a/qt/player.cpp b/qt/player.cpp index 4049788..871ecb9 100644 --- a/qt/player.cpp +++ b/qt/player.cpp @@ -14,10 +14,28 @@ Player::Player(QWidget* parent) { parent->layout()->addWidget(theLabel); } + +bool Player::hasName() { + return !name.isNull(); +} + +QString Player::getName() { + return name; +} + +QString Player::getCurrentLine() { + return currentLine; +} + +void Player::resetText() { + currentLine.clear(); + theLabel->setText(currentLine); +} + void Player::handleKey(QString str) { if (str.length() == 1) { currentLine += str; - } else if (name.isNull() && str == "Return") { + } else if (!hasName() && str == "Return") { // set name name = currentLine; currentLine = ""; diff --git a/qt/player.h b/qt/player.h index f725069..4674255 100644 --- a/qt/player.h +++ b/qt/player.h @@ -13,6 +13,10 @@ private: public: Player(QWidget* parent); void handleKey(QString); + void resetText(); + bool hasName(); + QString getName(); + QString getCurrentLine(); }; #endif // PLAYER_H