Commit 85a332db authored by Timothé KOBAK's avatar Timothé KOBAK

AHHHHHHHHHHHHHHHHHHHHHHHH

parent 8c7e59ae
......@@ -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'),
),
)
])
);
......
......@@ -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);
win();
isWon();
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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment