From a14af13d8b0e68269e67273b213389c22e61ab2d Mon Sep 17 00:00:00 2001 From: Lyxas <lucas.gazeau@etu.univ-nantes.fr> Date: Thu, 4 Jun 2020 21:42:35 +0200 Subject: [PATCH] update pass --- GoGameCleintGui.pro | 2 ++ GoGameCleintGui.pro.user | 2 +- README.md | 1 - gopassbutton.cpp | 14 ++++++++++++++ gopassbutton.h | 22 ++++++++++++++++++++++ mainwindow.cpp | 40 ++++++++++++++++++++++++++++++++++------ mainwindow.h | 4 ++++ pawn.cpp | 7 ------- pawn.h | 36 ------------------------------------ 9 files changed, 77 insertions(+), 51 deletions(-) delete mode 100644 README.md create mode 100644 gopassbutton.cpp create mode 100644 gopassbutton.h delete mode 100644 pawn.cpp delete mode 100644 pawn.h diff --git a/GoGameCleintGui.pro b/GoGameCleintGui.pro index aa5e6da..8c2cc84 100644 --- a/GoGameCleintGui.pro +++ b/GoGameCleintGui.pro @@ -3,12 +3,14 @@ QT += widgets SOURCES += \ golabel.cpp \ + gopassbutton.cpp \ gopawn.cpp \ main.cpp \ mainwindow.cpp HEADERS += \ golabel.h \ + gopassbutton.h \ gopawn.h \ mainwindow.h diff --git a/GoGameCleintGui.pro.user b/GoGameCleintGui.pro.user index 718c7b9..2e73010 100644 --- a/GoGameCleintGui.pro.user +++ b/GoGameCleintGui.pro.user @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE QtCreatorProject> -<!-- Written by QtCreator 4.11.2, 2020-06-04T13:57:59. --> +<!-- Written by QtCreator 4.11.2, 2020-06-04T21:41:55. --> <qtcreator> <data> <variable>EnvironmentId</variable> diff --git a/README.md b/README.md deleted file mode 100644 index 73cb5c2..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -Client for Go Game \ No newline at end of file diff --git a/gopassbutton.cpp b/gopassbutton.cpp new file mode 100644 index 0000000..0b74e8d --- /dev/null +++ b/gopassbutton.cpp @@ -0,0 +1,14 @@ +#include "gopassbutton.h" +#include "mainwindow.h" + +GoPassButton::GoPassButton(QString str, QWidget *parent,MainWindow *window) +{ + this->setText(str); + w = window; + QObject::connect(this,&QPushButton::clicked,this,&GoPassButton::onClicked); +} + + +void GoPassButton::onClicked(){ + w->passTurn(); +} diff --git a/gopassbutton.h b/gopassbutton.h new file mode 100644 index 0000000..22448ff --- /dev/null +++ b/gopassbutton.h @@ -0,0 +1,22 @@ +#ifndef GOPASSBUTTON_H +#define GOPASSBUTTON_H + + +#include <QPushButton> + +class MainWindow; + +class GoPassButton : public QPushButton +{ + Q_OBJECT +public: + GoPassButton(QString str, QWidget *parent,MainWindow *window); + +public slots: + void onClicked(); + +private: + MainWindow *w; +}; + +#endif // GOPASSBUTTON_H diff --git a/mainwindow.cpp b/mainwindow.cpp index ee1d2f8..e1fe8ae 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -61,15 +61,16 @@ MainWindow::MainWindow(int nbPlay,int sock_C,sockaddr_in sa_S,unsigned int taill scoreJ1->setStyleSheet("background-color: rgba(255, 255, 255, 0.0);"); scoreJ2->setStyleSheet("background-color: rgba(255, 255, 255, 0.0);"); - scoreJ1->setText(QString("Nb J1 : 0")); - scoreJ2->setText(QString("Nb J2 : 0")); + scoreJ1->setText(QString("Nb Pawn captured by J1 : 0")); + scoreJ2->setText(QString("Nb Pawn captured by J2 : 0")); - scoreJ1->setGeometry(0,429,429,20); - scoreJ2->setGeometry(0,450,429,20); + scoreJ1->setGeometry(0,429,300,20); + scoreJ2->setGeometry(0,450,300,20); scene->addWidget(scoreJ1); scene->addWidget(scoreJ2); - QPushButton test("Skip your turn"); - scene->addWidget(&test); + passButton = new GoPassButton("Skip your turn",this,this); + passButton->setGeometry(329,429,100,41); + scene->addWidget(passButton); } @@ -105,6 +106,8 @@ void MainWindow::enableButton(bool b){ matrix[i][o]->setEnabled(b); } } + passButton->setEnabled(b); + } void MainWindow::play(GoPawn *p){ @@ -147,6 +150,12 @@ void MainWindow::updateMap(){ (struct sockaddr *) &sa_S, &taille_sa_S); enableButton(true); qDebug() << message; + QString tmp(message); + if(tmp.contains("stop")){ + enableButton(false); + QMessageBox::information(this,"END","It's the end of the Game ! You can now count the points"); + return; + } for(int o=0;o<81;o++){ if(message[o]=='X'){ matrix[o/9][o%9]->setIcon(QIcon(QPixmap("/home/lyxas/GoGameCleintGui/noir.png"))); @@ -184,3 +193,22 @@ void MainWindow::updateMap(){ enableButton(false); } +void MainWindow::passTurn(){ + sendto(sock_C, "pass", 2048 * sizeof(char), 0, + (struct sockaddr *) &sa_S, taille_sa_S); + + recvfrom(sock_C, message, 2048 * sizeof(char), 0, + (struct sockaddr *) &sa_S, &taille_sa_S); + if(message[0] != 'o' || message[1] != 'k'){ + updateMap(); + QMessageBox::warning(this,"Invalid Move","Invalid move. It's your turn"); + return; + } + enableButton(false); + QMessageBox::information(this,"Wait","The other player is playing"); + updateMap(); + updateMap(); + QMessageBox::information(this,"Your turn","It's your turn"); + enableButton(true); + +} diff --git a/mainwindow.h b/mainwindow.h index 71f4b00..4751e07 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -11,6 +11,7 @@ #include <QMessageBox> #include <QLabel> #include <golabel.h> +#include <gopassbutton.h> class MainWindow : public QWidget { @@ -26,6 +27,7 @@ public: void enableButton(bool b); void updateMap(); void play(GoPawn *p); + void passTurn(); ~MainWindow(); private: GoPawn *matrix[9][9]; @@ -43,6 +45,8 @@ private: GoLabel *scoreJ2; char message[2048]; + bool isGameOver; + GoPassButton *passButton; }; diff --git a/pawn.cpp b/pawn.cpp deleted file mode 100644 index 2ca8d33..0000000 --- a/pawn.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "pawn.h" - -Pawn::Pawn(int x, int y){ - this->x = x; - this->y = y; -} - diff --git a/pawn.h b/pawn.h deleted file mode 100644 index 15a516b..0000000 --- a/pawn.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef PAWN_H -#define PAWN_H - - -#include <QApplication> -#include <QtGui> -#include <QGraphicsScene> -#include <QGraphicsView> -#include <QPushButton> - - -class Pawn : public QPushButton -{ - Q_OBJECT -public: - Pawn(int x, int y); - void setX(int x); - void setY(int y); - void setNumJoueur(int numJoueur); - void setImg(QIcon *img); - - int getX(); - int getY(); - int getNumJoueur(); - QIcon* getImg(); -public slots: - void changePicture(); -private: - int x; - int y; - QIcon *imgJ1; - QIcon *imgJ2; - int numJoueur; -}; - -#endif // PAWN_H -- GitLab