Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Momomotus
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pouchet Pierre
Momomotus
Commits
c829e69b
Commit
c829e69b
authored
1 month ago
by
Massies Alexandre
Browse files
Options
Downloads
Patches
Plain Diff
tri des mots selon le nombre de lettres et choix conséquent
parent
b416f5e2
Loading
Loading
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Motus/Main.qml
+33
-44
33 additions, 44 deletions
Motus/Main.qml
Motus/motusgame.cpp
+28
-13
28 additions, 13 deletions
Motus/motusgame.cpp
Motus/motusgame.h
+4
-1
4 additions, 1 deletion
Motus/motusgame.h
with
65 additions
and
58 deletions
Motus/Main.qml
+
33
−
44
View file @
c829e69b
...
...
@@ -34,55 +34,44 @@ Window {
// Gestion des touches du clavier physique (déclarée sous forme de fonction)
Keys.onPressed
:
function
(
event
)
{
if
(
case_focus
!=
-
1
&&
mot
!=
""
){
if
(
case_focus
&&
case_focus
.
_textText
!==
undefined
&&
/^
[
a-zA-Z
]
$/
.
test
(
event
.
text
))
{
case_focus
.
_textText
=
event
.
text
.
toUpperCase
();
if
(
mot
!=
""
){
// Saisie d'une lettre (de A à Z)
if
(
/^
[
a-zA-Z
]
$/
.
test
(
event
.
text
))
{
if
(
indice_case
<
nb_lettres
)
{
// On s'assure de ne pas dépasser la ligne
let
cellIndex
=
current_essai
*
nb_lettres
+
indice_case
;
caseArray
[
cellIndex
].
_textText
=
event
.
text
.
toUpperCase
();
indice_case
++
;
if
(
indice_case
<
nb_lettres
-
1
){
case_focus
=
caseArray
[
indice_case
+
nb_lettres
*
current_essai
];
}
else
{
case_focus
=
-
1
}
event
.
accepted
=
true
;
}
}
if
(
event
.
key
===
Qt
.
Key_Backspace
)
{
if
(
indice_case
>
0
&&
indice_case
!=
nb_lettres
-
1
)
{
// Gestion de la touche Backspace
else
if
(
event
.
key
===
Qt
.
Key_Backspace
)
{
if
(
indice_case
>
0
)
{
// On peut effacer si on a déjà saisi une lettre
indice_case
--
;
case_focus
=
caseArray
[
indice_case
];
case_focus
.
_textText
=
"
"
;
}
else
if
(
indice_case
===
nb_lettres
-
1
)
{
case_focus
=
caseArray
[
indice_case
+
nb_lettres
*
current_essai
];;
case_focus
.
textText
=
"
"
;
}
let
cellIndex
=
current_essai
*
nb_lettres
+
indice_case
;
caseArray
[
cellIndex
].
_textText
=
""
;
event
.
accepted
=
true
;
}
else
if
(
event
.
key
===
Qt
.
Key_Return
&&
indice_case
===
nb_lettres
-
1
)
{
if
(
current_essai
===
nb_essais
-
1
){
// on entre dans la boucle de l'endgame
// il faut bloquer toute interaction autre que relancer une partie ;
// reset les paramètres de gestion du focus des cases ;
// déclencher une animation de fin qui indique la victoire ou la défaite
// update les stats
nb_essais
=
0
;
}
else
{
// verificastr de la propal
// lettre mal placée : f0d437 (jaune) ; lettre mauvaise : 323232 (fond window) ; lettre bien placée : 23ed1c
// Passage à la ligne suivante avec la touche Entrée
else
if
(
event
.
key
===
Qt
.
Key_Return
)
{
// On ne passe à la ligne suivante que si la ligne est complètement remplie
if
(
indice_case
===
nb_lettres
)
{
// Ici, vous pouvez ajouter la vérification de la proposition (vérifier les lettres, colorier, etc.)
if
(
current_essai
<
nb_essais
-
1
)
{
current_essai
++
;
case_focus
=
caseArray
[
indice_case
+
nb_lettres
*
current_essai
];
}
indice_case
=
0
;
}
else
{
// Fin de partie : désactiver l'interface ou lancer une animation de fin, etc.
// Par exemple, réinitialiser nb_essais ou afficher un message
mot
=
""
;
}
event
.
accepted
=
true
;
}
}
}
}
// Disposition globale en colonne
...
...
@@ -122,7 +111,7 @@ Window {
anchors.fill
:
parent
cursorShape
:
Qt
.
PointingHandCursor
onClicked
:
{
// début d'une game, il faut bloquer les boutons de régénération etc
mot
=
motusGame
.
getRandomWord
();
mot
=
motusGame
.
getRandomWord
(
nb_lettres
);
motusGame
.
startTimer
();
case3
.
_textText
=
mot
;
mot_split
=
mot
.
split
(
""
);
...
...
This diff is collapsed.
Click to expand it.
Motus/motusgame.cpp
+
28
−
13
View file @
c829e69b
...
...
@@ -42,30 +42,45 @@ MotusGame::MotusGame(QObject *parent) : QObject(parent) {
// Générer un mot //////////////////////////////////////////////////////////////////////////////////////////
void
MotusGame
::
loadWords
()
{
words
.
clear
();
QFile
file
(
dictionnaryChoosed
);
// ✅ fonctionne avec le .qrc
// Vider la structure existante
wordsByLength
.
clear
();
QFile
file
(
dictionnaryChoosed
);
// Fichier dans le .qrc
if
(
file
.
open
(
QIODevice
::
ReadOnly
|
QIODevice
::
Text
))
{
QTextStream
in
(
&
file
);
while
(
!
in
.
atEnd
())
{
QString
line
=
in
.
readLine
().
trimmed
();
if
(
!
line
.
isEmpty
())
words
.
append
(
line
);
if
(
!
line
.
isEmpty
())
{
int
len
=
line
.
length
();
// On ne conserve que les mots de 4 à 12 lettres
if
(
len
>=
4
&&
len
<=
12
)
{
wordsByLength
[
len
].
append
(
line
);
}
}
}
file
.
close
();
qDebug
()
<<
"✅ Mots chargés :"
<<
words
.
size
();
int
totalWords
=
0
;
// Calcul du nombre total de mots chargés dans l'intervalle [4,12]
for
(
int
i
=
4
;
i
<=
12
;
++
i
)
{
totalWords
+=
wordsByLength
[
i
].
size
();
}
qDebug
()
<<
"✅ Mots chargés :"
<<
totalWords
;
}
else
{
qDebug
()
<<
"❌ Erreur : impossible d'ouvrir
words_alpha.txt"
;
qDebug
()
<<
"❌ Erreur : impossible d'ouvrir
"
<<
dictionnaryChoosed
;
}
}
QString
MotusGame
::
getRandomWord
(
)
{
if
(
words
.
isEmpty
())
QString
MotusGame
::
getRandomWord
(
int
letterCount
)
{
// Vérifier que le nombre de lettres est dans l'intervalle autorisé
if
(
letterCount
<
4
||
letterCount
>
12
)
{
qDebug
()
<<
"❌ Nombre de lettres invalide. Choisissez un nombre entre 4 et 12."
;
return
""
;
int
index
=
QRandomGenerator
::
global
()
->
bounded
(
words
.
size
());
motChoisi
=
words
[
index
];
// <- ici on le stocke
}
if
(
!
wordsByLength
.
contains
(
letterCount
)
||
wordsByLength
[
letterCount
].
isEmpty
())
{
qDebug
()
<<
"❌ Aucun mot disponible pour"
<<
letterCount
<<
"lettres."
;
return
""
;
}
int
index
=
QRandomGenerator
::
global
()
->
bounded
(
wordsByLength
[
letterCount
].
size
());
motChoisi
=
wordsByLength
[
letterCount
][
index
];
// Stockage du mot choisi
return
motChoisi
;
}
...
...
This diff is collapsed.
Click to expand it.
Motus/motusgame.h
+
4
−
1
View file @
c829e69b
...
...
@@ -4,6 +4,7 @@
#include
<QObject>
#include
<QString>
#include
<QStringList>
#include
<QMap>
#include
<QTimer>
...
...
@@ -24,7 +25,7 @@ class MotusGame : public QObject {
public:
explicit
MotusGame
(
QObject
*
parent
=
nullptr
);
Q_INVOKABLE
QString
getRandomWord
();
Q_INVOKABLE
QString
getRandomWord
(
int
value
);
QString
getDictionnaryChoosed
()
const
;
//Pour le changement de mot à deviner
void
setDictionnaryChoosed
(
const
QString
&
value
);
...
...
@@ -45,6 +46,8 @@ private:
QString
motChoisi
;
// Mot choisi aléatoirement dans la liste, selon le nombre de lettres choisi par l'utilisateur
QMap
<
int
,
QStringList
>
wordsByLength
;
int
letterNumber
;
// Nombre de lettres dans le mot, choisi par l'utilisateur
bool
randomizeletterNumber
=
true
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment