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,41 +19,47 @@ class Exo7 extends StatelessWidget {
style: TextStyle()
)
),
TextButton(
style: TextButton.styleFrom(
textStyle: const TextStyle(fontSize: 20),
Center(
child: TextButton(
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(
style: TextButton.styleFrom(
textStyle: const TextStyle(fontSize: 20),
Center(
child: TextButton(
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(
style: TextButton.styleFrom(
textStyle: const TextStyle(fontSize: 20),
Center(
child: TextButton(
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 {
style: TextStyle()
)
),
TextButton(
style: TextButton.styleFrom(
textStyle: const TextStyle(fontSize: 20),
Center(
child: TextButton(
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(
style: TextButton.styleFrom(
textStyle: const TextStyle(fontSize: 20),
Center(
child: TextButton(
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(
style: TextButton.styleFrom(
textStyle: const TextStyle(fontSize: 20),
Center(
child: TextButton(
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(
style: TextButton.styleFrom(
textStyle: const TextStyle(fontSize: 20),
Center(
child: TextButton(
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'),
)
])
);
......
......@@ -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);
},
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'),
)
],
);
},
);
}
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++){
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(() {
colNb = widget.colNb;
difficulty = widget.difficulty;
stopwatch = const Duration();
stopwatchTimer?.cancel();
stopwatchTimer = null;
score = difficulty * colNb;
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