♻️ Moved core game mechanic to its own class
parent
6375254892
commit
232174b309
@ -0,0 +1,30 @@
|
|||||||
|
#include "samegame.h"
|
||||||
|
|
||||||
|
// ist es nicht cool?
|
||||||
|
extern std::unique_ptr<QSettings> settings;
|
||||||
|
|
||||||
|
void SameGame::initialiseGameMatrix(int rows, int columns) {
|
||||||
|
gameMatrix = std::vector<std::vector<QString>>();
|
||||||
|
|
||||||
|
srand (time(NULL));
|
||||||
|
std::vector<QString> t_row;
|
||||||
|
for (int i = 0; i < rows; i++) {
|
||||||
|
t_row.clear();
|
||||||
|
for (int j = 0; j < columns; j++) {
|
||||||
|
// wähle zufällige Farbe aus den verfügbaren Farben
|
||||||
|
t_row.push_back( colors[rand() % colors.size()] );
|
||||||
|
}
|
||||||
|
gameMatrix.push_back(std::move(t_row));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SameGame::SameGame(int rows, int columns)
|
||||||
|
: colors(settings->value("colors/colors", QStringList() << "0xBD005E" << "0xFFC0CB" << "0xDB7093" << "0xF7A8B8" << "0x660033").toStringList())
|
||||||
|
// also ich finds echt cool!
|
||||||
|
{
|
||||||
|
initialiseGameMatrix(rows, columns);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString SameGame::getCell(int row, int column) {
|
||||||
|
return gameMatrix[row][column];
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
#ifndef SAMEGAME_H
|
||||||
|
#define SAMEGAME_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
class SameGame
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::vector<std::vector<QString>> gameMatrix;
|
||||||
|
const QStringList colors;
|
||||||
|
public:
|
||||||
|
void initialiseGameMatrix(int rows, int columns);
|
||||||
|
SameGame(int rows, int columns);
|
||||||
|
QString getCell(int row, int column);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SAMEGAME_H
|
Loading…
Reference in New Issue