Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
amse
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
Matis SPINELLI
amse
Commits
85a332db
Commit
85a332db
authored
Feb 27, 2024
by
Timothé KOBAK
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AHHHHHHHHHHHHHHHHHHHHHHHH
parent
8c7e59ae
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
184 additions
and
105 deletions
+184
-105
exo7.dart
tp2/lib/exo7.dart
+85
-70
exo7_taquin.dart
tp2/lib/exo7_taquin.dart
+99
-35
No files found.
tp2/lib/exo7.dart
View file @
85a332db
...
@@ -3,6 +3,7 @@ import 'exo7_taquin.dart';
...
@@ -3,6 +3,7 @@ import 'exo7_taquin.dart';
class
Exo7
extends
StatelessWidget
{
class
Exo7
extends
StatelessWidget
{
const
Exo7
({
super
.
key
});
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
...
@@ -18,41 +19,47 @@ class Exo7 extends StatelessWidget {
...
@@ -18,41 +19,47 @@ class Exo7 extends StatelessWidget {
style:
TextStyle
()
style:
TextStyle
()
)
)
),
),
TextButton
(
Center
(
style:
TextButton
.
styleFrom
(
child:
TextButton
(
textStyle:
const
TextStyle
(
fontSize:
20
),
style:
TextButton
.
styleFrom
(
textStyle:
const
TextStyle
(
fontSize:
20
),
),
onPressed:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
const
SizeChoose
(
difficulty:
10
)),
);
},
child:
const
Text
(
'Easy'
),
),
),
onPressed:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
const
SizeChoose
(
difficulty:
1
)),
);
},
child:
const
Text
(
'Easy'
),
),
),
TextButton
(
Center
(
style:
TextButton
.
styleFrom
(
child:
TextButton
(
textStyle:
const
TextStyle
(
fontSize:
20
),
style:
TextButton
.
styleFrom
(
textStyle:
const
TextStyle
(
fontSize:
20
),
),
onPressed:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
const
SizeChoose
(
difficulty:
20
)),
);
},
child:
const
Text
(
'Medium'
),
),
),
onPressed:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
const
SizeChoose
(
difficulty:
2
)),
);
},
child:
const
Text
(
'Medium'
),
),
),
TextButton
(
Center
(
style:
TextButton
.
styleFrom
(
child:
TextButton
(
textStyle:
const
TextStyle
(
fontSize:
20
),
style:
TextButton
.
styleFrom
(
textStyle:
const
TextStyle
(
fontSize:
20
),
),
onPressed:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
const
SizeChoose
(
difficulty:
30
)),
);
},
child:
const
Text
(
'Hard'
),
),
),
onPressed:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
const
SizeChoose
(
difficulty:
3
)),
);
},
child:
const
Text
(
'Hard'
),
),
),
])
])
);
);
...
@@ -79,53 +86,61 @@ class SizeChoose extends StatelessWidget {
...
@@ -79,53 +86,61 @@ class SizeChoose extends StatelessWidget {
style:
TextStyle
()
style:
TextStyle
()
)
)
),
),
TextButton
(
Center
(
style:
TextButton
.
styleFrom
(
child:
TextButton
(
textStyle:
const
TextStyle
(
fontSize:
20
),
style:
TextButton
.
styleFrom
(
textStyle:
const
TextStyle
(
fontSize:
20
),
),
onPressed:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
Taquin
(
difficulty:
difficulty
,
colNb:
2
)),
);
},
child:
const
Text
(
'2 par 2'
),
),
),
onPressed:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
Taquin
(
difficulty:
difficulty
,
colNb:
2
)),
);
},
child:
const
Text
(
'2 par 2'
),
),
),
TextButton
(
Center
(
style:
TextButton
.
styleFrom
(
child:
TextButton
(
textStyle:
const
TextStyle
(
fontSize:
20
),
style:
TextButton
.
styleFrom
(
textStyle:
const
TextStyle
(
fontSize:
20
),
),
onPressed:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
Taquin
(
difficulty:
difficulty
,
colNb:
3
)),
);
},
child:
const
Text
(
'3 par 3'
),
),
),
onPressed:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
Taquin
(
difficulty:
difficulty
,
colNb:
3
)),
);
},
child:
const
Text
(
'3 par 3'
),
),
),
TextButton
(
Center
(
style:
TextButton
.
styleFrom
(
child:
TextButton
(
textStyle:
const
TextStyle
(
fontSize:
20
),
style:
TextButton
.
styleFrom
(
textStyle:
const
TextStyle
(
fontSize:
20
),
),
onPressed:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
Taquin
(
difficulty:
difficulty
,
colNb:
4
)),
);
},
child:
const
Text
(
'4 par 4'
),
),
),
onPressed:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
Taquin
(
difficulty:
difficulty
,
colNb:
4
)),
);
},
child:
const
Text
(
'4 par 4'
),
),
),
TextButton
(
Center
(
style:
TextButton
.
styleFrom
(
child:
TextButton
(
textStyle:
const
TextStyle
(
fontSize:
20
),
style:
TextButton
.
styleFrom
(
textStyle:
const
TextStyle
(
fontSize:
20
),
),
onPressed:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
Taquin
(
difficulty:
difficulty
,
colNb:
5
)),
);
},
child:
const
Text
(
'5 par 5'
),
),
),
onPressed:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
Taquin
(
difficulty:
difficulty
,
colNb:
5
)),
);
},
child:
const
Text
(
'5 par 5'
),
)
)
])
])
);
);
...
...
tp2/lib/exo7_taquin.dart
View file @
85a332db
...
@@ -23,8 +23,8 @@ class _Taquin extends State<Taquin> {
...
@@ -23,8 +23,8 @@ class _Taquin extends State<Taquin> {
List
<
Key
>
initialOrder
=
<
Key
>[];
List
<
Key
>
initialOrder
=
<
Key
>[];
double
?
size
=
300
;
double
?
size
=
300
;
int
emptyTileIndex
=
0
;
int
emptyTileIndex
=
0
;
int
score
=
0
;
late
int
score
;
late
String
imageUrl
;
late
String
imageUrl
;
late
Image
image
;
late
Image
image
;
late
int
colNb
;
late
int
colNb
;
...
@@ -41,6 +41,7 @@ class _Taquin extends State<Taquin> {
...
@@ -41,6 +41,7 @@ class _Taquin extends State<Taquin> {
colNb
=
widget
.
colNb
;
colNb
=
widget
.
colNb
;
difficulty
=
widget
.
difficulty
;
difficulty
=
widget
.
difficulty
;
score
=
difficulty
*
colNb
;
tiles
=
buildImage
();
tiles
=
buildImage
();
moveTiles
();
moveTiles
();
...
@@ -71,9 +72,9 @@ class _Taquin extends State<Taquin> {
...
@@ -71,9 +72,9 @@ class _Taquin extends State<Taquin> {
onTap:
()
{
onTap:
()
{
setState
(()
{
setState
(()
{
swapTiles
(
k
);
swapTiles
(
k
);
wi
n
();
isWo
n
();
if
(
isValidTile
(
tiles
.
indexOf
(
tiles
.
singleWhere
((
element
)
=>
element
.
key
==
k
)))){
if
(
isValidTile
(
tiles
.
indexOf
(
tiles
.
singleWhere
((
element
)
=>
element
.
key
==
k
)))){
score
++
;
score
--
;
}
}
});
});
}
}
...
@@ -90,7 +91,7 @@ class _Taquin extends State<Taquin> {
...
@@ -90,7 +91,7 @@ class _Taquin extends State<Taquin> {
}
}
void
moveTiles
(){
void
moveTiles
(){
for
(
int
i
=
0
;
i
<
math
.
pow
(
colNb
,
difficulty
+
1
)
;
i
++)
{
for
(
int
i
=
0
;
i
<
colNb
*
difficulty
;
i
++)
{
var
validTiles
=
getValidTiles
();
var
validTiles
=
getValidTiles
();
swapTiles
(
swapTiles
(
...
@@ -99,31 +100,78 @@ class _Taquin extends State<Taquin> {
...
@@ -99,31 +100,78 @@ class _Taquin extends State<Taquin> {
}
}
}
}
void
_showWinDialog
(
BuildContext
context
){
void
_showWinDialog
(
BuildContext
context
,
int
winscore
){
showDialog
(
showDialog
(
context:
context
,
context:
context
,
builder:
(
BuildContext
context
){
builder:
(
BuildContext
context
){
return
AlertDialog
(
return
AlertDialog
(
title:
const
Text
(
'Congratulations !'
),
title:
const
Text
(
'Congratulations !'
),
content:
const
Text
(
'You won !'
),
content:
Column
(
actions:
<
Widget
>
[
mainAxisSize:
MainAxisSize
.
min
,
children:
<
Widget
>[
Text
(
'You won ! With a score of
$winscore
'
),
SizedBox
(
height:
20
),
// Add some space between text and image
image
,
],
),
actions:
<
Widget
>[
TextButton
(
TextButton
(
onPressed:
()
{
onPressed:
()
{
Navigator
.
pop
(
context
);
Navigator
.
pop
(
context
);
},
},
child:
const
Text
(
'Close'
),
),
TextButton
(
onPressed:
()
{
setState
(()
{
stopwatch
=
const
Duration
();
stopwatchTimer
?.
cancel
();
stopwatchTimer
=
null
;
score
=
difficulty
*
colNb
;
image
.
image
.
evict
();
image
=
new
Image
.
network
(
'https://picsum.photos/512'
);
tiles
=
buildImage
();
moveTiles
();
});
Navigator
.
pop
(
context
);
},
child:
const
Text
(
'Restart'
),
)
],
);
},
);
}
child:
const
Text
(
'Close'
),
void
_showHintDialog
(
BuildContext
context
){
showDialog
(
context:
context
,
builder:
(
BuildContext
context
){
return
AlertDialog
(
title:
const
Text
(
'Good luck !'
),
content:
Column
(
mainAxisSize:
MainAxisSize
.
min
,
children:
<
Widget
>[
Text
(
'This is the image you are trying to recompose :'
),
SizedBox
(
height:
20
),
// Add some space between text and image
image
,
],
),
),
actions:
<
Widget
>[
TextButton
(
onPressed:
()
{
Navigator
.
pop
(
context
);
},
child:
const
Text
(
'Close'
),
),
],
],
);
);
}
}
,
);
);
}
}
bool
win
(){
bool
isWon
(){
for
(
int
i
=
1
;
i
<
tiles
.
length
;
i
++){
for
(
int
i
=
1
;
i
<
tiles
.
length
;
i
++){
if
(
tiles
[
i
].
key
!=
initialOrder
[
i
]){
if
(
tiles
[
i
].
key
!=
initialOrder
[
i
]){
...
@@ -132,7 +180,13 @@ class _Taquin extends State<Taquin> {
...
@@ -132,7 +180,13 @@ class _Taquin extends State<Taquin> {
}
}
//print("It's a win");
//print("It's a win");
_showWinDialog
(
context
);
stopwatch
=
const
Duration
();
stopwatchTimer
?.
cancel
();
stopwatchTimer
=
null
;
final
winscore
=
score
-
1
;
_showWinDialog
(
context
,
winscore
);
return
true
;
return
true
;
}
}
...
@@ -190,7 +244,7 @@ class _Taquin extends State<Taquin> {
...
@@ -190,7 +244,7 @@ class _Taquin extends State<Taquin> {
timeWidget
=
stopwatchTimer
!=
null
?
Center
(
timeWidget
=
stopwatchTimer
!=
null
?
Center
(
child:
Text
.
rich
(
child:
Text
.
rich
(
TextSpan
(
TextSpan
(
text:
stopwatch
.
toString
(),
// default text style
text:
stopwatch
.
toString
()
.
substring
(
0
,
9
)
,
// default text style
style:
const
TextStyle
()
style:
const
TextStyle
()
)
)
)
)
...
@@ -206,45 +260,54 @@ class _Taquin extends State<Taquin> {
...
@@ -206,45 +260,54 @@ class _Taquin extends State<Taquin> {
'Score:
$score
'
,
'Score:
$score
'
,
style:
const
TextStyle
(
fontSize:
20
),
style:
const
TextStyle
(
fontSize:
20
),
),
),
const
SizedBox
(
height:
5
),
Row
(
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
[
children:
[
ElevatedButton
(
ElevatedButton
(
onPressed:
()
{
onPressed:
()
{
setState
(()
{
setState
(()
{
stopwatch
=
const
Duration
();
stopwatchTimer
?.
cancel
();
stopwatchTimer
=
null
;
colNb
=
widget
.
colNb
;
score
=
difficulty
*
colNb
;
difficulty
=
widget
.
difficulty
;
image
=
Image
.
network
(
'https://picsum.photos/512'
);
image
.
image
.
evict
();
image
=
new
Image
.
network
(
'https://picsum.photos/512'
);
tiles
=
buildImage
();
tiles
=
buildImage
();
moveTiles
();
moveTiles
();
});
});
// Add functionality for button 1
},
},
child:
const
Text
(
'Restart'
),
child:
const
Text
(
'Restart'
),
),
),
ElevatedButton
(
ElevatedButton
(
onPressed:
()
{
onPressed:
()
{
// Add functionality for button 1
setState
(()
{
setState
(()
{
stopwatchTimer
=
Timer
.
periodic
(
const
Duration
(
milliseconds:
100
),
(
timer
)
{
_showHintDialog
(
context
);
});
},
child:
const
Text
(
'HINT'
),
),
ElevatedButton
(
onPressed:
()
{
const
d
=
Duration
(
milliseconds:
100
);
setState
(()
{
stopwatchTimer
=
Timer
.
periodic
(
d
,
(
timer
)
{
setState
(()
{
setState
(()
{
stopwatch
=
stopwatch
+
const
Duration
(
milliseconds:
100
)
;
stopwatch
=
stopwatch
+
d
;
});
});
});
});
});
});
},
},
child:
const
Text
(
'Stopwatch'
),
child:
const
Text
(
'Stopwatch'
),
),
),
// TODO : PLUS DE BOUTO
],
],
),
),
const
SizedBox
(
height:
5
),
Row
(
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
[
children:
[
...
@@ -253,7 +316,7 @@ class _Taquin extends State<Taquin> {
...
@@ -253,7 +316,7 @@ class _Taquin extends State<Taquin> {
getImage
().
then
((
_
)
{
getImage
().
then
((
_
)
{
setState
(()
{});
setState
(()
{});
});
});
score
=
0
;
score
=
difficulty
*
colNb
;
},
},
child:
const
Text
(
'Image From Galeria'
),
child:
const
Text
(
'Image From Galeria'
),
),
),
...
@@ -262,7 +325,7 @@ class _Taquin extends State<Taquin> {
...
@@ -262,7 +325,7 @@ class _Taquin extends State<Taquin> {
getImageFromCamera
().
then
((
_
)
{
getImageFromCamera
().
then
((
_
)
{
setState
(()
{});
setState
(()
{});
});
});
score
=
0
;
score
=
difficulty
*
colNb
;
},
},
child:
const
Text
(
'Image from camera'
),
child:
const
Text
(
'Image from camera'
),
),
),
...
@@ -271,11 +334,12 @@ class _Taquin extends State<Taquin> {
...
@@ -271,11 +334,12 @@ class _Taquin extends State<Taquin> {
],
],
),
),
const
SizedBox
(
height:
5
),
Container
(
Container
(
margin:
const
EdgeInsets
.
all
(
10.0
),
margin:
const
EdgeInsets
.
all
(
10.0
),
child:
SizedBox
(
child:
SizedBox
(
height:
MediaQuery
.
of
(
context
).
size
.
height
*
0.
7
,
height:
MediaQuery
.
of
(
context
).
size
.
height
*
0.
5
,
width:
MediaQuery
.
of
(
context
).
size
.
height
*
0.
7
,
width:
MediaQuery
.
of
(
context
).
size
.
height
*
0.
5
,
child:
GridView
.
builder
(
child:
GridView
.
builder
(
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount
(
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount
(
crossAxisCount:
colNb
,
crossAxisCount:
colNb
,
...
...
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