name input and game start works
authorConstantin <constantin@exxxtremesys.lu>
Fri, 19 Jul 2013 13:19:53 +0000 (15:19 +0200)
committerConstantin <constantin@exxxtremesys.lu>
Fri, 19 Jul 2013 13:19:53 +0000 (15:19 +0200)
qt/multypo.cpp
qt/multypo.h
qt/player.cpp
qt/player.h

index 0c5451ece7c8be2deed7c237b6407a6938b87cfd..e6befe2535fd113b0ecaceb798ea04d7befda7c6 100644 (file)
@@ -4,6 +4,7 @@
 #include <QDebug>
 #include <QVBoxLayout>
 #include <QLabel>
+#include <QMap>
 
 #include <X11/Xlib.h>
 #include <X11/extensions/XInput2.h>
@@ -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<int, Player*>::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<int, Player*>::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)
index de0898fd530fa335bbe2804359671cc247d21535..9220df841240d0602427d1b481e551b079aede51 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <QWidget>
 #include <QMap>
+#include <QFile>
 
 #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<int, Player*> players;
 };
 
index 40497881224caaea2026fc0549dd4d9e605eb02f..871ecb9d474182fd1ad50ddd6790fff4a4d71d42 100644 (file)
@@ -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 = "";
index f7250699e30f7c847d3d9fe14462e7d04a01daed..4674255dabdf7fd9bfabe4d2b249761872e94b10 100644 (file)
@@ -13,6 +13,10 @@ private:
 public:
        Player(QWidget* parent);
        void handleKey(QString);
+       void resetText();
+       bool hasName();
+       QString getName();
+       QString getCurrentLine();
 };
 
 #endif // PLAYER_H