qt6windows7/examples/corelib/serialization/savegame/main.cpp

41 lines
1.0 KiB
C++
Raw Normal View History

2023-10-30 06:33:08 +08:00
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "game.h"
#include <QCoreApplication>
#include <QStringList>
#include <QString>
#include <QTextStream>
using namespace Qt::StringLiterals; // for _L1
//! [0]
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
const QStringList args = QCoreApplication::arguments();
const bool newGame
2023-11-02 01:02:52 +08:00
= args.size() <= 1 || QString::compare(args[1], "load"_L1, Qt::CaseInsensitive) != 0;
2023-10-30 06:33:08 +08:00
const bool json
2023-11-02 01:02:52 +08:00
= args.size() <= 2 || QString::compare(args[2], "binary"_L1, Qt::CaseInsensitive) != 0;
2023-10-30 06:33:08 +08:00
Game game;
if (newGame)
game.newGame();
else if (!game.loadGame(json ? Game::Json : Game::Binary))
return 1;
// Game is played; changes are made...
//! [0]
//! [1]
2023-11-02 01:02:52 +08:00
QTextStream s(stdout);
s << "Game ended in the following state:\n";
game.print(s);
2023-10-30 06:33:08 +08:00
if (!game.saveGame(json ? Game::Json : Game::Binary))
return 1;
return 0;
}
//! [1]