Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider a14af13d rédigé par Lucas GAZEAU's avatar Lucas GAZEAU
Parcourir les fichiers

update pass

parent 8aec029e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -3,12 +3,14 @@ QT += widgets ...@@ -3,12 +3,14 @@ QT += widgets
SOURCES += \ SOURCES += \
golabel.cpp \ golabel.cpp \
gopassbutton.cpp \
gopawn.cpp \ gopawn.cpp \
main.cpp \ main.cpp \
mainwindow.cpp mainwindow.cpp
HEADERS += \ HEADERS += \
golabel.h \ golabel.h \
gopassbutton.h \
gopawn.h \ gopawn.h \
mainwindow.h mainwindow.h
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!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> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
......
Client for Go Game
\ No newline at end of file
#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();
}
#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
...@@ -61,15 +61,16 @@ MainWindow::MainWindow(int nbPlay,int sock_C,sockaddr_in sa_S,unsigned int taill ...@@ -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);"); scoreJ1->setStyleSheet("background-color: rgba(255, 255, 255, 0.0);");
scoreJ2->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")); scoreJ1->setText(QString("Nb Pawn captured by J1 : 0"));
scoreJ2->setText(QString("Nb J2 : 0")); scoreJ2->setText(QString("Nb Pawn captured by J2 : 0"));
scoreJ1->setGeometry(0,429,429,20); scoreJ1->setGeometry(0,429,300,20);
scoreJ2->setGeometry(0,450,429,20); scoreJ2->setGeometry(0,450,300,20);
scene->addWidget(scoreJ1); scene->addWidget(scoreJ1);
scene->addWidget(scoreJ2); scene->addWidget(scoreJ2);
QPushButton test("Skip your turn"); passButton = new GoPassButton("Skip your turn",this,this);
scene->addWidget(&test); passButton->setGeometry(329,429,100,41);
scene->addWidget(passButton);
} }
...@@ -105,6 +106,8 @@ void MainWindow::enableButton(bool b){ ...@@ -105,6 +106,8 @@ void MainWindow::enableButton(bool b){
matrix[i][o]->setEnabled(b); matrix[i][o]->setEnabled(b);
} }
} }
passButton->setEnabled(b);
} }
void MainWindow::play(GoPawn *p){ void MainWindow::play(GoPawn *p){
...@@ -147,6 +150,12 @@ void MainWindow::updateMap(){ ...@@ -147,6 +150,12 @@ void MainWindow::updateMap(){
(struct sockaddr *) &sa_S, &taille_sa_S); (struct sockaddr *) &sa_S, &taille_sa_S);
enableButton(true); enableButton(true);
qDebug() << message; 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++){ for(int o=0;o<81;o++){
if(message[o]=='X'){ if(message[o]=='X'){
matrix[o/9][o%9]->setIcon(QIcon(QPixmap("/home/lyxas/GoGameCleintGui/noir.png"))); matrix[o/9][o%9]->setIcon(QIcon(QPixmap("/home/lyxas/GoGameCleintGui/noir.png")));
...@@ -184,3 +193,22 @@ void MainWindow::updateMap(){ ...@@ -184,3 +193,22 @@ void MainWindow::updateMap(){
enableButton(false); 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);
}
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QLabel> #include <QLabel>
#include <golabel.h> #include <golabel.h>
#include <gopassbutton.h>
class MainWindow : public QWidget class MainWindow : public QWidget
{ {
...@@ -26,6 +27,7 @@ public: ...@@ -26,6 +27,7 @@ public:
void enableButton(bool b); void enableButton(bool b);
void updateMap(); void updateMap();
void play(GoPawn *p); void play(GoPawn *p);
void passTurn();
~MainWindow(); ~MainWindow();
private: private:
GoPawn *matrix[9][9]; GoPawn *matrix[9][9];
...@@ -43,6 +45,8 @@ private: ...@@ -43,6 +45,8 @@ private:
GoLabel *scoreJ2; GoLabel *scoreJ2;
char message[2048]; char message[2048];
bool isGameOver;
GoPassButton *passButton;
}; };
......
#include "pawn.h"
Pawn::Pawn(int x, int y){
this->x = x;
this->y = y;
}
#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
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter