summaryrefslogtreecommitdiffstats
path: root/examples/statemachine/tankgame/gameovertransition.cpp
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eblomfel@trolltech.com>2009-05-14 11:12:12 (GMT)
committerEskil Abrahamsen Blomfeldt <eblomfel@trolltech.com>2009-05-14 11:12:12 (GMT)
commitededfad305258f9f450b314d9e2d53a6905bc6d0 (patch)
tree6a3b6e4d7ec09e596c0ba2b9f81b816614089962 /examples/statemachine/tankgame/gameovertransition.cpp
parentfa99a2ab12f646d73498b69fae0020da1abf9685 (diff)
downloadQt-ededfad305258f9f450b314d9e2d53a6905bc6d0.zip
Qt-ededfad305258f9f450b314d9e2d53a6905bc6d0.tar.gz
Qt-ededfad305258f9f450b314d9e2d53a6905bc6d0.tar.bz2
Pop up message when a tank wins the game
Also fixed: Added some docs and moved the tanks a little so they don't start partly outside the scene rect.
Diffstat (limited to 'examples/statemachine/tankgame/gameovertransition.cpp')
-rw-r--r--examples/statemachine/tankgame/gameovertransition.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/examples/statemachine/tankgame/gameovertransition.cpp b/examples/statemachine/tankgame/gameovertransition.cpp
new file mode 100644
index 0000000..21c3510
--- /dev/null
+++ b/examples/statemachine/tankgame/gameovertransition.cpp
@@ -0,0 +1,39 @@
+#include "gameovertransition.h"
+#include "tankitem.h"
+
+#include <QSignalEvent>
+#include <QSignalMapper>
+
+GameOverTransition::GameOverTransition(QAbstractState *targetState)
+ : QSignalTransition(new QSignalMapper(), SIGNAL(mapped(QObject*)))
+{
+ setTargetState(targetState);
+
+ QSignalMapper *mapper = qobject_cast<QSignalMapper *>(senderObject());
+ mapper->setParent(this);
+}
+
+void GameOverTransition::addTankItem(TankItem *tankItem)
+{
+ m_tankItems.append(tankItem);
+
+ QSignalMapper *mapper = qobject_cast<QSignalMapper *>(senderObject());
+ mapper->setMapping(tankItem, tankItem);
+ connect(tankItem, SIGNAL(aboutToBeDestroyed()), mapper, SLOT(map()));
+}
+
+bool GameOverTransition::eventTest(QEvent *e) const
+{
+ bool ret = QSignalTransition::eventTest(e);
+
+ if (ret) {
+ QSignalEvent *signalEvent = static_cast<QSignalEvent *>(e);
+ QObject *sender = qvariant_cast<QObject *>(signalEvent->arguments().at(0));
+ TankItem *tankItem = qobject_cast<TankItem *>(sender);
+ m_tankItems.removeAll(tankItem);
+
+ return m_tankItems.size() <= 1;
+ } else {
+ return false;
+ }
+} \ No newline at end of file