Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
JeuDeTaquin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Benjamin LEROUX
JeuDeTaquin
Commits
86c2180f
Commit
86c2180f
authored
Feb 22, 2021
by
Benjamin LEROUX
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Victory commit
parent
936f6a4b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
13 deletions
+40
-13
jeuDuTaquin.dart
lib/jeuDuTaquin.dart
+40
-13
No files found.
lib/jeuDuTaquin.dart
View file @
86c2180f
...
...
@@ -7,8 +7,9 @@ class TileWidget extends StatelessWidget {
bool
isUsable
=
false
;
TextStyle
textStyle
=
TextStyle
(
fontSize:
10
,
fontWeight:
FontWeight
.
bold
,
color:
Colors
.
red
,);
String
nbrText
=
""
;
int
index
;
TileWidget
(
this
.
tile
,
this
.
isUsable
,
this
.
nbrText
);
TileWidget
(
this
.
tile
,
this
.
isUsable
,
this
.
nbrText
,
this
.
index
);
@override
Widget
build
(
BuildContext
context
)
{
...
...
@@ -65,14 +66,14 @@ List<TileWidget>createTileWidgets(double slide, int emptyIndex, List<Tile> listT
for
(
int
i
=
0
;
i
<
max
;
i
++){
if
(
i
==
emptyIndex
&&
play
){
tiles
.
add
(
TileWidget
(
Tile
(
imageURL:
"https://upload.wikimedia.org/wikipedia/commons/thumb/6/6e/Fond_blanc.svg/1200px-Fond_blanc.svg.png"
,
alignment:
Alignment
(-
1
,-
1
),
size:
slide
),
false
,
""
));
alignment:
Alignment
(-
1
,-
1
),
size:
slide
),
false
,
""
,
i
));
}
else
if
(((
i
==
emptyIndex
+
1
&&
i
%
ligne
!=
0
)
||
i
==
emptyIndex
+
ligne
||
(
i
==
emptyIndex
-
1
&&
(
i
+
1
)%
ligne
!=
0
)||
i
==
emptyIndex
-
ligne
)
&&
play
){
tiles
.
add
(
TileWidget
(
listTiles
[
i
],
true
,
getRightText
(
nombres
,
i
)));
tiles
.
add
(
TileWidget
(
listTiles
[
i
],
true
,
getRightText
(
nombres
,
i
)
,
i
));
}
else
tiles
.
add
(
TileWidget
(
listTiles
[
i
],
false
,
getRightText
(
nombres
,
i
)));
else
tiles
.
add
(
TileWidget
(
listTiles
[
i
],
false
,
getRightText
(
nombres
,
i
)
,
i
));
}
return
tiles
;
}
...
...
@@ -86,12 +87,14 @@ class JeuDuTaquin extends StatefulWidget {
class
JeuDuTaquinState
extends
State
<
JeuDuTaquin
>
{
TextStyle
textStyle
=
TextStyle
(
fontSize:
16
,
fontWeight:
FontWeight
.
bold
,);
TextStyle
victoryStyle
=
TextStyle
(
fontSize:
26
,
fontWeight:
FontWeight
.
bold
,
color:
Colors
.
red
);
var
appBar
=
AppBar
(
title:
Text
(
'Jeu Du Taquin'
),);
List
<
TileWidget
>
tiles
=
createTileWidgets
(
3
,
4
,
createListTile
(
3
),
false
,
false
);
double
_currentSlideValue
=
3
;
double
_currentDifficultyValue
=
100
;
bool
isPlaying
=
false
;
bool
_numbers
=
false
;
bool
_isWon
=
false
;
int
emptyIndex
=
4
;
int
previousEmptyIndex
=-
1
;
int
count
=
0
;
...
...
@@ -104,7 +107,7 @@ class JeuDuTaquinState extends State<JeuDuTaquin> {
body:
ListView
(
children:
[
SizedBox
(
width:
MediaQuery
.
of
(
context
).
size
.
width
,
height:
MediaQuery
.
of
(
context
).
size
.
height
*
0.
6
,
height:
MediaQuery
.
of
(
context
).
size
.
height
*
0.
53
,
child:
Container
(
child:
GridView
.
builder
(
padding:
const
EdgeInsets
.
all
(
10
),
...
...
@@ -123,6 +126,10 @@ class JeuDuTaquinState extends State<JeuDuTaquin> {
previousEmptyIndex
=
emptyIndex
;
//on garde le coup précédent
count
++;
//on incremente le compteur de coup
swapTiles
(
index
,
emptyIndex
);
if
(
isWon
()){
reset
();
_isWon
=
true
;
}
},
),
);
...
...
@@ -130,6 +137,14 @@ class JeuDuTaquinState extends State<JeuDuTaquin> {
),
),
),
AnimatedOpacity
(
opacity:
_isWon
?
1.0
:
0.0
,
duration:
Duration
(
milliseconds:
2000
),
child:
Container
(
height:
40
,
child:
Align
(
child:
Text
(
"VICTOIRE !"
,
style:
victoryStyle
,),
alignment:
Alignment
.
center
,
))
),
isPlaying
?
Container
(
height:
40
,
child:
Align
(
child:
Text
(
"Compteur de coups: "
+
count
.
toString
(),
style:
textStyle
,),
alignment:
Alignment
.
center
,
...
...
@@ -151,8 +166,6 @@ class JeuDuTaquinState extends State<JeuDuTaquin> {
Container
(
height:
((
MediaQuery
.
of
(
context
).
size
.
height
)/
7
)-
appBar
.
preferredSize
.
height
,
width:
MediaQuery
.
of
(
context
).
size
.
width
-
90
,
child:
Slider
(
value:
_currentDifficultyValue
,
min:
20
,
max:
220
,
divisions:
10
,
activeColor:
Colors
.
blue
,
inactiveColor:
Colors
.
grey
,
label:
_currentDifficultyValue
.
round
().
toString
(),
onChanged:
(
double
value
)
{
setState
(()
{
...
...
@@ -188,10 +201,14 @@ class JeuDuTaquinState extends State<JeuDuTaquin> {
value:
_numbers
,
onChanged:
(
value
)
{
setState
(()
{
if
(!
isPlaying
)
_numbers
=
!
_numbers
;
});
if
(!
isPlaying
)
{
_numbers
=
!
_numbers
;
tiles
=
createTileWidgets
(
_currentSlideValue
,
emptyIndex
,
createListTile
(
_currentSlideValue
),
isPlaying
,
_numbers
);
}
}
);
}
),
),
),
]
):
new
Container
(),
...
...
@@ -202,11 +219,12 @@ class JeuDuTaquinState extends State<JeuDuTaquin> {
setState
(()
{
if
(!
isPlaying
){
//lancement du jeu
isPlaying
=
true
;
_isWon
=
false
;
tiles
=
createTileWidgets
(
_currentSlideValue
,
emptyIndex
,
createListTile
(
_currentSlideValue
),
isPlaying
,
_numbers
);
shuffle
(
_currentDifficultyValue
.
toInt
());
}
else
reset
();
}
);
}
);
},
tooltip:
'Play'
,
child:
new
Icon
(
isPlaying
?
Icons
.
cancel
:
Icons
.
play_arrow
),
...
...
@@ -243,7 +261,7 @@ class JeuDuTaquinState extends State<JeuDuTaquin> {
if
(
emptyIndex
>=
_currentSlideValue
)
tiles
[
emptyIndex
-
_currentSlideValue
.
toInt
()].
isUsable
=
true
;
//haut
if
(
emptyIndex
<(
_currentSlideValue
*(
_currentSlideValue
-
1
)))
tiles
[
emptyIndex
+
_currentSlideValue
.
toInt
()].
isUsable
=
true
;
//bas
if
((
emptyIndex
+
1
)%
_currentSlideValue
!=
0
)
tiles
[
emptyIndex
+
1
].
isUsable
=
true
;
//droite
if
(
emptyIndex
%
_currentSlideValue
!=
0
)
tiles
[
emptyIndex
-
1
].
isUsable
=
true
;
//gauche
if
(
emptyIndex
%
_currentSlideValue
!=
0
)
tiles
[
emptyIndex
-
1
].
isUsable
=
true
;
//gauche
});
}
...
...
@@ -296,4 +314,13 @@ class JeuDuTaquinState extends State<JeuDuTaquin> {
tiles
=
createTileWidgets
(
_currentSlideValue
,
emptyIndex
,
createListTile
(
_currentSlideValue
),
isPlaying
,
_numbers
);
}
bool
isWon
(){
bool
res
=
true
;
int
max
=
_currentSlideValue
.
toInt
()*
_currentSlideValue
.
toInt
();
for
(
int
i
=
0
;
i
<
max
;
i
++){
if
(
tiles
[
i
].
index
!=
i
)
res
=
false
;
}
return
res
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment