summaryrefslogtreecommitdiffstats
path: root/examples/corelib/json/savegame/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/corelib/json/savegame/main.cpp')
-rw-r--r--examples/corelib/json/savegame/main.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/examples/corelib/json/savegame/main.cpp b/examples/corelib/json/savegame/main.cpp
index 2e4e864942..d091684211 100644
--- a/examples/corelib/json/savegame/main.cpp
+++ b/examples/corelib/json/savegame/main.cpp
@@ -49,30 +49,32 @@
****************************************************************************/
#include <QCoreApplication>
+#include <QTextStream>
#include "game.h"
//! [0]
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
+ QStringList args = QCoreApplication::arguments();
+ bool newGame = true;
+ if (args.length() > 1)
+ newGame = (args[1].toLower() != QStringLiteral("load"));
+ bool json = true;
+ if (args.length() > 2)
+ json = (args[2].toLower() != QStringLiteral("binary"));
Game game;
- game.newGame();
+ if (newGame)
+ game.newGame();
+ else if (!game.loadGame(json ? Game::Json : Game::Binary))
+ return 1;
// Game is played; changes are made...
//! [0]
//! [1]
- if (!game.saveGame(Game::Json))
- return 1;
-
- if (!game.saveGame(Game::Binary))
- return 1;
-
- Game fromJsonGame;
- if (!fromJsonGame.loadGame(Game::Json))
- return 1;
-
- Game fromBinaryGame;
- if (!fromBinaryGame.loadGame(Game::Binary))
+ QTextStream(stdout) << "Game ended in the following state:\n";
+ game.print();
+ if (!game.saveGame(json ? Game::Json : Game::Binary))
return 1;
return 0;