savegame ex.: give some TLC to main()
- include what you use - make 'args' const, so we don't detach in op[] - make boolean variables const - use QString::compare(lhs, rhs, Qt::CaseInsensitive) instead of lhs.toLower() == rhs - use new _L1 UDL - fix indentation of a return statement Change-Id: If9da4fbe975d9a97939ea01558b2a8cef7ad3a24 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> (cherry picked from commit 9834e80833783357743b2a5abe3071760638effb) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
f6e07ba983
commit
6c07770372
@ -4,25 +4,28 @@
|
|||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QString>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
|
||||||
|
using namespace Qt::StringLiterals; // for _L1
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
QStringList args = QCoreApplication::arguments();
|
|
||||||
bool newGame = true;
|
const QStringList args = QCoreApplication::arguments();
|
||||||
if (args.length() > 1)
|
const bool newGame
|
||||||
newGame = (args[1].toLower() != QStringLiteral("load"));
|
= args.size() <= 1 || QString::compare(args[1], "load"_L1, Qt::CaseInsensitive) == 0;
|
||||||
bool json = true;
|
const bool json
|
||||||
if (args.length() > 2)
|
= args.size() <= 2 || QString::compare(args[2], "binary"_L1, Qt::CaseInsensitive) == 0;
|
||||||
json = (args[2].toLower() != QStringLiteral("binary"));
|
|
||||||
|
|
||||||
Game game;
|
Game game;
|
||||||
if (newGame)
|
if (newGame)
|
||||||
game.newGame();
|
game.newGame();
|
||||||
else if (!game.loadGame(json ? Game::Json : Game::Binary))
|
else if (!game.loadGame(json ? Game::Json : Game::Binary))
|
||||||
return 1;
|
return 1;
|
||||||
// Game is played; changes are made...
|
// Game is played; changes are made...
|
||||||
//! [0]
|
//! [0]
|
||||||
//! [1]
|
//! [1]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user