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 */
setCursor(QCursor(Qt::BlankCursor));
words.open(stdin,QIODevice::ReadOnly);
+
+ typingPlayers = 0;
}
MultypoWindow::~MultypoWindow()
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) {
}
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);
}
}
} 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()) {
break;
}
}
+ qDebug() << "Players empty?" << players.empty() << "All have names?" << allHaveNames;
if (!players.empty() && allHaveNames) {
gameStarted = true;
nextWord();
#include "player.h"
#include <QLayout>
+#include <QDebug>
static QString colorToString(QColor col)
{
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() {
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;
currentLine.chop(1);
}
theLabel->setText(currentLine);
+ return newChar;
}