diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2009-10-05 09:49:54 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-10-05 09:51:38 (GMT) |
commit | 32a9237c49fd126bee0cbe02c3c5bff5145a6e21 (patch) | |
tree | 6fc313f62e0eafeda35483c9f3630f4275a472ec /demos/sub-attaq/states.cpp | |
parent | 429c7c6760c100685e9800b89fca7f0afd2d8abc (diff) | |
download | Qt-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.cpp | 39 |
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); } |