Commit d3085e87 authored by Benjamin LEROUX's avatar Benjamin LEROUX

pictures from databse

parent cbaaa2ff
...@@ -68,7 +68,7 @@ class _DisplayPlateauWidgetState extends State<DisplayPlateauWidget> { ...@@ -68,7 +68,7 @@ class _DisplayPlateauWidgetState extends State<DisplayPlateauWidget> {
for(double i=-1.0;i<=1.0;){ for(double i=-1.0;i<=1.0;){
for(double j=-1.0;j<=1.0;){ for(double j=-1.0;j<=1.0;){
res.add(new Tile(imageURL: 'https://picsum.photos/512/1024', alignment: Alignment(j, i),size: size)); res.add(new Tile( image: Image.network('https://picsum.photos/512/1024'), alignment: Alignment(j, i),size: size));
j+=(2/(size-1)); j+=(2/(size-1));
} }
i+=(2/(size-1)); i+=(2/(size-1));
......
...@@ -4,8 +4,9 @@ class Tile { ...@@ -4,8 +4,9 @@ class Tile {
String imageURL; String imageURL;
Alignment alignment; Alignment alignment;
double size; double size;
Image image;
Tile({this.imageURL, this.alignment,this.size}); Tile({this.image, this.alignment,this.size});
Widget croppedImageTile() { Widget croppedImageTile() {
return SizedBox.expand( return SizedBox.expand(
...@@ -17,7 +18,8 @@ class Tile { ...@@ -17,7 +18,8 @@ class Tile {
alignment: this.alignment, alignment: this.alignment,
widthFactor: 1/size, widthFactor: 1/size,
heightFactor: 1/size, heightFactor: 1/size,
child: Image.network(this.imageURL), child: image,
//Image.network(this.imageURL),
), ),
), ),
), ),
...@@ -27,7 +29,7 @@ class Tile { ...@@ -27,7 +29,7 @@ class Tile {
} }
Tile tile = new Tile( Tile tile = new Tile(
imageURL: 'https://picsum.photos/512/1024', alignment: Alignment(0, 0),size: 4); image: Image.network('https://picsum.photos/512/1024'), alignment: Alignment(0, 0),size: 4);
class DisplayTileWidget extends StatelessWidget { class DisplayTileWidget extends StatelessWidget {
@override @override
......
...@@ -2,12 +2,12 @@ import 'package:flutter/cupertino.dart'; ...@@ -2,12 +2,12 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'dart:math'; import 'dart:math';
class exo2 extends StatefulWidget{ class Exo2 extends StatefulWidget{
@override @override
_exo2State createState() => _exo2State(); _Exo2State createState() => _Exo2State();
} }
class _exo2State extends State<exo2> { class _Exo2State extends State<Exo2> {
var appBar= AppBar(title: Text('Exo 2'),); var appBar= AppBar(title: Text('Exo 2'),);
double _currentSliderValueX = 0.0; double _currentSliderValueX = 0.0;
......
...@@ -7,6 +7,7 @@ class Tile { ...@@ -7,6 +7,7 @@ class Tile {
Tile(this.index,this.color); Tile(this.index,this.color);
} }
// ignore: must_be_immutable
class TileWidget extends StatelessWidget { class TileWidget extends StatelessWidget {
Tile tile; Tile tile;
bool isUsable=false; bool isUsable=false;
......
...@@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; ...@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'Tile.dart'; import 'Tile.dart';
import 'dart:math'; import 'dart:math';
// ignore: must_be_immutable
class TileWidget extends StatelessWidget { class TileWidget extends StatelessWidget {
Tile tile; Tile tile;
bool isUsable=false; bool isUsable=false;
...@@ -27,6 +28,7 @@ class TileWidget extends StatelessWidget { ...@@ -27,6 +28,7 @@ class TileWidget extends StatelessWidget {
} }
} }
//Decoration des cases cliquables
BoxDecoration myBoxDecoration(bool isUsable) { BoxDecoration myBoxDecoration(bool isUsable) {
BoxDecoration res=BoxDecoration(); BoxDecoration res=BoxDecoration();
if(isUsable){ if(isUsable){
...@@ -40,12 +42,12 @@ BoxDecoration myBoxDecoration(bool isUsable) { ...@@ -40,12 +42,12 @@ BoxDecoration myBoxDecoration(bool isUsable) {
return res; return res;
} }
List<Tile> createListTile(double size){ List<Tile> createListTile(double size, Image image){
List<Tile> res=<Tile>[]; List<Tile> res=<Tile>[];
for(double i=-1.0;i<=1.0;){ for(double i=-1.0;i<=1.0;){
for(double j=-1.0;j<=1.0;){ for(double j=-1.0;j<=1.0;){
res.add(new Tile(imageURL: 'https://picsum.photos/512/512', alignment: Alignment(j, i),size: size)); res.add(new Tile(image: image, alignment: Alignment(j, i),size: size));
j+=(2/(size-1)); j+=(2/(size-1));
} }
i+=(2/(size-1)); i+=(2/(size-1));
...@@ -65,7 +67,8 @@ List<TileWidget>createTileWidgets(double slide, int emptyIndex, List<Tile> listT ...@@ -65,7 +67,8 @@ List<TileWidget>createTileWidgets(double slide, int emptyIndex, List<Tile> listT
int ligne=slide.toInt(); int ligne=slide.toInt();
for(int i=0;i<max;i++){ for(int i=0;i<max;i++){
if(i==emptyIndex && play){ 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", tiles.add(TileWidget(Tile(
image: Image.network("https://upload.wikimedia.org/wikipedia/commons/thumb/6/6e/Fond_blanc.svg/1200px-Fond_blanc.svg.png"),
alignment: Alignment(-1,-1),size: slide),false,"",i)); alignment: Alignment(-1,-1),size: slide),false,"",i));
}else if(((i==emptyIndex+1 && i%ligne!=0) || }else if(((i==emptyIndex+1 && i%ligne!=0) ||
i==emptyIndex+ligne || i==emptyIndex+ligne ||
...@@ -86,10 +89,12 @@ class JeuDuTaquin extends StatefulWidget { ...@@ -86,10 +89,12 @@ class JeuDuTaquin extends StatefulWidget {
} }
class JeuDuTaquinState extends State<JeuDuTaquin> { class JeuDuTaquinState extends State<JeuDuTaquin> {
TextStyle textStyle = TextStyle(fontSize: 16, fontWeight: FontWeight.bold,); final TextStyle textStyle = TextStyle(fontSize: 16, fontWeight: FontWeight.bold,);
TextStyle victoryStyle = TextStyle(fontSize: 26, fontWeight: FontWeight.bold,color: Colors.red); final TextStyle victoryStyle = TextStyle(fontSize: 26, fontWeight: FontWeight.bold,color: Colors.red);
var appBar= AppBar(title: Text('Jeu Du Taquin'),); final appBar= AppBar(title: Text('Jeu Du Taquin'),);
List<TileWidget> tiles=createTileWidgets(3, 4,createListTile(3),false,false); String imageSelect ="Image Aléatoire";
Image image = Image.network('https://picsum.photos/512/512');
List<TileWidget> tiles=createTileWidgets(3, 4,createListTile(3,Image.network('https://picsum.photos/512/512')),false,false);
double _currentSlideValue=3; double _currentSlideValue=3;
double _currentDifficultyValue=100; double _currentDifficultyValue=100;
bool isPlaying=false; bool isPlaying=false;
...@@ -145,10 +150,40 @@ class JeuDuTaquinState extends State<JeuDuTaquin> { ...@@ -145,10 +150,40 @@ class JeuDuTaquinState extends State<JeuDuTaquin> {
alignment: Alignment.center, alignment: Alignment.center,
)) ))
), ),
isPlaying? Container(height: 40,child:Align( !isPlaying? Row(children: <Widget>[
child:Text("Compteur de coups: "+count.toString(),style: textStyle,), Container(width: 90,child:Text("Image:", style: textStyle,textAlign: TextAlign.center,),padding: EdgeInsets.fromLTRB(8, 0, 0, 0),),
alignment: Alignment.center, Container(height:((MediaQuery.of(context).size.height)/7)-appBar.preferredSize.height,width: MediaQuery.of(context).size.width-115,child:
)): new Container(), DropdownButton<String>(
value: imageSelect,
icon: Icon(Icons.arrow_circle_down_outlined, color: Colors.lightBlueAccent,),
iconSize: 20,
elevation: 16,
style: TextStyle(color: Colors.blueGrey,fontSize: 18),
underline: Container(
height: 2,
color: Colors.blue,
),
onChanged: (String newValue) {
setState(() {
imageSelect = newValue;
if(imageSelect=="Image Aléatoire") {
image=Image.network('https://picsum.photos/512/512');
}else image=Image.asset("assets/"+imageSelect+".jpg");
tiles=createTileWidgets(_currentSlideValue,emptyIndex,createListTile(_currentSlideValue,image),isPlaying,_numbers);
});
},
items: <String>['Image Aléatoire', 'Montgolfières','Plage','Ponton','Route', 'Ville',]
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: SizedBox(width: MediaQuery.of(context).size.width-135,child:Text(value,textAlign: TextAlign.center,)),
);
}).toList(),
)
),
]
): new Container(),
isPlaying? Align( isPlaying? Align(
child:RaisedButton( child:RaisedButton(
onPressed: () { onPressed: () {
...@@ -187,7 +222,7 @@ class JeuDuTaquinState extends State<JeuDuTaquin> { ...@@ -187,7 +222,7 @@ class JeuDuTaquinState extends State<JeuDuTaquin> {
_currentSlideValue = value; _currentSlideValue = value;
if(_currentSlideValue%2==1)emptyIndex=((_currentSlideValue*_currentSlideValue)-1)~/2; //si impair alors milieu if(_currentSlideValue%2==1)emptyIndex=((_currentSlideValue*_currentSlideValue)-1)~/2; //si impair alors milieu
else emptyIndex=random.nextInt((_currentSlideValue*_currentSlideValue).toInt()); //sinon aleatoire else emptyIndex=random.nextInt((_currentSlideValue*_currentSlideValue).toInt()); //sinon aleatoire
tiles=createTileWidgets(_currentSlideValue,emptyIndex,createListTile(_currentSlideValue),isPlaying,_numbers); tiles=createTileWidgets(_currentSlideValue,emptyIndex,createListTile(_currentSlideValue,image),isPlaying,_numbers);
} }
}); });
}), }),
...@@ -197,13 +232,13 @@ class JeuDuTaquinState extends State<JeuDuTaquin> { ...@@ -197,13 +232,13 @@ class JeuDuTaquinState extends State<JeuDuTaquin> {
!isPlaying? Row(mainAxisSize: MainAxisSize.min, !isPlaying? Row(mainAxisSize: MainAxisSize.min,
children: <Widget>[ children: <Widget>[
Container(width: 100,child:Text('Afficher les nombres:', style: textStyle, textAlign: TextAlign.center,),padding: EdgeInsets.fromLTRB(8, 0, 0, 0),), Container(width: 100,child:Text('Afficher les nombres:', style: textStyle, textAlign: TextAlign.center,),padding: EdgeInsets.fromLTRB(8, 0, 0, 0),),
Container(height:((MediaQuery.of(context).size.height)/7)-appBar.preferredSize.height,width: 100,child: Checkbox( Container(height:((MediaQuery.of(context).size.height)/7)-appBar.preferredSize.height,width: 70,child: Switch(
value: _numbers, value: _numbers,
onChanged: (value) { onChanged: (value) {
setState(() { setState(() {
if(!isPlaying) { if(!isPlaying) {
_numbers = !_numbers; _numbers = !_numbers;
tiles = createTileWidgets(_currentSlideValue, emptyIndex, createListTile(_currentSlideValue), isPlaying, _numbers); tiles = createTileWidgets(_currentSlideValue, emptyIndex, createListTile(_currentSlideValue,image), isPlaying, _numbers);
} }
} }
); );
...@@ -220,9 +255,9 @@ class JeuDuTaquinState extends State<JeuDuTaquin> { ...@@ -220,9 +255,9 @@ class JeuDuTaquinState extends State<JeuDuTaquin> {
if(!isPlaying){ //lancement du jeu if(!isPlaying){ //lancement du jeu
isPlaying=true; isPlaying=true;
_isWon=false; _isWon=false;
tiles=createTileWidgets(_currentSlideValue,emptyIndex,createListTile(_currentSlideValue),isPlaying,_numbers); tiles=createTileWidgets(_currentSlideValue,emptyIndex,createListTile(_currentSlideValue,image),isPlaying,_numbers);
shuffle(_currentDifficultyValue.toInt()); shuffle(_currentDifficultyValue.toInt());
}else reset(); }else reset();
} }
); );
}, },
...@@ -279,7 +314,7 @@ class JeuDuTaquinState extends State<JeuDuTaquin> { ...@@ -279,7 +314,7 @@ class JeuDuTaquinState extends State<JeuDuTaquin> {
case 1: { case 1: {
if((emptyIndex+1)%_currentSlideValue!=0) { if((emptyIndex+1)%_currentSlideValue!=0) {
swapTiles(emptyIndex + 1, emptyIndex);; swapTiles(emptyIndex + 1, emptyIndex);
} }
else i--; else i--;
} }
...@@ -311,7 +346,7 @@ class JeuDuTaquinState extends State<JeuDuTaquin> { ...@@ -311,7 +346,7 @@ class JeuDuTaquinState extends State<JeuDuTaquin> {
isPlaying=false; isPlaying=false;
count=0; count=0;
previousEmptyIndex=-1; previousEmptyIndex=-1;
tiles=createTileWidgets(_currentSlideValue,emptyIndex,createListTile(_currentSlideValue),isPlaying,_numbers); tiles=createTileWidgets(_currentSlideValue,emptyIndex,createListTile(_currentSlideValue,image),isPlaying,_numbers);
} }
bool isWon(){ bool isWon(){
......
...@@ -65,7 +65,7 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -65,7 +65,7 @@ class _MyHomePageState extends State<MyHomePage> {
trailing: Icon(Icons.play_arrow), trailing: Icon(Icons.play_arrow),
title: Text('Exercice 2'), title: Text('Exercice 2'),
subtitle: Text('Transformer une image'), subtitle: Text('Transformer une image'),
onTap:() {Navigator.push(context, MaterialPageRoute(builder: (context) =>exo2()));}, onTap:() {Navigator.push(context, MaterialPageRoute(builder: (context) =>Exo2()));},
), ),
], ],
), ),
......
...@@ -38,6 +38,8 @@ dev_dependencies: ...@@ -38,6 +38,8 @@ dev_dependencies:
# The following section is specific to Flutter. # The following section is specific to Flutter.
flutter: flutter:
assets:
- assets/
# The following line ensures that the Material Icons font is # The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in # included with your application, so that you can use the icons in
......
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