File indexing completed on 2024-04-21 04:02:06

0001 /***************************************************************************
0002 *   KBlocks, a falling blocks game by KDE                                *
0003 *   SPDX-FileCopyrightText: 2010 Zhongjie Cai <squall.leonhart.cai@gmail.com>       *
0004 *                                                                         *
0005 *   SPDX-License-Identifier: GPL-2.0-or-later
0006 ***************************************************************************/
0007 #ifndef KBLOCKSGAMEREPLAYER_H
0008 #define KBLOCKSGAMEREPLAYER_H
0009 
0010 #include "KBlocksDefine.h"
0011 
0012 #include <fstream>
0013 #include <string>
0014 #include <vector>
0015 #include <list>
0016 #include <map>
0017 
0018 using std::string;
0019 using std::vector;
0020 using std::list;
0021 using std::map;
0022 
0023 struct KBlocksReplayData {
0024     int index;
0025     int type;
0026     int value;
0027     int time;
0028 };
0029 
0030 class KBlocksGameReplayer
0031 {
0032 public:
0033     explicit KBlocksGameReplayer(const char *fileName, bool isBinaryMode = true);
0034     ~KBlocksGameReplayer();
0035 
0036 public:
0037     void setStepLength(int stepLen);
0038 
0039     int getGameCount();
0040     int getGameSeed();
0041     bool isSameSeed();
0042 
0043     bool getNextRecords(vector<KBlocksReplayData> *data);
0044 
0045 private:
0046     void loadText(std::ifstream &pFile);
0047     void loadBinary(std::ifstream &pFile);
0048 
0049 private:
0050     int mGameCount;
0051     int mGameSeed;
0052     bool mSameSeed;
0053     int mStepLength;
0054     list<KBlocksReplayData> mReplayList;
0055     map<string, int> mRTMap;
0056 };
0057 
0058 #endif