Viergewinnt (four-in-a-row) implementation in c++ and QT
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

newgame.cpp 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* VierGewinnt - A simple 4-in-a-row network game
  2. *
  3. * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de
  4. * http://www.seba-geek.de
  5. *
  6. * This file is part of VierGewinnt.
  7. *
  8. * VierGewinnt is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * VierGewinnt is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with VierGewinnt. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include "newgame.h"
  22. NewGameDialog::NewGameDialog(QTcpSocket *sock, QWidget *parent) : QDialog(parent) {
  23. mysock = sock;
  24. gameend = new QLabel("");
  25. newgame = new QLabel(tr("Ein neues Spiel?"));
  26. netplayer = new QLabel("");
  27. ok = new QPushButton(tr("Ok"));
  28. connect(ok, SIGNAL(clicked()), this, SLOT(localAck()));
  29. cancel = new QPushButton(tr("Abbrechen"));
  30. connect(cancel, SIGNAL(clicked()), this, SLOT(closeGame()));
  31. connect(this, SIGNAL(rejected()), this, SLOT(closeGame()));
  32. setWindowTitle(tr("Neues Spiel?"));
  33. reset(true);
  34. buttonrow = new QHBoxLayout;
  35. buttonrow->addStretch();
  36. buttonrow->addWidget(ok);
  37. buttonrow->addStretch();
  38. buttonrow->addWidget(cancel);
  39. buttonrow->addStretch();
  40. layout = new QVBoxLayout;
  41. layout->addWidget(gameend);
  42. layout->addSpacing(32);
  43. layout->addWidget(newgame);
  44. layout->addWidget(netplayer);
  45. layout->addLayout(buttonrow);
  46. //center
  47. layout->setAlignment(gameend, Qt::AlignHCenter);
  48. layout->setAlignment(newgame, Qt::AlignHCenter);
  49. layout->setAlignment(netplayer, Qt::AlignHCenter);
  50. setLayout(layout);
  51. setModal(Qt::WindowModal);
  52. }
  53. void NewGameDialog::reset(bool won) {
  54. netplayer->setText(tr("Dein Mispieler hat bisher noch nicht zugestimmt."));
  55. ok->setDisabled(false);
  56. if(won) {
  57. gameend->setText(tr("Whee, du hast gewonnen! :)"));
  58. } else {
  59. gameend->setText(tr("Du hast verloren -.-"));
  60. }
  61. }
  62. void NewGameDialog::netPlayerAck() {
  63. netplayer->setText(tr("Dein Mispieler hat zugestimmt."));
  64. }
  65. void NewGameDialog::localAck() {
  66. ok->setDisabled(true);
  67. QTextStream sockstream(mysock);
  68. sockstream << "ACK NEW GAME\n";
  69. }
  70. void NewGameDialog::closeGame() {
  71. mysock->close();
  72. done(1);
  73. }