qt6windows7/examples/corelib/serialization/savegame/game.h

40 lines
729 B
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
#ifndef GAME_H
#define GAME_H
#include "character.h"
#include "level.h"
#include <QJsonObject>
#include <QList>
2023-11-02 01:02:52 +08:00
QT_FORWARD_DECLARE_CLASS(QTextStream)
2023-10-30 06:33:08 +08:00
//! [0]
class Game
{
public:
2023-11-02 01:02:52 +08:00
enum SaveFormat { Json, Binary };
2023-10-30 06:33:08 +08:00
Character player() const;
QList<Level> levels() const;
void newGame();
bool loadGame(SaveFormat saveFormat);
bool saveGame(SaveFormat saveFormat) const;
void read(const QJsonObject &json);
2023-11-02 01:02:52 +08:00
QJsonObject toJson() const;
void print(QTextStream &s, int indentation = 0) const;
2023-10-30 06:33:08 +08:00
private:
Character mPlayer;
QList<Level> mLevels;
};
//! [0]
#endif // GAME_H