Skip to content
Snippets Groups Projects
Commit 0a3fa25b authored by Ulysse Durand's avatar Ulysse Durand
Browse files

Merge branch 'master' of gitlab.ec-lyon.fr:durandu/projetcppqt

parents 2e97628c 30cff4ea
Branches
No related tags found
No related merge requests found
...@@ -5,9 +5,10 @@ Item { ...@@ -5,9 +5,10 @@ Item {
width: 900 width: 900
height: 800 height: 800
Rectangle { Rectangle {
id: rectangle id: rectangle
color: "#ffffff" color: "#8ff0a4"
anchors.fill: parent anchors.fill: parent
Grid { Grid {
...@@ -20,21 +21,32 @@ Item { ...@@ -20,21 +21,32 @@ 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 {
...@@ -44,9 +56,3 @@ Item { ...@@ -44,9 +56,3 @@ Item {
} }
} }
Loader {
id: pageLoader2
anchors.centerIn: parent
}
}
...@@ -24,14 +24,14 @@ Window { ...@@ -24,14 +24,14 @@ Window {
font.pixelSize: 30 font.pixelSize: 30
} }
} }
/*
MenuDeroulant { MenuDeroulant {
id: menuDeroulant id: menuDeroulant
x: 38 x: 38
y: 301 y: 301
rectangleColor: "#b33939" rectangleColor: "#b33939"
} }
*/
Bouton { Bouton {
id: bouton id: bouton
x: 360 x: 360
...@@ -48,4 +48,26 @@ Window { ...@@ -48,4 +48,26 @@ Window {
anchors.centerIn: parent anchors.centerIn: parent
} }
Text {
id: _text1
x: 194
y: 167
width: 551
height: 56
color: "#0e0e0e"
text: qsTr("Projet par Ulysse Durand et Yanis Dziki, ")
font.pixelSize: 30
}
Text {
id: _text2
x: 186
y: 372
width: 551
height: 56
color: "#0e0e0e"
text: qsTr("Le jeu se lance par défaut avec un 5 essais\n pour des mots de 8 lettres")
font.pixelSize: 30
}
} }
...@@ -35,6 +35,17 @@ string Brain::getGrid() { ...@@ -35,6 +35,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;
......
...@@ -24,13 +24,34 @@ void Jeu::onClavierClick(QString lettre) { ...@@ -24,13 +24,34 @@ void Jeu::onClavierClick(QString lettre) {
if (currentIndex < width*height) { if (currentIndex < width*height) {
m_letterModel->setLetter(currentIndex, lettre); m_letterModel->setLetter(currentIndex, lettre);
currentIndex++; currentIndex++;
} }
brain->entreLettre(lettre.toStdString()[0]); brain->entreLettre(lettre.toStdString()[0]);
for (int index = 0; index < width*height; index ++) { for (int index = 0; index < width*height; 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();
// for (int index = 0; index < 40; index ++) {
// string nomCell = "cell_"+to_string(index/8)+"_"+to_string(index%8);
// QObject *cell = rootObject->findChild<QObject*>(nomCell);
// if (cell) {
// cell->setProperty("color", "red");
// }
// }
} }
......
...@@ -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;
}; };
...@@ -39,6 +39,15 @@ string Ligne::getMot() { ...@@ -39,6 +39,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