Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
projetcppqt
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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Durand Ulysse
projetcppqt
Commits
2fb5488b
Commit
2fb5488b
authored
3 months ago
by
Yanis Dziki
Browse files
Options
Downloads
Plain Diff
Omg les couleurs
parents
47b210cf
4a4b0813
No related branches found
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
motus/GameWindow.qml
+0
-1
0 additions, 1 deletion
motus/GameWindow.qml
motus/brain.cpp
+28
-16
28 additions, 16 deletions
motus/brain.cpp
motus/brain.h
+1
-0
1 addition, 0 deletions
motus/brain.h
motus/ligne.cpp
+3
-3
3 additions, 3 deletions
motus/ligne.cpp
motus/main.cpp
+3
-2
3 additions, 2 deletions
motus/main.cpp
with
35 additions
and
22 deletions
motus/GameWindow.qml
+
0
−
1
View file @
2fb5488b
...
@@ -55,4 +55,3 @@ Item {
...
@@ -55,4 +55,3 @@ Item {
}
}
}
}
This diff is collapsed.
Click to expand it.
motus/brain.cpp
+
28
−
16
View file @
2fb5488b
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#include
<iostream>
#include
<iostream>
#include
<filesystem>
#include
<filesystem>
#include
"fullligneexception.h"
#include
"fullligneexception.h"
#include
"emptyligneexception.h"
#include
<QString>
#include
<QString>
using
namespace
std
;
using
namespace
std
;
...
@@ -12,7 +13,7 @@ namespace fs = std::filesystem;
...
@@ -12,7 +13,7 @@ namespace fs = std::filesystem;
#include
"nowordexception.h"
#include
"nowordexception.h"
#include
"brain.h"
#include
"brain.h"
Brain
::
Brain
(
string
dicodir
)
:
dicodir
(
dicodir
),
nbEssais
(
0
)
{
Brain
::
Brain
(
string
dicodir
)
:
dicodir
(
dicodir
),
nbEssais
(
0
)
,
inGame
(
0
)
{
vector
<
string
>
files
=
getTxtFiles
();
vector
<
string
>
files
=
getTxtFiles
();
// TODO
// TODO
// Initialise le menu déroulant avec files
// Initialise le menu déroulant avec files
...
@@ -20,6 +21,14 @@ Brain::Brain(string dicodir) : dicodir(dicodir), nbEssais(0) {
...
@@ -20,6 +21,14 @@ Brain::Brain(string dicodir) : dicodir(dicodir), nbEssais(0) {
string
Brain
::
getGrid
()
{
string
Brain
::
getGrid
()
{
string
res
=
""
;
string
res
=
""
;
if
(
inGame
>
0
)
{
for
(
int
i
=
0
;
i
<
2
;
i
++
)
{
res
+=
" "
;}
res
+=
(
inGame
==
1
)
?
" LOSER "
:
" WINNER "
;
for
(
int
i
=
0
;
i
<
2
;
i
++
)
{
res
+=
" "
;}
return
res
;
}
for
(
int
i
=
0
;
i
<
mNbEssaisMax
;
i
++
)
{
for
(
int
i
=
0
;
i
<
mNbEssaisMax
;
i
++
)
{
res
+=
lignes
[
i
]
->
getMot
();
res
+=
lignes
[
i
]
->
getMot
();
}
}
...
@@ -55,13 +64,20 @@ vector<string> Brain::getTxtFiles() {
...
@@ -55,13 +64,20 @@ vector<string> Brain::getTxtFiles() {
}
}
void
Brain
::
entreLettre
(
char
lettre
)
{
void
Brain
::
entreLettre
(
char
lettre
)
{
if
(
inGame
>
0
)
return
;
if
(
lettre
==
'0'
)
{
if
(
lettre
==
'0'
)
{
validateWord
();
validateWord
();
return
;
return
;
}
}
if
(
lettre
==
'!'
)
{
if
(
lettre
==
'!'
)
{
try
{
supprLettre
();
supprLettre
();
lignes
[
nbEssais
]
->
show
();
lignes
[
nbEssais
]
->
show
();
}
catch
(
EmptyLigneException
e
)
{
cout
<<
e
.
what
()
<<
endl
;
}
return
;
return
;
}
}
try
{
try
{
...
@@ -88,8 +104,8 @@ void Brain::trouveMot() {
...
@@ -88,8 +104,8 @@ void Brain::trouveMot() {
string
line
;
string
line
;
cout
<<
"Mot de taille : "
<<
mTailleMot
<<
" dans "
<<
dico
<<
endl
;
cout
<<
"Mot de taille : "
<<
mTailleMot
<<
" dans "
<<
dico
<<
endl
;
while
(
std
::
getline
(
file
,
line
))
{
while
(
std
::
getline
(
file
,
line
))
{
if
(
line
.
length
()
==
mTailleMot
)
{
if
(
line
.
length
()
==
mTailleMot
+
1
)
{
listeMots
.
push_back
(
line
);
listeMots
.
push_back
(
line
.
substr
(
0
,
8
)
);
}
}
}
}
...
@@ -118,6 +134,7 @@ void Brain::initGame() {
...
@@ -118,6 +134,7 @@ void Brain::initGame() {
lignes
.
push_back
(
new
Ligne
(
getMot
()));
lignes
.
push_back
(
new
Ligne
(
getMot
()));
lignes
[
i
]
->
initLigne
();
lignes
[
i
]
->
initLigne
();
}
}
cout
<<
"Solution : "
<<
getMot
()
<<
endl
;
}
catch
(
NoWordException
e
)
{
}
catch
(
NoWordException
e
)
{
cout
<<
e
.
what
()
<<
endl
;
cout
<<
e
.
what
()
<<
endl
;
}
}
...
@@ -146,18 +163,13 @@ void Brain::validateWord() {
...
@@ -146,18 +163,13 @@ void Brain::validateWord() {
void
Brain
::
onGameFinish
(
bool
isWin
)
{
void
Brain
::
onGameFinish
(
bool
isWin
)
{
if
(
!
isWin
)
{
if
(
!
isWin
)
{
cout
<<
"Perdu !"
<<
endl
;
cout
<<
"Perdu !"
<<
endl
;
inGame
=
1
;
}
else
{
cout
<<
"Gagné !"
<<
endl
;
inGame
=
2
;
}
}
// TODO :
// Si isWin
// Affiche un message de victoire sur la fenetre menu
// Ferme la fenetre de jeu
// Sinon
// Affiche un message de defaite sur la fenetre menu
// Ferme la fenetre de jeu
// Reset du brain
nbEssais
=
0
;
nbEssais
=
0
;
lignes
.
clear
();
lignes
.
clear
();
}
}
This diff is collapsed.
Click to expand it.
motus/brain.h
+
1
−
0
View file @
2fb5488b
...
@@ -33,6 +33,7 @@ private:
...
@@ -33,6 +33,7 @@ private:
string
dicodir
;
string
dicodir
;
string
dico
;
string
dico
;
string
mot
;
string
mot
;
int
inGame
;
int
mNbEssaisMax
;
int
mNbEssaisMax
;
int
nbEssais
;
int
nbEssais
;
int
mTailleMot
;
int
mTailleMot
;
...
...
This diff is collapsed.
Click to expand it.
motus/ligne.cpp
+
3
−
3
View file @
2fb5488b
...
@@ -16,15 +16,15 @@ void Ligne::initLigne() {
...
@@ -16,15 +16,15 @@ void Ligne::initLigne() {
bool
Ligne
::
isGameCleared
()
{
bool
Ligne
::
isGameCleared
()
{
int
nbjustes
=
0
;
int
nbjustes
=
0
;
cout
<<
bonmot
.
length
()
<<
endl
;
show
();
show
();
for
(
int
i
=
0
;
i
<
bonmot
.
length
();
i
++
)
{
for
(
int
i
=
0
;
i
<
bonmot
.
length
();
i
++
)
{
char
bonnelettre
=
toupper
(
bonmot
[
i
]);
// Convert to uppercase
char
bonnelettre
=
toupper
(
bonmot
[
i
]);
char
lettreacomparer
=
contenu
[
i
]
->
getLetter
();
// Get the QChar from contenu
char
lettreacomparer
=
contenu
[
i
]
->
getLetter
();
int
etat1
=
(
bonnelettre
==
lettreacomparer
)
?
1
:
0
;
int
etat1
=
(
bonnelettre
==
lettreacomparer
)
?
1
:
0
;
int
etat2
=
Ligne
::
dansMot
(
lettreacomparer
,
bonmot
);
int
etat2
=
Ligne
::
dansMot
(
lettreacomparer
,
bonmot
);
int
etat
=
etat1
+
etat2
;
int
etat
=
etat1
+
etat2
;
contenu
[
i
]
->
setEtat
(
etat
);
contenu
[
i
]
->
setEtat
(
etat
);
nbjustes
+=
etat
;
}
}
...
...
This diff is collapsed.
Click to expand it.
motus/main.cpp
+
3
−
2
View file @
2fb5488b
...
@@ -20,13 +20,14 @@ int main(int argc, char *argv[]) {
...
@@ -20,13 +20,14 @@ int main(int argc, char *argv[]) {
engine
.
rootContext
()
->
setContextProperty
(
"letterModel"
,
&
letterModel
);
engine
.
rootContext
()
->
setContextProperty
(
"letterModel"
,
&
letterModel
);
engine
.
loadFromModule
(
"motus"
,
"Main"
);
engine
.
loadFromModule
(
"motus"
,
"Main"
);
QObject
*
rootObject
=
engine
.
rootObjects
().
first
();
// Gets the first root object
QObject
*
rootObject
=
engine
.
rootObjects
().
first
();
QQuickItem
*
rootItem
=
qobject_cast
<
QQuickItem
*>
(
rootObject
);
QQuickItem
*
rootItem
=
qobject_cast
<
QQuickItem
*>
(
rootObject
);
QQuickItem
*
parentItem
=
rootItem
;
QQuickItem
*
parentItem
=
rootItem
;
// Créer l'objet Jeu sans mot
Jeu
jeu
(
rootObject
);
Jeu
jeu
(
rootObject
);
jeu
.
setLetterModel
(
&
letterModel
);
jeu
.
setLetterModel
(
&
letterModel
);
engine
.
rootContext
()
->
setContextProperty
(
"jeu"
,
&
jeu
);
engine
.
rootContext
()
->
setContextProperty
(
"jeu"
,
&
jeu
);
...
...
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