diff options
author | Andreas Buhr <andreas@andreasbuhr.de> | 2021-03-02 15:27:50 +0100 |
---|---|---|
committer | Andreas Buhr <andreas@andreasbuhr.de> | 2021-03-05 15:21:21 +0100 |
commit | 4b9c6e69345169de23210852d0b1a3997668e942 (patch) | |
tree | fe076a0483002ba188801dba35fcf8e4338c983b /examples | |
parent | adbeef4d07cb49fa2f4b86582dfb61b545433ecb (diff) |
Pingpong example: Restart game at end
To play again, it was necessary to restart the whole executable.
This patch restarts the game at the end so that players can keep
playing.
Change-Id: I593a57862d449631d8f93b7d8e3cb56314f4fedd
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/bluetooth/pingpong/pingpong.cpp | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/examples/bluetooth/pingpong/pingpong.cpp b/examples/bluetooth/pingpong/pingpong.cpp index 5fa0ceba..2d7a05ee 100644 --- a/examples/bluetooth/pingpong/pingpong.cpp +++ b/examples/bluetooth/pingpong/pingpong.cpp @@ -70,6 +70,8 @@ PingPong::~PingPong() void PingPong::startGame() { + m_resultLeft = m_resultRight = 0; + emit resultChanged(); m_showDialog = false; emit showDialogChanged(); //! [Start the game] @@ -189,22 +191,23 @@ void PingPong::checkBoundaries() void PingPong::checkResult() { + if (m_resultRight < 10 && m_resultLeft < 10) + return; + if (m_resultRight == 10 && m_role == 2) { - setMessage("Game over. You win!"); - m_timer->stop(); + setMessage("Game over. You win! Next game starts in 10s"); } else if (m_resultRight == 10 && m_role == 1) { - setMessage("Game over. You lose!"); - m_timer->stop(); + setMessage("Game over. You lose! Next game starts in 10s"); } else if (m_resultLeft == 10 && m_role == 1) { - setMessage("Game over. You win!"); - m_timer->stop(); + setMessage("Game over. You win! Next game starts in 10s"); } else if (m_resultLeft == 10 && m_role == 2) { - setMessage("Game over. You lose!"); - m_timer->stop(); + setMessage("Game over. You lose! Next game starts in 10s"); } + m_timer->stop(); + QTimer::singleShot(10000, this, SLOT(startGame())); } void PingPong::startServer() |