Skip to content

Commit

Permalink
return home v51425
Browse files Browse the repository at this point in the history
  • Loading branch information
Augustin-maker committed Apr 16, 2024
1 parent 0b14582 commit 6f50c67
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
19 changes: 15 additions & 4 deletions src/screens/endgamescreen.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "endgamescreen.hpp"
#include "snakewindow.hpp"

#include <qfontdatabase.h>

Expand Down Expand Up @@ -76,10 +77,19 @@ EndGameScreen::EndGameScreen(const int score, QWidget *parent)
connect(submitButton, &QPushButton::clicked, this, &EndGameScreen::submitName);

// Création du bouton de retour au menu principal
QPushButton *returnButton = new QPushButton("Return to Main Menu", this);
returnButton->setFont(QFont("Arial", 16));
QPushButton *returnButton = new QPushButton("Main Menu", this);
snakefont.setPointSize(20);
returnButton->setFont(snakefont);
returnButton->setStyleSheet("padding-left: 20px; padding-right: 20px;");
returnButton->setFixedSize(200, 50); // Taille fixe pour le bouton
connect(returnButton, &QPushButton::clicked, this, &EndGameScreen::returnToMainMenu);
connect(returnButton, &QPushButton::clicked, [this]() {
// widget parent (SnakeWindow)
SnakeWindow *snakeWindow = qobject_cast<SnakeWindow *>(parentWidget());
if (snakeWindow) {
// Appeler returnToMainMenu de SnakeWindow
snakeWindow->returnToMainMenu();
}
});



Expand Down Expand Up @@ -115,5 +125,6 @@ void EndGameScreen::submitName() {

void EndGameScreen::returnToMainMenu() {
// Mettez ici le code pour revenir au menu principal, par exemple :
emit returnToMainMenuClicked(); // Émet un signal pour informer le parent que le bouton a été cliqué
emit back();

}
2 changes: 1 addition & 1 deletion src/screens/endgamescreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private slots:
QLineEdit *nameInput;

signals:
void returnToMainMenuClicked();
void back();
};

#endif //SNAKEQT_ENDGAMESCREEN_HPP
5 changes: 5 additions & 0 deletions src/screens/snakewindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,8 @@ void SnakeWindow::handleGameOver(const int score) {

update();
}

void SnakeWindow::returnToMainMenu() {
// Return to the main menu
stackedWidget->setCurrentWidget(mainMenu);
}
2 changes: 2 additions & 0 deletions src/screens/snakewindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public slots:

static void handleExitClicked();

void returnToMainMenu();

void toggleFullScreen() {
if (windowState() & Qt::WindowFullScreen) {
showNormal();
Expand Down

0 comments on commit 6f50c67

Please sign in to comment.