commit 1ea8b010571594d2060448e6bcae0d5f695dc7a3 Author: seba Date: Sat Nov 1 16:12:36 2008 +0100 Initial Commit, first release diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bdc8aea --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.o +moc_* +viergewinnt-qt diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3328faa --- /dev/null +++ b/Makefile @@ -0,0 +1,328 @@ +############################################################################# +# Makefile for building: viergewinnt-qt +# Generated by qmake (2.01a) (Qt 4.4.3) on: Sa Nov 1 16:10:13 2008 +# Project: viergewinnt-qt.pro +# Template: app +# Command: /usr/bin/qmake -unix -o Makefile viergewinnt-qt.pro +############################################################################# + +####### Compiler, tools and options + +CC = gcc +CXX = g++ +DEFINES = -DQT_NO_DEBUG_OUTPUT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED +CFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES) +CXXFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES) +INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. +LINK = g++ +LFLAGS = +LIBS = $(SUBLIBS) -L/usr/lib -lQtGui -lQtNetwork -lQtCore -lpthread +AR = ar cqs +RANLIB = +QMAKE = /usr/bin/qmake +TAR = tar -cf +COMPRESS = gzip -9f +COPY = cp -f +SED = sed +COPY_FILE = $(COPY) +COPY_DIR = $(COPY) -r +INSTALL_FILE = install -m 644 -p +INSTALL_DIR = $(COPY_DIR) +INSTALL_PROGRAM = install -m 755 -p +DEL_FILE = rm -f +SYMLINK = ln -sf +DEL_DIR = rmdir +MOVE = mv -f +CHK_DIR_EXISTS= test -d +MKDIR = mkdir -p + +####### Output directory + +OBJECTS_DIR = ./ + +####### Files + +SOURCES = about.cpp \ + creategame.cpp \ + findserver.cpp \ + main.cpp \ + newgame.cpp \ + playerwait.cpp \ + renderarea.cpp \ + selectmaster.cpp \ + viergewinnt.cpp moc_about.cpp \ + moc_creategame.cpp \ + moc_findserver.cpp \ + moc_newgame.cpp \ + moc_playerwait.cpp \ + moc_renderarea.cpp \ + moc_selectmaster.cpp \ + moc_viergewinnt.cpp +OBJECTS = about.o \ + creategame.o \ + findserver.o \ + main.o \ + newgame.o \ + playerwait.o \ + renderarea.o \ + selectmaster.o \ + viergewinnt.o \ + moc_about.o \ + moc_creategame.o \ + moc_findserver.o \ + moc_newgame.o \ + moc_playerwait.o \ + moc_renderarea.o \ + moc_selectmaster.o \ + moc_viergewinnt.o +DIST = /usr/share/qt4/mkspecs/common/g++.conf \ + /usr/share/qt4/mkspecs/common/unix.conf \ + /usr/share/qt4/mkspecs/common/linux.conf \ + /usr/share/qt4/mkspecs/qconfig.pri \ + /usr/share/qt4/mkspecs/features/qt_functions.prf \ + /usr/share/qt4/mkspecs/features/qt_config.prf \ + /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ + /usr/share/qt4/mkspecs/features/default_pre.prf \ + /usr/share/qt4/mkspecs/features/release.prf \ + /usr/share/qt4/mkspecs/features/default_post.prf \ + /usr/share/qt4/mkspecs/features/warn_on.prf \ + /usr/share/qt4/mkspecs/features/qt.prf \ + /usr/share/qt4/mkspecs/features/unix/thread.prf \ + /usr/share/qt4/mkspecs/features/moc.prf \ + /usr/share/qt4/mkspecs/features/resources.prf \ + /usr/share/qt4/mkspecs/features/uic.prf \ + /usr/share/qt4/mkspecs/features/yacc.prf \ + /usr/share/qt4/mkspecs/features/lex.prf \ + viergewinnt-qt.pro +QMAKE_TARGET = viergewinnt-qt +DESTDIR = +TARGET = viergewinnt-qt + +first: all +####### Implicit rules + +.SUFFIXES: .o .c .cpp .cc .cxx .C + +.cpp.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.cc.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.cxx.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.C.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.c.o: + $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<" + +####### Build rules + +all: Makefile $(TARGET) + +$(TARGET): $(OBJECTS) + $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS) + +Makefile: viergewinnt-qt.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/mkspecs/common/g++.conf \ + /usr/share/qt4/mkspecs/common/unix.conf \ + /usr/share/qt4/mkspecs/common/linux.conf \ + /usr/share/qt4/mkspecs/qconfig.pri \ + /usr/share/qt4/mkspecs/features/qt_functions.prf \ + /usr/share/qt4/mkspecs/features/qt_config.prf \ + /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ + /usr/share/qt4/mkspecs/features/default_pre.prf \ + /usr/share/qt4/mkspecs/features/release.prf \ + /usr/share/qt4/mkspecs/features/default_post.prf \ + /usr/share/qt4/mkspecs/features/warn_on.prf \ + /usr/share/qt4/mkspecs/features/qt.prf \ + /usr/share/qt4/mkspecs/features/unix/thread.prf \ + /usr/share/qt4/mkspecs/features/moc.prf \ + /usr/share/qt4/mkspecs/features/resources.prf \ + /usr/share/qt4/mkspecs/features/uic.prf \ + /usr/share/qt4/mkspecs/features/yacc.prf \ + /usr/share/qt4/mkspecs/features/lex.prf \ + /usr/lib/libQtGui.prl \ + /usr/lib/libQtNetwork.prl \ + /usr/lib/libQtCore.prl + $(QMAKE) -unix -o Makefile viergewinnt-qt.pro +/usr/share/qt4/mkspecs/common/g++.conf: +/usr/share/qt4/mkspecs/common/unix.conf: +/usr/share/qt4/mkspecs/common/linux.conf: +/usr/share/qt4/mkspecs/qconfig.pri: +/usr/share/qt4/mkspecs/features/qt_functions.prf: +/usr/share/qt4/mkspecs/features/qt_config.prf: +/usr/share/qt4/mkspecs/features/exclusive_builds.prf: +/usr/share/qt4/mkspecs/features/default_pre.prf: +/usr/share/qt4/mkspecs/features/release.prf: +/usr/share/qt4/mkspecs/features/default_post.prf: +/usr/share/qt4/mkspecs/features/warn_on.prf: +/usr/share/qt4/mkspecs/features/qt.prf: +/usr/share/qt4/mkspecs/features/unix/thread.prf: +/usr/share/qt4/mkspecs/features/moc.prf: +/usr/share/qt4/mkspecs/features/resources.prf: +/usr/share/qt4/mkspecs/features/uic.prf: +/usr/share/qt4/mkspecs/features/yacc.prf: +/usr/share/qt4/mkspecs/features/lex.prf: +/usr/lib/libQtGui.prl: +/usr/lib/libQtNetwork.prl: +/usr/lib/libQtCore.prl: +qmake: FORCE + @$(QMAKE) -unix -o Makefile viergewinnt-qt.pro + +dist: + @$(CHK_DIR_EXISTS) .tmp/viergewinnt-qt1.0.0 || $(MKDIR) .tmp/viergewinnt-qt1.0.0 + $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/viergewinnt-qt1.0.0/ && $(COPY_FILE) --parents about.h creategame.h findserver.h newgame.h playerwait.h renderarea.h selectmaster.h viergewinnt.h .tmp/viergewinnt-qt1.0.0/ && $(COPY_FILE) --parents about.cpp creategame.cpp findserver.cpp main.cpp newgame.cpp playerwait.cpp renderarea.cpp selectmaster.cpp viergewinnt.cpp .tmp/viergewinnt-qt1.0.0/ && $(COPY_FILE) --parents viergewinnt-qt_en.ts .tmp/viergewinnt-qt1.0.0/ && (cd `dirname .tmp/viergewinnt-qt1.0.0` && $(TAR) viergewinnt-qt1.0.0.tar viergewinnt-qt1.0.0 && $(COMPRESS) viergewinnt-qt1.0.0.tar) && $(MOVE) `dirname .tmp/viergewinnt-qt1.0.0`/viergewinnt-qt1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/viergewinnt-qt1.0.0 + + +clean:compiler_clean + -$(DEL_FILE) $(OBJECTS) + -$(DEL_FILE) *~ core *.core + + +####### Sub-libraries + +distclean: clean + -$(DEL_FILE) $(TARGET) + -$(DEL_FILE) Makefile + + +mocclean: compiler_moc_header_clean compiler_moc_source_clean + +mocables: compiler_moc_header_make_all compiler_moc_source_make_all + +compiler_moc_header_make_all: moc_about.cpp moc_creategame.cpp moc_findserver.cpp moc_newgame.cpp moc_playerwait.cpp moc_renderarea.cpp moc_selectmaster.cpp moc_viergewinnt.cpp +compiler_moc_header_clean: + -$(DEL_FILE) moc_about.cpp moc_creategame.cpp moc_findserver.cpp moc_newgame.cpp moc_playerwait.cpp moc_renderarea.cpp moc_selectmaster.cpp moc_viergewinnt.cpp +moc_about.cpp: about.h + /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) about.h -o moc_about.cpp + +moc_creategame.cpp: creategame.h + /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) creategame.h -o moc_creategame.cpp + +moc_findserver.cpp: selectmaster.h \ + creategame.h \ + viergewinnt.h \ + newgame.h \ + playerwait.h \ + about.h \ + findserver.h + /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) findserver.h -o moc_findserver.cpp + +moc_newgame.cpp: newgame.h + /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) newgame.h -o moc_newgame.cpp + +moc_playerwait.cpp: playerwait.h + /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) playerwait.h -o moc_playerwait.cpp + +moc_renderarea.cpp: viergewinnt.h \ + newgame.h \ + playerwait.h \ + renderarea.h + /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) renderarea.h -o moc_renderarea.cpp + +moc_selectmaster.cpp: selectmaster.h + /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) selectmaster.h -o moc_selectmaster.cpp + +moc_viergewinnt.cpp: newgame.h \ + playerwait.h \ + viergewinnt.h + /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) viergewinnt.h -o moc_viergewinnt.cpp + +compiler_rcc_make_all: +compiler_rcc_clean: +compiler_image_collection_make_all: qmake_image_collection.cpp +compiler_image_collection_clean: + -$(DEL_FILE) qmake_image_collection.cpp +compiler_moc_source_make_all: +compiler_moc_source_clean: +compiler_uic_make_all: +compiler_uic_clean: +compiler_yacc_decl_make_all: +compiler_yacc_decl_clean: +compiler_yacc_impl_make_all: +compiler_yacc_impl_clean: +compiler_lex_make_all: +compiler_lex_clean: +compiler_clean: compiler_moc_header_clean + +####### Compile + +about.o: about.cpp about.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o about.o about.cpp + +creategame.o: creategame.cpp creategame.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o creategame.o creategame.cpp + +findserver.o: findserver.cpp findserver.h \ + selectmaster.h \ + creategame.h \ + viergewinnt.h \ + newgame.h \ + playerwait.h \ + about.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o findserver.o findserver.cpp + +main.o: main.cpp findserver.h \ + selectmaster.h \ + creategame.h \ + viergewinnt.h \ + newgame.h \ + playerwait.h \ + about.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp + +newgame.o: newgame.cpp newgame.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o newgame.o newgame.cpp + +playerwait.o: playerwait.cpp playerwait.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o playerwait.o playerwait.cpp + +renderarea.o: renderarea.cpp renderarea.h \ + viergewinnt.h \ + newgame.h \ + playerwait.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o renderarea.o renderarea.cpp + +selectmaster.o: selectmaster.cpp selectmaster.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o selectmaster.o selectmaster.cpp + +viergewinnt.o: viergewinnt.cpp viergewinnt.h \ + newgame.h \ + playerwait.h \ + renderarea.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o viergewinnt.o viergewinnt.cpp + +moc_about.o: moc_about.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_about.o moc_about.cpp + +moc_creategame.o: moc_creategame.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_creategame.o moc_creategame.cpp + +moc_findserver.o: moc_findserver.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_findserver.o moc_findserver.cpp + +moc_newgame.o: moc_newgame.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_newgame.o moc_newgame.cpp + +moc_playerwait.o: moc_playerwait.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_playerwait.o moc_playerwait.cpp + +moc_renderarea.o: moc_renderarea.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_renderarea.o moc_renderarea.cpp + +moc_selectmaster.o: moc_selectmaster.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_selectmaster.o moc_selectmaster.cpp + +moc_viergewinnt.o: moc_viergewinnt.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_viergewinnt.o moc_viergewinnt.cpp + +####### Install + +install: FORCE + +uninstall: FORCE + +FORCE: + diff --git a/about.cpp b/about.cpp new file mode 100644 index 0000000..c4dda5b --- /dev/null +++ b/about.cpp @@ -0,0 +1,46 @@ +/* VierGewinnt - A simple 4-in-a-row network game + * + * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de + * http://www.seba-geek.de + * + * This file is part of VierGewinnt. + * + * VierGewinnt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * VierGewinnt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VierGewinnt. If not, see . + */ + +#include "about.h" + +AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent) { +// setFixedSize(320, 200); + setWindowTitle(tr("Über")); + setModal(Qt::WindowModal); + + ok = new QPushButton(tr("Ok")); + connect(ok, SIGNAL(clicked()), this, SLOT(accept())); + head = new QLabel(tr("Netzwerk-VierGewinnt Client\nProgrammiert von seba\nwww.seba-geek.de")); + head->setAlignment(Qt::AlignHCenter); + body = new QLabel(tr("Erstes QT-Programm!\nDies ist ein Client für das VierGewinnt-Modul vom \"Generic Network-Server\". Endlich eine Verbesserung zum SDL-Client...")); + body->setWordWrap(true); + + layout = new QVBoxLayout; + + layout->addWidget(head); + layout->addSpacing(32); + layout->addWidget(body); + layout->addWidget(ok); + + layout->setAlignment(head, Qt::AlignHCenter); + + setLayout(layout); +} diff --git a/about.h b/about.h new file mode 100644 index 0000000..23d1871 --- /dev/null +++ b/about.h @@ -0,0 +1,43 @@ +/* VierGewinnt - A simple 4-in-a-row network game + * + * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de + * http://www.seba-geek.de + * + * This file is part of VierGewinnt. + * + * VierGewinnt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * VierGewinnt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VierGewinnt. If not, see . + */ + +#ifndef __ABOUT_H +#define __ABOUT_H + +#include +#include +#include +#include + +class AboutDialog : public QDialog { + Q_OBJECT + + public: + AboutDialog(QWidget *parent=0); + + private: + QPushButton *ok; + QLabel *head; + QLabel *body; + QVBoxLayout *layout; +}; + +#endif diff --git a/creategame.cpp b/creategame.cpp new file mode 100644 index 0000000..1ed75e5 --- /dev/null +++ b/creategame.cpp @@ -0,0 +1,58 @@ +/* VierGewinnt - A simple 4-in-a-row network game + * + * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de + * http://www.seba-geek.de + * + * This file is part of VierGewinnt. + * + * VierGewinnt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * VierGewinnt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VierGewinnt. If not, see . + */ + +#include "creategame.h" + +CreateGameDialog::CreateGameDialog(QTcpSocket *_mysock, QWidget *parent) : QDialog(parent) { + mysock = _mysock; + setWindowTitle(tr("Neues Spiel")); + +// stat = new QLabel(""); + gname = new QLabel(tr("Spielname")); + editgname = new QLineEdit; + ok = new QPushButton(tr("Ok")); + connect(ok, SIGNAL(clicked()), this, SLOT(startListen())); + cancel = new QPushButton(tr("Abbrechen")); + connect(cancel, SIGNAL(clicked()), this, SLOT(reject())); + + layout = new QGridLayout; +// layout->addWidget(stat, 0, 0, 1, 2); + layout->addWidget(gname, 1, 0); + layout->addWidget(editgname, 1, 1); + layout->addWidget(ok, 2, 0); + layout->addWidget(cancel, 2, 1); + + setLayout(layout); + setModal(Qt::WindowModal); +} + +// void CreateGameDialog::reset() { +// stat->setText(""); +// ok->show(); +// } + +void CreateGameDialog::startListen() { + QTextStream sockstream(mysock); + if(editgname->text()=="") + editgname->insert(tr("Unbenanntes Spiel")); + sockstream << "CREATE " << editgname->text() << "\n"; + accept(); +} diff --git a/creategame.h b/creategame.h new file mode 100644 index 0000000..a702065 --- /dev/null +++ b/creategame.h @@ -0,0 +1,59 @@ +#ifndef __CREATEGAME_H +/* VierGewinnt - A simple 4-in-a-row network game + * + * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de + * http://www.seba-geek.de + * + * This file is part of VierGewinnt. + * + * VierGewinnt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * VierGewinnt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VierGewinnt. If not, see . + */ + +#define __CREATEGAME_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +class CreateGameDialog : public QDialog { + Q_OBJECT + public: + CreateGameDialog(QTcpSocket *_mysock, QWidget *parent=0); + +// void reset(); + + private slots: + void startListen(); + + private: + QTcpSocket *mysock; + + QGridLayout *layout; +// QLabel *stat; + QLabel *gname; + QLineEdit *editgname; + QPushButton *ok; + QPushButton *cancel; + +}; + +#endif diff --git a/findserver.cpp b/findserver.cpp new file mode 100644 index 0000000..1c78d49 --- /dev/null +++ b/findserver.cpp @@ -0,0 +1,348 @@ +/* VierGewinnt - A simple 4-in-a-row network game + * + * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de + * http://www.seba-geek.de + * + * This file is part of VierGewinnt. + * + * VierGewinnt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * VierGewinnt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VierGewinnt. If not, see . + */ + +#include "findserver.h" + +#include +#include +#include + +FindServerWidget::FindServerWidget(QWidget *parent) : QWidget(parent) { + setFixedSize(640, 480); + setWindowTitle(tr("Sebas Netzwerk-VierGewinnt Client")+" - "+tr("Serverliste")); + masterserver = "1.proj.seba-geek.de"; // srv1.proj.seba-geek.de + masterport = 31415; + + // net stuff + mysock = new QTcpSocket; + connect(mysock, SIGNAL(connected()), this, SLOT(procNet())); + connect(mysock, SIGNAL(readyRead()), this, SLOT(procNet())); + connect(mysock, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(procNetError(QAbstractSocket::SocketError))); + connect(mysock, SIGNAL(disconnected()), this, SLOT(procNetDisconnect())); + + // dialoge + masterdialog = new SelectMasterDialog(this); + cgamedialog = new CreateGameDialog(mysock); /* , this */ + vwinwid = new VierGewinntWidget(mysock, this); + about = new AboutDialog(this); + + // networkbrowser + nettable = new QTreeWidget; + nettable->setColumnCount(5); +// nettable->setMaximumWidth(400); + QStringList header; + header << tr("Id") << tr("Spielname") << tr("Spieler") << tr("Spielfeld") << tr("Gewinnt") << ""; + nettable->setHeaderLabels(header); +// nettable->resizeColumnToContents(0); +// nettable->resizeColumnToContents(1); +// nettable->resizeColumnToContents(2); + + // buttonreihe + buttonrow = new QHBoxLayout; + refresh = new QPushButton(tr("Erneuern")); + connect(refresh, SIGNAL(clicked()), this, SLOT(refreshServerList())); + create = new QPushButton(tr("Erstellen")); + connect(create, SIGNAL(clicked()), this, SLOT(createGame())); + join = new QPushButton(tr("Beitreten")); + connect(join, SIGNAL(clicked()), this, SLOT(joinGame())); + othermaster = new QPushButton(tr("Anderer Masterserver")); + connect(othermaster, SIGNAL(clicked()), this, SLOT(changeMaster())); + butabout = new QPushButton(tr("Über")); + connect(butabout, SIGNAL(clicked()), about, SLOT(exec())); + + + + buttonrow->addWidget(refresh); + buttonrow->addWidget(create); + buttonrow->addWidget(join); + buttonrow->addStretch(); + buttonrow->addWidget(othermaster); + buttonrow->addWidget(butabout); + + + // network drunter + status = new QTextEdit; + status->setReadOnly(true); + status->setMaximumHeight(80); + addLog(tr("Drücke Erneuern um eine Serverliste zu erhalten")); + + // layout stuff + layout = new QVBoxLayout; + + layout->addWidget(nettable); + layout->addLayout(buttonrow); + layout->addWidget(status); + + setLayout(layout); + + loginstate = 0; + refreshonconnect = false; + ingame = false; +} + +void FindServerWidget::refreshServerList() { + if(mysock->state()==QTcpSocket::UnconnectedState) { + refreshonconnect = true; + startConnect(); + } else { + QTextStream sockstream(mysock); + addLog(tr("Fordere Liste an...")); + nettable->clear(); + sockstream << "LIST\n"; + } +} + +void FindServerWidget::changeMaster() { +// this->hide(); + masterdialog->setData(masterserver, masterport); + masterdialog->show(); + if(masterdialog->exec()== QDialog::Accepted) { + masterserver = masterdialog->getMasterServer(); + masterport = masterdialog->getMasterPort(); + mysock->close(); + startConnect(); + } +} + +void FindServerWidget::createGame() { + if(mysock->state()==QTcpSocket::UnconnectedState) + startConnect(); +// this->setDisabled(true); +// this->hide(); +// cgamedialog->reset(); + cgamedialog->show(); + if(cgamedialog->exec()== QDialog::Accepted) { + addLog(tr("Spiel erstellt")); + vwinwid->init(7, 6); + qDebug() << "i am still here!"; + } else { +// this->setDisabled(false); +// mysock->close(); + } +// this->show(); +} + +void FindServerWidget::joinGame() { + QTreeWidgetItem *myitem = nettable->currentItem(); + if(myitem==0) { + QMessageBox msgbox(this); + msgbox.setText(tr("Es wurde kein Spiel zum beitreten ausgewählt")); + msgbox.exec(); + return; + } + + if(mysock->state()==QTcpSocket::UnconnectedState) + startConnect(); + + // initing the field (here we have the data) + vwinwid->init(7, 6); // to be changed when custom fields are allowed + + // get id + int gameid = myitem->text(0).toInt(); + addLog(tr("Trete Spiel bei..")); + QTextStream mytext(mysock); + mytext << "JOIN " << gameid << "\n"; +} + +void FindServerWidget::procNet() { + QTextStream sockstream(mysock); + QString tmpbuf; + switch(loginstate) { + case 0:{ + sockstream << "VERSION viergewinnt-qt\n"; + loginstate++; + }break; + case 1: + tmpbuf = mysock->readLine(); + if(tmpbuf.contains("ACK VERSION")) { + addLog(tr("Version akzeptiert")); + sockstream << "SELECT VierGewinnt\n"; + loginstate++; + } else { + addLog(tr("Version nicht akzeptiert, kein GNS-Server!")); + mysock->close(); + } + break; + case 2: + tmpbuf = mysock->readLine(); + if(tmpbuf.contains("ACK SELECT")) { + loginstate++; + addLog(tr("Modul ausgewählt")); + if(refreshonconnect) { + refreshServerList(); + + refreshonconnect = false; + } + } else { + addLog(tr("VierGewinnt-Modul nicht gefunden!")); + mysock->close(); + } + break; + default: + // list, join or error +// tmpbuf = mysock->readLine(); +// addLog("Got INput: "+sockstream.readLine()); + + do { + + QTextStream sockstream2(mysock->readLine()); + sockstream2 >> tmpbuf; + + if(tmpbuf=="ERROR") { + sockstream2 >> tmpbuf; + int myerrno = tmpbuf.toInt(); + if(myerrno==121) { + addLog(tr("Keine Spiele offen :(")); + } else if(myerrno==125) { + addLog(tr("Konnte nicht beitreten: Spiel voll")); + } else if(myerrno==124) { + addLog(tr("Spiel konnte nicht gefunden werden")); + } else if(tmpbuf=="Not") { + sockstream2 >> tmpbuf; + if(tmpbuf=="your") { + vwinwid->ackAdd(false); + } + } else if(tmpbuf=="Row") { + vwinwid->ackAdd(false); + } else { + qDebug() << "Unbekannter Fehler: " << tmpbuf; +// addLog(tr("Unbekannter error: ")+tmpbuf); + } + } else if(tmpbuf=="GAME") { + QStringList qstrlst; + QString tmpbuf2; + sockstream2 >> tmpbuf; // id + qstrlst << tmpbuf; + sockstream2 >> tmpbuf2; // player in + sockstream2 >> tmpbuf; // player max + tmpbuf2 += "/"; + tmpbuf2 += tmpbuf; + sockstream2 >> tmpbuf; // game's name + qstrlst << tmpbuf; + qstrlst << tmpbuf2; + sockstream2 >> tmpbuf2; // x + sockstream2 >> tmpbuf; // y + tmpbuf2 += "x"; + tmpbuf2 += tmpbuf; + qstrlst << tmpbuf2; + sockstream2 >> tmpbuf; // for the win + qstrlst << tmpbuf; + nettable->addTopLevelItem(new QTreeWidgetItem(qstrlst)); + } else if(tmpbuf=="ACK") { + sockstream2 >> tmpbuf; + if(tmpbuf=="CREATE") { + addLog("Spiel erstellt, warte auf Mitspieler"); + vwinwid->clientExited(); + this->hide(); + vwinwid->show(); + } else if(tmpbuf=="JOIN") { + // set data to mainwindow + goToGameWindow(); + } else if(tmpbuf=="ADD") { + vwinwid->ackAdd(true); + } + } else if(tmpbuf=="INFO") { + sockstream2 >> tmpbuf; + if(tmpbuf=="START") { + vwinwid->startGame(); + qDebug() << "Game Started!"; + } else if(tmpbuf=="TURN") { + sockstream2 >> tmpbuf; + vwinwid->setTurn(tmpbuf.toInt()==1); + } else if(tmpbuf=="ADD") { + sockstream2 >> tmpbuf; + vwinwid->add(tmpbuf.toInt(), VierGewinntWidget::o); + } else if(tmpbuf=="GAME") { + sockstream2 >> tmpbuf; + if(tmpbuf=="STOP") { + vwinwid->clientExited(); + } + } else if(tmpbuf=="STATUS") { + sockstream2 >> tmpbuf; + vwinwid->newGame(tmpbuf=="WON"); + // REQ NEW GAME Message ignored, handled here + } else if(tmpbuf=="CLIENT") { + sockstream2 >> tmpbuf; + if(tmpbuf=="NEW") { + vwinwid->ackNewGame(); + } + } else if(tmpbuf=="NEW") { + sockstream2 >> tmpbuf; + if(tmpbuf=="GAME") { + vwinwid->startGame(); + } + } else if(tmpbuf=="SCORE") { + QString tmpbuf2; + sockstream2 >> tmpbuf; + sockstream2 >> tmpbuf2; + vwinwid->setScore(tmpbuf.toInt(), tmpbuf2.toInt()); + } + } else { + qDebug() << "Unhandled TMPBUF: " << tmpbuf; + } + } while(!sockstream.atEnd()); + break; + } +} + +void FindServerWidget::procNetError(QAbstractSocket::SocketError e) { + switch(e) { + case QAbstractSocket::HostNotFoundError: + addLog(tr("Fehler: Der Master-Server Hostname konnte nicht aufgelöst werden!")); + break; + case QAbstractSocket::ConnectionRefusedError: + addLog(tr("Fehler: Verbindungsversuch zum Master-Server ist fehlgeschlagen!")); + break; + case QAbstractSocket::RemoteHostClosedError: + procNetDisconnect(); + break; + default: + addLog(tr("Netzwerkfehler: '%1'").arg(mysock->errorString())); + break; + } + qDebug() << "Networ error: " << mysock->errorString(); +} + +void FindServerWidget::procNetDisconnect() { + vwinwid->hide(); + this->show(); + nettable->clear(); + addLog(tr("Die Verbindung zum Masterserver wurde getrennt.")); +} + +void FindServerWidget::addLog(QString str) { + status->append(str); + qDebug() << "Log: " << str; +} + +void FindServerWidget::startConnect() { + loginstate = 0; + ingame = false; + addLog((tr("Versuche Verbindung zu ")+masterserver+" ...")); + mysock->connectToHost(masterserver, masterport); +} + +void FindServerWidget::goToGameWindow() { + qDebug() << "SHOW togamewindow"; + this->hide(); + vwinwid->startGame(); + vwinwid->show(); +} diff --git a/findserver.h b/findserver.h new file mode 100644 index 0000000..74d76a5 --- /dev/null +++ b/findserver.h @@ -0,0 +1,84 @@ +#ifndef __FINDSERVER_H +#define __FINDSERVER_H + +#include +#include +#include +#include +/* VierGewinnt - A simple 4-in-a-row network game + * + * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de + * http://www.seba-geek.de + * + * This file is part of VierGewinnt. + * + * VierGewinnt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * VierGewinnt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VierGewinnt. If not, see . + */ + +#include +#include +#include +#include + +#include "selectmaster.h" +#include "creategame.h" +#include "viergewinnt.h" +#include "about.h" + +class FindServerWidget : public QWidget { + Q_OBJECT + + public: + FindServerWidget(QWidget *parent=0); + + private slots: + void refreshServerList(); + void changeMaster(); + void createGame(); + void joinGame(); + void procNet(); + void procNetError(QAbstractSocket::SocketError e); + void procNetDisconnect(); + + private: + // main stuff + void addLog(QString str); + void startConnect(); + void goToGameWindow(); + + // gns stuff + QTcpSocket *mysock; + QString masterserver; + int masterport; + bool ingame; + bool refreshonconnect; + int loginstate; + CreateGameDialog *cgamedialog; + + // gui stuff + QTreeWidget *nettable; + QHBoxLayout *buttonrow; + QPushButton *refresh; + QPushButton *create; + QPushButton *join; + QPushButton *othermaster; + QPushButton *butabout; + QTextEdit *status; + SelectMasterDialog *masterdialog; + QVBoxLayout *layout; + VierGewinntWidget *vwinwid; + AboutDialog *about; +}; + +#endif diff --git a/gpl-2.0.txt b/gpl-2.0.txt new file mode 100644 index 0000000..d511905 --- /dev/null +++ b/gpl-2.0.txt @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..8809aa1 --- /dev/null +++ b/main.cpp @@ -0,0 +1,39 @@ +/* VierGewinnt - A simple 4-in-a-row network game + * + * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de + * http://www.seba-geek.de + * + * This file is part of VierGewinnt. + * + * VierGewinnt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * VierGewinnt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VierGewinnt. If not, see . + */ + +#include +#include +#include +#include "findserver.h" + +int main(int argc, char **argv) { + QApplication app(argc, argv); + + QLocale locale; + QTranslator translator; + translator.load(QString("trans/viergewinnt-qt_") + locale.name()); + app.installTranslator(&translator); + + FindServerWidget fswid; + fswid.show(); + + return app.exec(); +} diff --git a/newgame.cpp b/newgame.cpp new file mode 100644 index 0000000..b4c175e --- /dev/null +++ b/newgame.cpp @@ -0,0 +1,87 @@ +/* VierGewinnt - A simple 4-in-a-row network game + * + * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de + * http://www.seba-geek.de + * + * This file is part of VierGewinnt. + * + * VierGewinnt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * VierGewinnt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VierGewinnt. If not, see . + */ + +#include "newgame.h" + + +NewGameDialog::NewGameDialog(QTcpSocket *sock, QWidget *parent) : QDialog(parent) { + mysock = sock; + gameend = new QLabel(""); + newgame = new QLabel(tr("Ein neues Spiel?")); + netplayer = new QLabel(""); + ok = new QPushButton(tr("Ok")); + connect(ok, SIGNAL(clicked()), this, SLOT(localAck())); + cancel = new QPushButton(tr("Abbrechen")); + connect(cancel, SIGNAL(clicked()), this, SLOT(closeGame())); + connect(this, SIGNAL(rejected()), this, SLOT(closeGame())); + setWindowTitle(tr("Neues Spiel?")); + reset(true); + + buttonrow = new QHBoxLayout; + buttonrow->addStretch(); + buttonrow->addWidget(ok); + buttonrow->addStretch(); + buttonrow->addWidget(cancel); + buttonrow->addStretch(); + + + layout = new QVBoxLayout; + + layout->addWidget(gameend); + layout->addSpacing(32); + layout->addWidget(newgame); + layout->addWidget(netplayer); + layout->addLayout(buttonrow); + + //center + layout->setAlignment(gameend, Qt::AlignHCenter); + layout->setAlignment(newgame, Qt::AlignHCenter); + layout->setAlignment(netplayer, Qt::AlignHCenter); + + setLayout(layout); + + setModal(Qt::WindowModal); +} + +void NewGameDialog::reset(bool won) { + netplayer->setText(tr("Dein Mispieler hat bisher noch nicht zugestimmt.")); + ok->setDisabled(false); + if(won) { + gameend->setText(tr("Whee, du hast gewonnen! :)")); + } else { + gameend->setText(tr("Du hast verloren -.-")); + } +} + +void NewGameDialog::netPlayerAck() { + netplayer->setText(tr("Dein Mispieler hat zugestimmt.")); +} + +void NewGameDialog::localAck() { + ok->setDisabled(true); + QTextStream sockstream(mysock); + sockstream << "ACK NEW GAME\n"; +} + +void NewGameDialog::closeGame() { + mysock->close(); + done(1); +} diff --git a/newgame.h b/newgame.h new file mode 100644 index 0000000..963c96e --- /dev/null +++ b/newgame.h @@ -0,0 +1,60 @@ +/* VierGewinnt - A simple 4-in-a-row network game + * + * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de + * http://www.seba-geek.de + * + * This file is part of VierGewinnt. + * + * VierGewinnt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * VierGewinnt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VierGewinnt. If not, see . + */ + +#ifndef __NEWGAME_H +#define __NEWGAME_H + +#include +#include +#include +#include +#include +#include +#include + + +class NewGameDialog : public QDialog { + Q_OBJECT + + public: + NewGameDialog(QTcpSocket *sock, QWidget *parent=0); + + void reset(bool won); + void netPlayerAck(); + + private slots: + void localAck(); + void closeGame(); + + private: + QVBoxLayout *layout; + QHBoxLayout *buttonrow; + QLabel *gameend; + QLabel *newgame; + QLabel *netplayer; + QPushButton *ok; + QPushButton *cancel; + QTcpSocket *mysock; + + bool myack, youack; +}; + +#endif diff --git a/playerwait.cpp b/playerwait.cpp new file mode 100644 index 0000000..c6ecb95 --- /dev/null +++ b/playerwait.cpp @@ -0,0 +1,45 @@ +/* VierGewinnt - A simple 4-in-a-row network game + * + * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de + * http://www.seba-geek.de + * + * This file is part of VierGewinnt. + * + * VierGewinnt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * VierGewinnt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VierGewinnt. If not, see . + */ + +#include "playerwait.h" + +PlayerWaitDialog::PlayerWaitDialog(QTcpSocket *sock, QWidget *parent) : QDialog(parent) { + mysock = sock; + cancel = new QPushButton(tr("Abbrechen")); + connect(cancel, SIGNAL(clicked()), this, SLOT(closeGame())); + connect(this, SIGNAL(rejected()), this, SLOT(closeGame())); + waiting = new QLabel(tr("Warte auf anderen Spieler...")); + setWindowTitle(tr("Auf Spieler warten")); + + layout = new QVBoxLayout; + layout->addWidget(waiting); + layout->addStretch(); + layout->addWidget(cancel); + + setLayout(layout); + + setModal(Qt::WindowModal); +} + +void PlayerWaitDialog::closeGame() { + mysock->close(); + done(1); +} diff --git a/playerwait.h b/playerwait.h new file mode 100644 index 0000000..e440848 --- /dev/null +++ b/playerwait.h @@ -0,0 +1,49 @@ +/* VierGewinnt - A simple 4-in-a-row network game + * + * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de + * http://www.seba-geek.de + * + * This file is part of VierGewinnt. + * + * VierGewinnt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * VierGewinnt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VierGewinnt. If not, see . + */ + +#ifndef __PLAYERWAIT_H +#define __PLAYERWAIT_H + +#include +#include +#include +#include +#include + +class PlayerWaitDialog : public QDialog { + Q_OBJECT + + public: + PlayerWaitDialog(QTcpSocket *sock, QWidget *parent=0); + + private slots: + void closeGame(); + + private: + QVBoxLayout *layout; + QTcpSocket *mysock; + QPushButton *cancel; + QLabel *waiting; + +}; + + +#endif diff --git a/renderarea.cpp b/renderarea.cpp new file mode 100644 index 0000000..9ab3a9b --- /dev/null +++ b/renderarea.cpp @@ -0,0 +1,108 @@ +/* VierGewinnt - A simple 4-in-a-row network game + * + * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de + * http://www.seba-geek.de + * + * This file is part of VierGewinnt. + * + * VierGewinnt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * VierGewinnt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VierGewinnt. If not, see . + */ + +#include "renderarea.h" + +#include + +RenderArea::RenderArea(QWidget *parent) : QWidget(parent) { + QSizePolicy tmppol; + tmppol.setHorizontalPolicy(QSizePolicy::Maximum); + tmppol.setVerticalPolicy(QSizePolicy::Maximum); + setSizePolicy(tmppol); + +// this->antialiased = true; + + // pens + xpen.setColor(Qt::green); + xpen.setWidth(10); + xpen.setJoinStyle(Qt::RoundJoin); + xpen.setCapStyle(Qt::RoundCap); + + ypen.setColor(Qt::red); + ypen.setWidth(10); + + mfact = 0.75; + feld = 0; // just to clarify, also set in next statement + setFeldInfo(7, 6, 0); +} + +void RenderArea::setFeldInfo(int _x, int _y, VierGewinntWidget::Stein **_feld) { + fx = _x; + fy = _y; + feld = _feld; +} + +QSize RenderArea::minimumSizeHint() const { + return QSize(320, 240); +} + +QSize RenderArea::sizeHint() const { + return QSize(640, 480); +} + +void RenderArea::paintEvent(QPaintEvent * /*event*/) { + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing, true); + // Start with grid + int fsize = std::min(width()/fx, height()/fy); +// painter.drawLine(0, 0, width(), height()); + painter.translate((width()-fsize*fx)/2, (height()-fsize*fy)/2); + for(int i=0; i<=fx; i++) + painter.drawLine(i*fsize, 0, i*fsize, fsize*fy); + for(int i=0; i<=fy; i++) + painter.drawLine(0, i*fsize, fsize*fx, i*fsize); + + + if(feld==0) + return; + + // paint x and o + for(int i=0; ibutton()!=Qt::LeftButton) + return; + + int fsize = std::min(width()/fx, height()/fy); + int myrow = (event->x()-((width()-fsize*fx)/2))/fsize; + if(myrow<0||myrow>=fx||event->x()-((width()-fsize*fx)/2)<0) + return; + + addStein(myrow); +} diff --git a/renderarea.h b/renderarea.h new file mode 100644 index 0000000..3818c2c --- /dev/null +++ b/renderarea.h @@ -0,0 +1,56 @@ +/* VierGewinnt - A simple 4-in-a-row network game + * + * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de + * http://www.seba-geek.de + * + * This file is part of VierGewinnt. + * + * VierGewinnt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * VierGewinnt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VierGewinnt. If not, see . + */ + +#ifndef __RENDERAREA_H +#define __RENDERAREA_H + +#include +#include +#include +#include "viergewinnt.h" + +class RenderArea : public QWidget { + Q_OBJECT + + public: + RenderArea(QWidget *parent=0); + + void setFeldInfo(int _x, int _y, VierGewinntWidget::Stein **_feld); + QSize minimumSizeHint() const; + QSize sizeHint() const; + + signals: + void addStein(int row); + + protected: + void paintEvent(QPaintEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + + private: + int fx; + int fy; + float mfact; + VierGewinntWidget::Stein **feld; + QPen xpen; + QPen ypen; +}; + +#endif diff --git a/selectmaster.cpp b/selectmaster.cpp new file mode 100644 index 0000000..d7bddc3 --- /dev/null +++ b/selectmaster.cpp @@ -0,0 +1,84 @@ +/* VierGewinnt - A simple 4-in-a-row network game + * + * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de + * http://www.seba-geek.de + * + * This file is part of VierGewinnt. + * + * VierGewinnt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * VierGewinnt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VierGewinnt. If not, see . + */ + +#include "selectmaster.h" + +SelectMasterDialog::SelectMasterDialog(QWidget *parent) : QDialog(parent) { + labelhead = new QLabel(tr("Bitte gib einen anderen Masterserver an")); + labelmasteraddr = new QLabel(tr("Master-Server:")); + labelmasterport = new QLabel(tr("Master-Port:")); + editmasteraddr = new QLineEdit; + editmasterport = new QLineEdit; + okcancel = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + + connect(okcancel, SIGNAL(accepted()), this, SLOT(checkAndAccept())); + connect(okcancel, SIGNAL(rejected()), this, SLOT(reject())); + + layout = new QGridLayout; + layout->addWidget(labelhead, 0, 0, 1, 2); + layout->addWidget(labelmasteraddr, 1, 0); + layout->addWidget(editmasteraddr, 1, 1); + layout->addWidget(labelmasterport, 2, 0); + layout->addWidget(editmasterport, 2, 1); + layout->addWidget(okcancel, 3, 0, 1, 2); + + setLayout(layout); + setWindowTitle(tr("Master-Server ändern")); + setModal(Qt::WindowModal); + +} + +void SelectMasterDialog::checkAndAccept() { + if(editmasteraddr->text()=="") { + QMessageBox msgbox(this); + msgbox.setText(tr("Der Master-Server ist ungültig")); + msgbox.exec(); + return; + } + + int tmpport = editmasterport->text().toInt(); + if(tmpport<1||tmpport>65535) { + QMessageBox msgbox(this); + msgbox.setText(tr("Der Master-Port ist ungültig")); + msgbox.exec(); + return; + } + masterserver = editmasteraddr->text(); + masterport = tmpport; + accept(); +} + +void SelectMasterDialog::setData(QString srv, int port) { + masterserver = srv; + masterport = port; + editmasteraddr->setText(masterserver); + std::stringstream str; + str << masterport; + editmasterport->setText(QString(str.str().c_str())); +} + +QString SelectMasterDialog::getMasterServer() { + return masterserver; +} + +int SelectMasterDialog::getMasterPort() { + return masterport; +} diff --git a/selectmaster.h b/selectmaster.h new file mode 100644 index 0000000..c16c4a2 --- /dev/null +++ b/selectmaster.h @@ -0,0 +1,61 @@ +/* VierGewinnt - A simple 4-in-a-row network game + * + * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de + * http://www.seba-geek.de + * + * This file is part of VierGewinnt. + * + * VierGewinnt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * VierGewinnt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VierGewinnt. If not, see . + */ + +#ifndef __SELECTMASTER_H +#define __SELECTMASTER_H + +#include +#include +#include +#include +#include +#include +#include +#include + +class SelectMasterDialog : public QDialog { + Q_OBJECT + + public: + SelectMasterDialog(QWidget *parent=0); + void setData(QString srv, int port); + + QString getMasterServer(); + int getMasterPort(); + + private slots: + void checkAndAccept(); + + private: + QString masterserver; + int masterport; + + // Guistuff + QDialogButtonBox *okcancel; + QLineEdit *editmasteraddr; + QLineEdit *editmasterport; + QLabel *labelmasteraddr; + QLabel *labelmasterport; + QLabel *labelhead; + QGridLayout *layout; +}; + +#endif diff --git a/trans/viergewinnt-qt_en.qm b/trans/viergewinnt-qt_en.qm new file mode 100644 index 0000000..e3e95b9 Binary files /dev/null and b/trans/viergewinnt-qt_en.qm differ diff --git a/trans/viergewinnt-qt_en.ts b/trans/viergewinnt-qt_en.ts new file mode 100644 index 0000000..1914c7b --- /dev/null +++ b/trans/viergewinnt-qt_en.ts @@ -0,0 +1,341 @@ + + +ISO-8859-15 + + AboutDialog + + + Über + About + + + + Ok + Ok + + + + Netzwerk-VierGewinnt Client +Programmiert von seba +www.seba-geek.de + Network-VierGewinnt Client +Programmed by seba +www.seba-geek.de + + + + Erstes QT-Programm! +Dies ist ein Client für das VierGewinnt-Modul vom "Generic Network-Server". Endlich eine Verbesserung zum SDL-Client... + First QT-Programm! +This is a client for the VierGewinnt-Module from the "Generic Network-Server". At last an improvement to the SDL-Client... + + + + CreateGameDialog + + + Neues Spiel + New Game + + + + Spielname + Gamename + + + + Ok + Ok + + + + Abbrechen + Cancel + + + + Unbenanntes Spiel + Unknown Game + + + + FindServerWidget + + + Sebas Netzwerk-VierGewinnt Client + Sebas Network-VierGewinnt Client + + + + Serverliste + Serverlist + + + + Id + Id + + + + Spielname + Gamename + + + + Spieler + Players + + + + Spielfeld + Field + + + + Gewinnt + Wins + + + + Erneuern + Refresh + + + + Erstellen + Create + + + + Beitreten + Join + + + + Anderer Masterserver + Change masterserver + + + + Über + About + + + + Drücke Erneuern um eine Serverliste zu erhalten + Press Refresh to get the serverlist + + + + Fordere Liste an... + Requesting list... + + + + Spiel erstellt + Game created + + + + Es wurde kein Spiel zum beitreten ausgewählt + No Game was selected + + + + Trete Spiel bei.. + Joining game.. + + + + Version akzeptiert + Version accepted + + + + Version nicht akzeptiert, kein GNS-Server! + Version rejected, not a GNS-Server! + + + + Modul ausgewählt + Module selected + + + + VierGewinnt-Modul nicht gefunden! + VierGewinnt-Module not found! + + + + Keine Spiele offen :( + No games open :( + + + + Konnte nicht beitreten: Spiel voll + Could not join: Game full + + + + Spiel konnte nicht gefunden werden + Could not find game + + + + Fehler: Der Master-Server Hostname konnte nicht aufgelöst werden! + Error: The masterserver hostname could not be resolved! + + + + Fehler: Verbindungsversuch zum Master-Server ist fehlgeschlagen! + Error: Could not connect to masterserver! + + + + Netzwerkfehler: '%1' + Networkerror: '%1' + + + + Die Verbindung zum Masterserver wurde getrennt. + Disconnected from masterserver. + + + + Versuche Verbindung zu + Trying to connect to + + + + NewGameDialog + + + Ein neues Spiel? + A new game? + + + + Ok + Ok + + + + Abbrechen + Cancel + + + + Neues Spiel? + New game? + + + + Dein Mispieler hat bisher noch nicht zugestimmt. + Your opponent did not agree to a new game right now. + + + + Whee, du hast gewonnen! :) + Whee, you won! :) + + + + Du hast verloren -.- + You have lost -.- + + + + Dein Mispieler hat zugestimmt. + Your opponent agreed. + + + + PlayerWaitDialog + + + Abbrechen + Cancel + + + + Warte auf anderen Spieler... + Waiting for other player... + + + + Auf Spieler warten + Waiting for other player + + + + SelectMasterDialog + + + Bitte gib einen anderen Masterserver an + Please enter another masterserver + + + + Master-Server: + Masterserver: + + + + Master-Port: + Masterport: + + + + Master-Server ändern + Change masterserver + + + + Der Master-Server ist ungültig + The masterserver is invalid + + + + Der Master-Port ist ungültig + The masterport is invalid + + + + VierGewinntWidget + + + Sebas Netzwerk-VierGewinnt Client + Sebas Network-VierGewinnt Client + + + + Spielfenster + Gamewindow + + + + Spiel ist gestartet + The game has been started + + + + zu + to + + + + Spiel Beenden + Quit game + + + + Du bist am Zug + It's your move + + + + Dein Mitspieler ist am Zug + It's your opponents move + + + diff --git a/viergewinnt-qt.pro b/viergewinnt-qt.pro new file mode 100644 index 0000000..adef0a1 --- /dev/null +++ b/viergewinnt-qt.pro @@ -0,0 +1,33 @@ +###################################################################### +# Automatically generated by qmake (2.01a) Sa Nov 1 01:59:30 2008 +###################################################################### + +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . +DEFINES += QT_NO_DEBUG_OUTPUT +QT += network +CONFIG += qt warn_on release + +# Input +TRANSLATIONS = viergewinnt-qt_en.ts +CODECFORTR = ISO-8859-15 + +HEADERS += about.h \ + creategame.h \ + findserver.h \ + newgame.h \ + playerwait.h \ + renderarea.h \ + selectmaster.h \ + viergewinnt.h +SOURCES += about.cpp \ + creategame.cpp \ + findserver.cpp \ + main.cpp \ + newgame.cpp \ + playerwait.cpp \ + renderarea.cpp \ + selectmaster.cpp \ + viergewinnt.cpp diff --git a/viergewinnt.cpp b/viergewinnt.cpp new file mode 100644 index 0000000..5bb2193 --- /dev/null +++ b/viergewinnt.cpp @@ -0,0 +1,195 @@ +/* VierGewinnt - A simple 4-in-a-row network game + * + * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de + * http://www.seba-geek.de + * + * This file is part of VierGewinnt. + * + * VierGewinnt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * VierGewinnt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VierGewinnt. If not, see . + */ + +#include "viergewinnt.h" +#include "renderarea.h" + +VierGewinntWidget::VierGewinntWidget(QTcpSocket *tcpsock, QWidget *parent) : QDialog(parent) { + setFixedSize(640, 480); + setWindowTitle(tr("Sebas Netzwerk-VierGewinnt Client")+" - "+tr("Spielfenster")); + feld = 0; + mysock = tcpsock; + fx = 7; + fy = 6; + + // Arrange QT Stuff + status = new QLabel(tr("Spiel ist gestartet")); + rarea = new RenderArea; + connect(rarea, SIGNAL(addStein(int)), this, SLOT(netAdd(int))); + + myscore = new QLCDNumber(2); + vs = new QLabel(tr("zu")); + youscore = new QLCDNumber(2); + exit = new QPushButton(tr("Spiel Beenden")); + connect(exit, SIGNAL(clicked()), this, SLOT(closeGame())); + + // layout + upperrow = new QHBoxLayout; + upperrow->addStretch(); + upperrow->addWidget(status); + upperrow->addStretch(); + + underrow = new QHBoxLayout; + underrow->addStretch(); + underrow->addWidget(myscore); + underrow->addWidget(vs); + underrow->addWidget(youscore); + underrow->addStretch(); + underrow->addWidget(exit); + + layout = new QVBoxLayout; + layout->addLayout(upperrow); + layout->addWidget(rarea); + layout->addLayout(underrow); + setLayout(layout); + + waitforplayer = new PlayerWaitDialog(mysock, this); + newgame = new NewGameDialog(mysock, this); +} + +void VierGewinntWidget::init(int _x, int _y) { + qDebug() << "game init(" << _x << ", " << _y << ")\n"; + dealloc(); + + // reset all possible dialogues +// setDisabled(false); + newgame->hide(); + waitforplayer->hide(); + + fx = _x; + fy = _y; + feld = new Stein*[fx]; + for(int i=0; isetFeldInfo(fx, fy, feld); +} + +void VierGewinntWidget::startGame() { +// this->setDisabled(false); + // clear all dialogues here + qDebug() << "Starting Game"; + newgame->hide(); + waitforplayer->hide(); + + cleanFeld(); + QTextStream sockstream(mysock); + sockstream << "TURN\n"; + sockstream << "SHOWSCORE\n"; +} + +void VierGewinntWidget::add(int row, Stein st) { + for(int i=fy-1; i>=0; i--) { + qDebug() << "doing " << i << " for row " << row << ", adding " << st; + if(feld[row][i]==n) { + feld[row][i] = st; + rarea->update(); + setTurn(!myturn); + return; + } + } + +} + +void VierGewinntWidget::cleanFeld() { + qDebug() << "Cleaning Feld"; + if(feld==0) + return; + for(int i=0; iupdate(); + + while(!pendingadd.empty()) + pendingadd.pop(); +} + +void VierGewinntWidget::setTurn(bool _myturn) { + myturn = _myturn; + if(myturn) { + status->setText(tr("Du bist am Zug")); + } else { + status->setText(tr("Dein Mitspieler ist am Zug")); + } +} + +void VierGewinntWidget::clientExited() { + // pending dialog mit cancel + qDebug() << "Wait for player..."; + newgame->hide(); + waitforplayer->show(); +} + +void VierGewinntWidget::ackAdd(bool valid) { + if(valid) + add(pendingadd.front(), x); + pendingadd.pop(); +} + +void VierGewinntWidget::ackNewGame() { + newgame->netPlayerAck(); +} + +void VierGewinntWidget::newGame(bool won) { + if(won) { + setScore(myscore->intValue()+1, youscore->intValue()); + } else { + setScore(myscore->intValue(), youscore->intValue()+1); + } +// this->setDisabled(true); + newgame->reset(won); + newgame->show(); + + // exec, abhfangen +} + +void VierGewinntWidget::closeGame() { + mysock->close(); +} + +void VierGewinntWidget::netAdd(int row) { +// if(!myturn) +// return; + pendingadd.push(row); + QTextStream sockstream(mysock); + sockstream << "ADD " << row << "\n"; +} + +void VierGewinntWidget::setScore(int a, int b) { + myscore->display(a); + youscore->display(b); +} + +void VierGewinntWidget::dealloc() { + if(feld==0) + return; + for(int i=0; i. + */ + +#ifndef __VIERGEWINNT_H +#define __VIERGEWINNT_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "newgame.h" +#include "playerwait.h" + +class RenderArea; + +class VierGewinntWidget : public QDialog { + Q_OBJECT + + public: + VierGewinntWidget(QTcpSocket *tcpsock, QWidget *parent); + ~VierGewinntWidget(); + + enum Stein {n=0, x, o}; + + void init(int _x, int _y); + void startGame(); + void add(int row, Stein st); + void cleanFeld(); + void setScore(int a, int b); + + // called by networkstuff + void setTurn(bool _myturn); + void clientExited(); + void ackAdd(bool valid); + void ackNewGame(); + void newGame(bool won); + + private slots: + void closeGame(); + void netAdd(int row); + + private: + void dealloc(); + + int fx, fy; + Stein **feld; + QTcpSocket *mysock; + bool myturn; + std::queue pendingadd; + + // guistuff + QVBoxLayout *layout; + QHBoxLayout *upperrow; + QHBoxLayout *underrow; + PlayerWaitDialog *waitforplayer; + NewGameDialog *newgame; + + QLabel *status; + RenderArea *rarea; + QLCDNumber *myscore; + QLabel *vs; + QLCDNumber *youscore; + QPushButton *exit; +}; + +#endif