File indexing completed on 2024-10-06 03:45:31
0001 /* 0002 SPDX-FileCopyrightText: 2009 Ian Wadham <iandw.au@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KGRLEVELGRID_H 0008 #define KGRLEVELGRID_H 0009 0010 #include "kgrglobals.h" 0011 0012 #include <QList> 0013 #include <QObject> 0014 0015 class KGrLevelGrid : public QObject 0016 { 0017 Q_OBJECT 0018 public: 0019 KGrLevelGrid (QObject * parent, const KGrRecording * theLevelData); 0020 ~KGrLevelGrid() override; 0021 0022 inline char cellType (int i, int j) { 0023 return layout [i + j * width]; 0024 } 0025 0026 inline Flags heroMoves (int i, int j) { 0027 return heroAccess [i + j * width]; 0028 } 0029 0030 inline Flags enemyMoves (int i, int j) { 0031 return enemyAccess [i + j * width]; 0032 } 0033 0034 inline void gotGold (const int i, const int j, const bool runnerHasGold) { 0035 layout [i + j * width] = (runnerHasGold) ? FREE : NUGGET; 0036 } 0037 0038 inline int enemyOccupied (int i, int j) { 0039 return enemyHere [i + j * width]; 0040 } 0041 0042 inline void setEnemyOccupied (int i, int j, const int spriteId) { 0043 enemyHere [i + j * width] = spriteId; 0044 } 0045 0046 void calculateAccess (bool pRunThruHole); 0047 0048 void changeCellAt (const int i, const int j, const char type); 0049 0050 void placeHiddenLadders(); 0051 0052 Q_SIGNALS: 0053 void showHiddenLadders (const QList<int> & ladders, const int width); 0054 0055 private: 0056 inline int index (int i, int j) { 0057 return (i + j * width); 0058 } 0059 0060 void calculateCellAccess (const int i, const int j); 0061 0062 int width; 0063 int height; 0064 0065 bool runThruHole; // Rule: Whether enemies run L/R through a hole. 0066 0067 QList<char> layout; 0068 QList<Flags> heroAccess; 0069 QList<Flags> enemyAccess; 0070 QList<int> enemyHere; 0071 0072 QList<int> hiddenLadders; 0073 QList<int> hiddenEnemies; 0074 QList<int> flashingGold; 0075 }; 0076 0077 #endif // KGRLEVELGRID_H