From 827f3ccdf6ee3e05510c0f63df0cb80b3e674780 Mon Sep 17 00:00:00 2001 From: dm1sh Date: Sat, 28 May 2022 18:56:32 +0300 Subject: [PATCH] Added game finished message --- GamePanel.cpp | 14 ++++++++++++++ MainFrame.cpp | 27 ++++++++++++++++++++++++--- events.h | 9 +++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 events.h diff --git a/GamePanel.cpp b/GamePanel.cpp index 2ef17e8..1d5e84b 100644 --- a/GamePanel.cpp +++ b/GamePanel.cpp @@ -2,6 +2,7 @@ #include +#include "events.h" #include "utils.h" // clang-format off @@ -82,9 +83,20 @@ void GamePanel::OnResize(wxSizeEvent& _) { Refresh(); } +wxDEFINE_EVENT(END_EVT, wxCommandEvent); + void GamePanel::OnTimer(wxTimerEvent& _) { controller.stopwatch += 1; sb->SetStatusText(LTimeToStr(controller.stopwatch), 0); + + if (controller.remaining == 0) { + wxCommandEvent event(END_EVT); + event.SetString(LTimeToStr(controller.stopwatch)); + wxPostEvent(GetParent(), event); + + timer.Stop(); + controller.stopwatch = 0; + } } void GamePanel::OnClick(wxMouseEvent& _) { @@ -94,6 +106,8 @@ void GamePanel::OnClick(wxMouseEvent& _) { drawer.composeBoard(controller.getTable(), controller.gridSize); + wxLogDebug(wxString::Format(_("Remaining %i"), controller.remaining)); + Refresh(); } } diff --git a/MainFrame.cpp b/MainFrame.cpp index b32bb39..46a1ebf 100644 --- a/MainFrame.cpp +++ b/MainFrame.cpp @@ -4,6 +4,8 @@ #include "HelpDlg.h" #include "RulesDlg.h" +#include "events.h" + #include "resources/icon.xpm" MainFrame::MainFrame() @@ -23,6 +25,19 @@ MainFrame::MainFrame() }); }); + Bind(END_EVT, [this](wxCommandEvent& evt) -> void { + wxMessageDialog dlg(this, _("Хотите сыграть снова?"), + _("Игра окончена"), wxYES_NO); + dlg.SetExtendedMessage(_("Поздравляем, вы закончили игру за ") + + evt.GetString()); + if (dlg.ShowModal() == wxID_YES) { + panel->Start(layoutPath, solveable, + [this](const wxSize& size) -> void { + this->SetMinClientSize(size); + }); + } + }); + CreateStatusBar(2); panel = new GamePanel(this); @@ -71,17 +86,23 @@ void MainFrame::bindMenu() { Bind( wxEVT_MENU, - [this](wxCommandEvent& _) -> void { (new HelpDlg(this, -1))->Show(); }, + [this](wxCommandEvent& _) -> void { + (new HelpDlg(this, wxID_ANY))->Show(); + }, IDM_Help); Bind( wxEVT_MENU, - [this](wxCommandEvent& _) -> void { (new AboutDlg(this, -1))->Show(); }, + [this](wxCommandEvent& _) -> void { + (new AboutDlg(this, wxID_ANY))->Show(); + }, IDM_About); Bind( wxEVT_MENU, - [this](wxCommandEvent& _) -> void { (new RulesDlg(this, -1))->Show(); }, + [this](wxCommandEvent& _) -> void { + (new RulesDlg(this, wxID_ANY))->Show(); + }, IDM_Rules); Bind( diff --git a/events.h b/events.h new file mode 100644 index 0000000..efe0cea --- /dev/null +++ b/events.h @@ -0,0 +1,9 @@ +#ifndef EVENTS_H +#define EVENTS_H + +#include "wxw.h" + +wxDECLARE_EVENT(START_EVT, wxCommandEvent); +wxDECLARE_EVENT(END_EVT, wxCommandEvent); + +#endif \ No newline at end of file