summaryrefslogtreecommitdiffstats
path: root/demos/sub-attaq/states.cpp
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-10-05 09:49:54 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2009-10-05 09:51:38 (GMT)
commit32a9237c49fd126bee0cbe02c3c5bff5145a6e21 (patch)
tree6fc313f62e0eafeda35483c9f3630f4275a472ec /demos/sub-attaq/states.cpp
parent429c7c6760c100685e9800b89fca7f0afd2d8abc (diff)
downloadQt-32a9237c49fd126bee0cbe02c3c5bff5145a6e21.zip
Qt-32a9237c49fd126bee0cbe02c3c5bff5145a6e21.tar.gz
Qt-32a9237c49fd126bee0cbe02c3c5bff5145a6e21.tar.bz2
Simplification and use of QGraphicsObject in sub-attas demo
Reviewed-by: alexis
Diffstat (limited to 'demos/sub-attaq/states.cpp')
-rw-r--r--demos/sub-attaq/states.cpp39
1 files changed, 12 insertions, 27 deletions
diff --git a/demos/sub-attaq/states.cpp b/demos/sub-attaq/states.cpp
index 7443ae7..742095e 100644
--- a/demos/sub-attaq/states.cpp
+++ b/demos/sub-attaq/states.cpp
@@ -67,8 +67,7 @@ PlayState::PlayState(GraphicsScene *scene, QState *parent)
PlayState::~PlayState()
{
- if (machine)
- delete machine;
+ delete machine;
}
void PlayState::onEntry(QEvent *)
@@ -169,7 +168,7 @@ void LevelState::initializeLevel()
scene->boat->setCurrentDirection(Boat::None);
scene->boat->setBombsLaunched(0);
scene->boat->show();
- scene->setFocusItem(scene->boat,Qt::OtherFocusReason);
+ scene->setFocusItem(scene->boat, Qt::OtherFocusReason);
scene->boat->run();
scene->progressItem->setScore(game->score);
@@ -276,13 +275,8 @@ void WinState::onExit(QEvent *)
}
/** UpdateScore State */
-UpdateScoreState::UpdateScoreState(PlayState *game, QState *parent) : QState(parent)
-{
- this->game = game;
-}
-void UpdateScoreState::onEntry(QEvent *e)
+UpdateScoreState::UpdateScoreState(PlayState *g, QState *parent) : QState(parent), game(g)
{
- QState::onEntry(e);
}
/** Win transition */
@@ -297,12 +291,10 @@ bool UpdateScoreTransition::eventTest(QEvent *event)
{
if (!QSignalTransition::eventTest(event))
return false;
- else {
- QStateMachine::SignalEvent *se = static_cast<QStateMachine::SignalEvent*>(event);
- game->score += se->arguments().at(0).toInt();
- scene->progressItem->setScore(game->score);
- return true;
- }
+ QStateMachine::SignalEvent *se = static_cast<QStateMachine::SignalEvent*>(event);
+ game->score += se->arguments().at(0).toInt();
+ scene->progressItem->setScore(game->score);
+ return true;
}
/** Win transition */
@@ -317,12 +309,10 @@ bool WinTransition::eventTest(QEvent *event)
{
if (!QSignalTransition::eventTest(event))
return false;
- else {
- QStateMachine::SignalEvent *se = static_cast<QStateMachine::SignalEvent*>(event);
- game->score += se->arguments().at(0).toInt();
- scene->progressItem->setScore(game->score);
- return true;
- }
+ QStateMachine::SignalEvent *se = static_cast<QStateMachine::SignalEvent*>(event);
+ game->score += se->arguments().at(0).toInt();
+ scene->progressItem->setScore(game->score);
+ return true;
}
/** Space transition */
@@ -334,12 +324,7 @@ CustomSpaceTransition::CustomSpaceTransition(QWidget *widget, PlayState *game, Q
bool CustomSpaceTransition::eventTest(QEvent *event)
{
- Q_UNUSED(event);
if (!QKeyEventTransition::eventTest(event))
return false;
- if (game->currentLevel != 0)
- return true;
- else
- return false;
-
+ return (game->currentLevel != 0);
}