Skip to content
Snippets Groups Projects
Commit 47b210cf authored by Yanis Dziki's avatar Yanis Dziki
Browse files

Omg les couleurs

parent 358b142a
No related branches found
No related tags found
No related merge requests found
...@@ -20,28 +20,39 @@ Item { ...@@ -20,28 +20,39 @@ Item {
height: 400 height: 400
Repeater { Repeater {
model: letterModel // <-- C++ ListModel exposé ici model: letterModel
delegate: Rectangle { delegate: Rectangle {
width: 60 width: 60
height: 60 height: 60
color: "#dddddd"
border.color: "#888" border.color: "#888"
radius: 5 radius: 5
color: {
switch (model.state) {
case 1: return "yellow";
case 2: return "red";
default: return "#dddddd";
}
}
Text { Text {
anchors.centerIn: parent anchors.centerIn: parent
text: model.letter text: model.letter
font.pixelSize: 24 font.pixelSize: 24
} }
} }
} }
} }
}
Clavier { Clavier {
id: clavier id: clavier
x: 225 x: 225
y: 594 y: 594
} }
} }
}
...@@ -26,6 +26,17 @@ string Brain::getGrid() { ...@@ -26,6 +26,17 @@ string Brain::getGrid() {
return res; return res;
} }
string Brain::getGridStates() {
std::string res = "";
for (int i = 0; i < mNbEssaisMax; ++i) {
res += lignes[i]->getEtats(); // chaque ligne donne une string d'états
}
return res;
}
vector<string> Brain::getTxtFiles() { vector<string> Brain::getTxtFiles() {
vector<string> txtFiles; vector<string> txtFiles;
......
...@@ -27,6 +27,7 @@ public: ...@@ -27,6 +27,7 @@ public:
void supprLettre(); void supprLettre();
string getGrid(); string getGrid();
vector<Ligne*> lignes; vector<Ligne*> lignes;
string getGridStates();
private: private:
string dicodir; string dicodir;
......
...@@ -27,6 +27,7 @@ void Jeu::onClavierClick(QString lettre) { ...@@ -27,6 +27,7 @@ void Jeu::onClavierClick(QString lettre) {
if (currentIndex < 40) { // on évite de dépasser la grille if (currentIndex < 40) { // on évite de dépasser la grille
m_letterModel->setLetter(currentIndex, lettre); m_letterModel->setLetter(currentIndex, lettre);
currentIndex++; currentIndex++;
} }
...@@ -34,7 +35,15 @@ void Jeu::onClavierClick(QString lettre) { ...@@ -34,7 +35,15 @@ void Jeu::onClavierClick(QString lettre) {
brain->entreLettre(lettre.toStdString()[0]); brain->entreLettre(lettre.toStdString()[0]);
for (int index = 0; index < 40; index ++) { for (int index = 0; index < 40; index ++) {
m_letterModel->setLetter(index, QString::fromLatin1(&brain->getGrid()[index], 1)); m_letterModel->setLetter(index, QString::fromLatin1(&brain->getGrid()[index], 1));
} }
std::string etats = brain->getGridStates();
for (int index = 0; index < 40; ++index) {
int etat = etats[index] - '0'; // convertit '0', '1', '2' → 0, 1, 2
m_letterModel->setStates(index, etat);
}
// string lagrille = brain->getGrid(); // string lagrille = brain->getGrid();
// for (int index = 0; index < 40; index ++) { // for (int index = 0; index < 40; index ++) {
......
...@@ -5,6 +5,7 @@ LetterModel::LetterModel(QObject *parent) ...@@ -5,6 +5,7 @@ LetterModel::LetterModel(QObject *parent)
{ {
// Initialiser 40 lettres avec "_" // Initialiser 40 lettres avec "_"
m_letters.fill("_", 40); m_letters.fill("_", 40);
m_states.fill(0,40);
} }
int LetterModel::rowCount(const QModelIndex &parent) const { int LetterModel::rowCount(const QModelIndex &parent) const {
...@@ -18,19 +19,30 @@ QVariant LetterModel::data(const QModelIndex &index, int role) const { ...@@ -18,19 +19,30 @@ QVariant LetterModel::data(const QModelIndex &index, int role) const {
if (role == LetterRole) if (role == LetterRole)
return m_letters.at(index.row()); return m_letters.at(index.row());
else if (role == StateRole)
return m_states.at(index.row());
return QVariant(); return QVariant();
} }
QHash<int, QByteArray> LetterModel::roleNames() const { QHash<int, QByteArray> LetterModel::roleNames() const {
return { return {
{ LetterRole, "letter" } { LetterRole, "letter" },
{ StateRole, "state" }
}; };
} }
void LetterModel::setLetter(int index, const QString &value) { void LetterModel::setLetter(int index, const QString &value) {
if (index >= 0 && index < m_letters.size()) { if (index >= 0 && index < m_letters.size()) {
m_letters[index] = value; m_letters[index] = value;
emit dataChanged(this->index(index), this->index(index), { LetterRole }); emit dataChanged(this->index(index), this->index(index), { LetterRole });
} }
} }
void LetterModel::setStates(int index, int value) {
if (index >= 0 && index < m_states.size()) {
m_states[index] = value;
emit dataChanged(this->index(index), this->index(index), { StateRole });
}
}
...@@ -9,7 +9,8 @@ class LetterModel : public QAbstractListModel { ...@@ -9,7 +9,8 @@ class LetterModel : public QAbstractListModel {
public: public:
enum Roles { enum Roles {
LetterRole = Qt::UserRole + 1 LetterRole = Qt::UserRole + 1,
StateRole
}; };
explicit LetterModel(QObject *parent = nullptr); explicit LetterModel(QObject *parent = nullptr);
...@@ -19,7 +20,9 @@ public: ...@@ -19,7 +20,9 @@ public:
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
Q_INVOKABLE void setLetter(int index, const QString &value); Q_INVOKABLE void setLetter(int index, const QString &value);
Q_INVOKABLE void setStates(int index, int value);
private: private:
QVector<QString> m_letters; QVector<QString> m_letters;
QVector<int> m_states;
}; };
...@@ -40,6 +40,15 @@ string Ligne::getMot() { ...@@ -40,6 +40,15 @@ string Ligne::getMot() {
return res; return res;
} }
string Ligne::getEtats() {
string res ="";
for (int i=0; i<bonmot.length();i++) {
res = res + std::to_string(contenu[i]->getEtat());
}
return res;
}
void Ligne::show() { void Ligne::show() {
cout << "La ligne : |"; cout << "La ligne : |";
for (int i=0;i<bonmot.length();i++) { for (int i=0;i<bonmot.length();i++) {
......
...@@ -25,6 +25,8 @@ public: ...@@ -25,6 +25,8 @@ public:
vector<VraieCase*> contenu; vector<VraieCase*> contenu;
string getMot(); string getMot();
bool dansMot(char lettre, string mot); bool dansMot(char lettre, string mot);
string getEtats();
private: private:
string bonmot; string bonmot;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment