ralfs Fixes
authorConstantin <constantin@exxxtremesys.lu>
Fri, 19 Jul 2013 18:25:57 +0000 (20:25 +0200)
committerConstantin <constantin@exxxtremesys.lu>
Fri, 19 Jul 2013 18:25:57 +0000 (20:25 +0200)
play.sh
qt/multypo.cpp
qt/player.cpp
qt/player.h

diff --git a/play.sh b/play.sh
index f51371ef1d1fe426ca76e384dafd54feac790a2f..6c3b185f3961edf18b957e1664cbaa6e37df0a54 100755 (executable)
--- a/play.sh
+++ b/play.sh
@@ -4,5 +4,5 @@
 
 WORDSTOPLAY=10
 
-sort -R dict.txt | egrep '^[A-Za-z]{5,}$' | head -n $WORDSTOPLAY | tr [:upper:] [:lower:]
+sort -R dict.txt | egrep '^[A-Za-z]{5,}$' | head -n $WORDSTOPLAY | tr [:upper:] [:lower:]  | qt/multypo
 
index 8dea3e025abeea2b8ca1aa2aaa25dbd7d64d741e..c9e710187163be7fe2e3db99f836ed1f988bf911 100644 (file)
 
 MultypoWindow::MultypoWindow(QWidget *parent) :
        QWidget(parent),
-       xiInited(false)
+       xiInited(false),
+       gameStarted(false)
 {
        /* Prepare colors */
-       setStyleSheet("background-color: black; color: green; font-size: 30pt");
+       setStyleSheet("background-color: black; color: green; font-size: 55pt");
 
        /* Prepare conents */
        setLayout(new QVBoxLayout(this));
 
-       mainLabel = new QLabel("Hit <Esc> to quit", this);
+       mainLabel = new QLabel("Namen eingeben, dann Return", this);
        layout()->addWidget(mainLabel);
 
        /* Fullscreen, no cursor */
@@ -28,6 +29,8 @@ MultypoWindow::MultypoWindow(QWidget *parent) :
        setCursor(QCursor(Qt::BlankCursor));
 
        words.open(stdin,QIODevice::ReadOnly);
+
+       typingPlayers = 0;
 }
 
 MultypoWindow::~MultypoWindow()
@@ -43,6 +46,7 @@ void MultypoWindow::resetPlayerText() {
 void MultypoWindow::nextWord() {
        QByteArray tmp = words.readLine().trimmed();
        QString word = QString::fromUtf8(tmp);
+       qDebug() << "New word" << word;
        if (word.isEmpty()) { // game over
                mainLabel->setText("GAME OVER");
                for (QMap<int, Player*>::Iterator it = players.begin(); it != players.end(); ++it) {
@@ -66,14 +70,16 @@ void MultypoWindow::handleKeyPress(int device, QString string)
        }
 
        if (!players.contains(device)) {
+               if (gameStarted)
+                       return;
                players[device] = new Player(this);
        }
-       players[device]->handleKey(string);
+       bool newChar = players[device]->handleKey(string);
 
        if (gameStarted) { // ingame
-               qDebug() << players[device]->getCurrentLine();
-               qDebug() << mainLabel->text();
-               if (players[device]->getCurrentLine() == mainLabel->text()) {
+               qDebug() << "current player line" << players[device]->getCurrentLine();
+               qDebug() << "current word" << mainLabel->text();
+               if (newChar && players[device]->getCurrentLine() == mainLabel->text()) {
                        players[device]->score += typingPlayers;
                        QString readyString = QString("READY: %1 points").arg(typingPlayers);
                        players[device]->setWaiting(readyString);
@@ -85,6 +91,7 @@ void MultypoWindow::handleKeyPress(int device, QString string)
                        }
                }
        } else { // name entering phase
+               qDebug() << "checking for game started";
                bool allHaveNames = true;
                for (QMap<int, Player*>::Iterator it = players.begin(); it != players.end(); ++it) {
                        if (! it.value()->hasName()) {
@@ -92,6 +99,7 @@ void MultypoWindow::handleKeyPress(int device, QString string)
                                break;
                        }
                }
+               qDebug() << "Players empty?" << players.empty() << "All have names?" << allHaveNames;
                if (!players.empty() && allHaveNames) {
                        gameStarted = true;
                        nextWord();
index 4c84eb74a182ba66b2ef472b0d58ae07e8fcbe88..937bbab739dddb597f1bbf310a3187ac6a0c5a4a 100644 (file)
@@ -1,6 +1,7 @@
 #include "player.h"
 
 #include <QLayout>
+#include <QDebug>
 
 static QString colorToString(QColor col)
 {
@@ -13,11 +14,11 @@ Player::Player(QWidget* parent) {
        theLabel = new QLabel (parent);
        parent->layout()->addWidget(theLabel);
        modifyable = true;
+       qDebug() << "Player created";
 }
 
-
 bool Player::hasName() {
-       return !name.isNull();
+       return !name.isEmpty();
 }
 
 QString Player::getName() {
@@ -39,11 +40,13 @@ void Player::resetText() {
        modifyable = true;
 }
 
-void Player::handleKey(QString str) {
+bool Player::handleKey(QString str) {
        if (!modifyable)
-               return;
+               return false;
+       bool newChar = false;
        if (str.length() == 1) {
                currentLine += str;
+               newChar = true;
        } else if (!hasName() && str == "Return") {
                // set name
                name = currentLine;
@@ -52,4 +55,5 @@ void Player::handleKey(QString str) {
                currentLine.chop(1);
        }
        theLabel->setText(currentLine);
+       return newChar;
 }
index 7b782839457f777f03543d7702965ae2a3db6443..c74413cd1831840162e0f9ceca6daeb13e96ba70 100644 (file)
@@ -13,7 +13,7 @@ private:
        bool modifyable;
 public:
        Player(QWidget* parent);
-       void handleKey(QString);
+       bool handleKey(QString); /* returns whether a char was added */
        void resetText();
        bool hasName();
        QString getName();