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