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
Show 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';
class
Exo7
extends
StatelessWidget
{
const
Exo7
({
super
.
key
});
@override
Widget
build
(
BuildContext
context
)
{
...
...
@@ -18,42 +19,48 @@ class Exo7 extends StatelessWidget {
style:
TextStyle
()
)
),
TextButton
(
Center
(
child:
TextButton
(
style:
TextButton
.
styleFrom
(
textStyle:
const
TextStyle
(
fontSize:
20
),
),
onPressed:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
const
SizeChoose
(
difficulty:
1
)),
MaterialPageRoute
(
builder:
(
context
)
=>
const
SizeChoose
(
difficulty:
10
)),
);
},
child:
const
Text
(
'Easy'
),
),
TextButton
(
),
Center
(
child:
TextButton
(
style:
TextButton
.
styleFrom
(
textStyle:
const
TextStyle
(
fontSize:
20
),
),
onPressed:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
const
SizeChoose
(
difficulty:
2
)),
MaterialPageRoute
(
builder:
(
context
)
=>
const
SizeChoose
(
difficulty:
20
)),
);
},
child:
const
Text
(
'Medium'
),
),
TextButton
(
),
Center
(
child:
TextButton
(
style:
TextButton
.
styleFrom
(
textStyle:
const
TextStyle
(
fontSize:
20
),
),
onPressed:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
const
SizeChoose
(
difficulty:
3
)),
MaterialPageRoute
(
builder:
(
context
)
=>
const
SizeChoose
(
difficulty:
30
)),
);
},
child:
const
Text
(
'Hard'
),
),
),
])
);
}
...
...
@@ -79,7 +86,8 @@ class SizeChoose extends StatelessWidget {
style:
TextStyle
()
)
),
TextButton
(
Center
(
child:
TextButton
(
style:
TextButton
.
styleFrom
(
textStyle:
const
TextStyle
(
fontSize:
20
),
),
...
...
@@ -91,7 +99,9 @@ class SizeChoose extends StatelessWidget {
},
child:
const
Text
(
'2 par 2'
),
),
TextButton
(
),
Center
(
child:
TextButton
(
style:
TextButton
.
styleFrom
(
textStyle:
const
TextStyle
(
fontSize:
20
),
),
...
...
@@ -103,7 +113,9 @@ class SizeChoose extends StatelessWidget {
},
child:
const
Text
(
'3 par 3'
),
),
TextButton
(
),
Center
(
child:
TextButton
(
style:
TextButton
.
styleFrom
(
textStyle:
const
TextStyle
(
fontSize:
20
),
),
...
...
@@ -115,7 +127,9 @@ class SizeChoose extends StatelessWidget {
},
child:
const
Text
(
'4 par 4'
),
),
TextButton
(
),
Center
(
child:
TextButton
(
style:
TextButton
.
styleFrom
(
textStyle:
const
TextStyle
(
fontSize:
20
),
),
...
...
@@ -126,6 +140,7 @@ class SizeChoose extends StatelessWidget {
);
},
child:
const
Text
(
'5 par 5'
),
),
)
])
);
...
...
tp2/lib/exo7_taquin.dart
View file @
85a332db
...
...
@@ -23,8 +23,8 @@ class _Taquin extends State<Taquin> {
List
<
Key
>
initialOrder
=
<
Key
>[];
double
?
size
=
300
;
int
emptyTileIndex
=
0
;
int
score
=
0
;
late
int
score
;
late
String
imageUrl
;
late
Image
image
;
late
int
colNb
;
...
...
@@ -41,6 +41,7 @@ class _Taquin extends State<Taquin> {
colNb
=
widget
.
colNb
;
difficulty
=
widget
.
difficulty
;
score
=
difficulty
*
colNb
;
tiles
=
buildImage
();
moveTiles
();
...
...
@@ -71,9 +72,9 @@ class _Taquin extends State<Taquin> {
onTap:
()
{
setState
(()
{
swapTiles
(
k
);
wi
n
();
isWo
n
();
if
(
isValidTile
(
tiles
.
indexOf
(
tiles
.
singleWhere
((
element
)
=>
element
.
key
==
k
)))){
score
++
;
score
--
;
}
});
}
...
...
@@ -90,7 +91,7 @@ class _Taquin extends State<Taquin> {
}
void
moveTiles
(){
for
(
int
i
=
0
;
i
<
math
.
pow
(
colNb
,
difficulty
+
1
)
;
i
++)
{
for
(
int
i
=
0
;
i
<
colNb
*
difficulty
;
i
++)
{
var
validTiles
=
getValidTiles
();
swapTiles
(
...
...
@@ -99,31 +100,78 @@ class _Taquin extends State<Taquin> {
}
}
void
_showWinDialog
(
BuildContext
context
){
void
_showWinDialog
(
BuildContext
context
,
int
winscore
){
showDialog
(
context:
context
,
builder:
(
BuildContext
context
){
return
AlertDialog
(
title:
const
Text
(
'Congratulations !'
),
content:
const
Text
(
'You won !'
),
actions:
<
Widget
>
[
content:
Column
(
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
(
onPressed:
()
{
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'
),
)
],
);
},
);
}
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
++){
if
(
tiles
[
i
].
key
!=
initialOrder
[
i
]){
...
...
@@ -132,7 +180,13 @@ class _Taquin extends State<Taquin> {
}
//print("It's a win");
_showWinDialog
(
context
);
stopwatch
=
const
Duration
();
stopwatchTimer
?.
cancel
();
stopwatchTimer
=
null
;
final
winscore
=
score
-
1
;
_showWinDialog
(
context
,
winscore
);
return
true
;
}
...
...
@@ -190,7 +244,7 @@ class _Taquin extends State<Taquin> {
timeWidget
=
stopwatchTimer
!=
null
?
Center
(
child:
Text
.
rich
(
TextSpan
(
text:
stopwatch
.
toString
(),
// default text style
text:
stopwatch
.
toString
()
.
substring
(
0
,
9
)
,
// default text style
style:
const
TextStyle
()
)
)
...
...
@@ -206,45 +260,54 @@ class _Taquin extends State<Taquin> {
'Score:
$score
'
,
style:
const
TextStyle
(
fontSize:
20
),
),
const
SizedBox
(
height:
5
),
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
[
ElevatedButton
(
onPressed:
()
{
setState
(()
{
stopwatch
=
const
Duration
();
stopwatchTimer
?.
cancel
();
stopwatchTimer
=
null
;
score
=
difficulty
*
colNb
;
colNb
=
widget
.
colNb
;
difficulty
=
widget
.
difficulty
;
image
=
Image
.
network
(
'https://picsum.photos/512'
);
image
.
image
.
evict
();
image
=
new
Image
.
network
(
'https://picsum.photos/512'
);
tiles
=
buildImage
();
moveTiles
();
});
// Add functionality for button 1
},
child:
const
Text
(
'Restart'
),
),
ElevatedButton
(
onPressed:
()
{
// Add functionality for button 1
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
(()
{
stopwatch
=
stopwatch
+
const
Duration
(
milliseconds:
100
)
;
stopwatch
=
stopwatch
+
d
;
});
});
});
},
child:
const
Text
(
'Stopwatch'
),
),
// TODO : PLUS DE BOUTO
],
),
const
SizedBox
(
height:
5
),
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
[
...
...
@@ -253,7 +316,7 @@ class _Taquin extends State<Taquin> {
getImage
().
then
((
_
)
{
setState
(()
{});
});
score
=
0
;
score
=
difficulty
*
colNb
;
},
child:
const
Text
(
'Image From Galeria'
),
),
...
...
@@ -262,7 +325,7 @@ class _Taquin extends State<Taquin> {
getImageFromCamera
().
then
((
_
)
{
setState
(()
{});
});
score
=
0
;
score
=
difficulty
*
colNb
;
},
child:
const
Text
(
'Image from camera'
),
),
...
...
@@ -271,11 +334,12 @@ class _Taquin extends State<Taquin> {
],
),
const
SizedBox
(
height:
5
),
Container
(
margin:
const
EdgeInsets
.
all
(
10.0
),
child:
SizedBox
(
height:
MediaQuery
.
of
(
context
).
size
.
height
*
0.
7
,
width:
MediaQuery
.
of
(
context
).
size
.
height
*
0.
7
,
height:
MediaQuery
.
of
(
context
).
size
.
height
*
0.
5
,
width:
MediaQuery
.
of
(
context
).
size
.
height
*
0.
5
,
child:
GridView
.
builder
(
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount
(
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