Commit d3085e87 authored by Benjamin LEROUX's avatar Benjamin LEROUX

pictures from databse

parent cbaaa2ff
......@@ -68,7 +68,7 @@ class _DisplayPlateauWidgetState extends State<DisplayPlateauWidget> {
for(double i=-1.0;i<=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));
}
i+=(2/(size-1));
......
......@@ -4,8 +4,9 @@ class Tile {
String imageURL;
Alignment alignment;
double size;
Image image;
Tile({this.imageURL, this.alignment,this.size});
Tile({this.image, this.alignment,this.size});
Widget croppedImageTile() {
return SizedBox.expand(
......@@ -17,7 +18,8 @@ class Tile {
alignment: this.alignment,
widthFactor: 1/size,
heightFactor: 1/size,
child: Image.network(this.imageURL),
child: image,
//Image.network(this.imageURL),
),
),
),
......@@ -27,7 +29,7 @@ class 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 {
@override
......
......@@ -2,12 +2,12 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'dart:math';
class exo2 extends StatefulWidget{
class Exo2 extends StatefulWidget{
@override
_exo2State createState() => _exo2State();
_Exo2State createState() => _Exo2State();
}
class _exo2State extends State<exo2> {
class _Exo2State extends State<Exo2> {
var appBar= AppBar(title: Text('Exo 2'),);
double _currentSliderValueX = 0.0;
......
......@@ -7,6 +7,7 @@ class Tile {
Tile(this.index,this.color);
}
// ignore: must_be_immutable
class TileWidget extends StatelessWidget {
Tile tile;
bool isUsable=false;
......
......@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'Tile.dart';
import 'dart:math';
// ignore: must_be_immutable
class TileWidget extends StatelessWidget {
Tile tile;
bool isUsable=false;
......@@ -27,6 +28,7 @@ class TileWidget extends StatelessWidget {
}
}
//Decoration des cases cliquables
BoxDecoration myBoxDecoration(bool isUsable) {
BoxDecoration res=BoxDecoration();
if(isUsable){
......@@ -40,12 +42,12 @@ BoxDecoration myBoxDecoration(bool isUsable) {
return res;
}
List<Tile> createListTile(double size){
List<Tile> createListTile(double size, Image image){
List<Tile> res=<Tile>[];
for(double i=-1.0;i<=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));
}
i+=(2/(size-1));
......@@ -65,7 +67,8 @@ List<TileWidget>createTileWidgets(double slide, int emptyIndex, List<Tile> listT
int ligne=slide.toInt();
for(int i=0;i<max;i++){
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));
}else if(((i==emptyIndex+1 && i%ligne!=0) ||
i==emptyIndex+ligne ||
......@@ -86,10 +89,12 @@ class JeuDuTaquin extends StatefulWidget {
}
class JeuDuTaquinState extends State<JeuDuTaquin> {
TextStyle textStyle = TextStyle(fontSize: 16, fontWeight: FontWeight.bold,);
TextStyle victoryStyle = TextStyle(fontSize: 26, fontWeight: FontWeight.bold,color: Colors.red);
var appBar= AppBar(title: Text('Jeu Du Taquin'),);
List<TileWidget> tiles=createTileWidgets(3, 4,createListTile(3),false,false);
final TextStyle textStyle = TextStyle(fontSize: 16, fontWeight: FontWeight.bold,);
final TextStyle victoryStyle = TextStyle(fontSize: 26, fontWeight: FontWeight.bold,color: Colors.red);
final appBar= AppBar(title: Text('Jeu Du Taquin'),);
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 _currentDifficultyValue=100;
bool isPlaying=false;
......@@ -145,10 +150,40 @@ class JeuDuTaquinState extends State<JeuDuTaquin> {
alignment: Alignment.center,
))
),
isPlaying? Container(height: 40,child:Align(
child:Text("Compteur de coups: "+count.toString(),style: textStyle,),
alignment: Alignment.center,
)): new Container(),
!isPlaying? Row(children: <Widget>[
Container(width: 90,child:Text("Image:", style: textStyle,textAlign: TextAlign.center,),padding: EdgeInsets.fromLTRB(8, 0, 0, 0),),
Container(height:((MediaQuery.of(context).size.height)/7)-appBar.preferredSize.height,width: MediaQuery.of(context).size.width-115,child:
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(
child:RaisedButton(
onPressed: () {
......@@ -187,7 +222,7 @@ class JeuDuTaquinState extends State<JeuDuTaquin> {
_currentSlideValue = value;
if(_currentSlideValue%2==1)emptyIndex=((_currentSlideValue*_currentSlideValue)-1)~/2; //si impair alors milieu
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> {
!isPlaying? Row(mainAxisSize: MainAxisSize.min,
children: <Widget>[
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,
onChanged: (value) {
setState(() {
if(!isPlaying) {
_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> {
if(!isPlaying){ //lancement du jeu
isPlaying=true;
_isWon=false;
tiles=createTileWidgets(_currentSlideValue,emptyIndex,createListTile(_currentSlideValue),isPlaying,_numbers);
tiles=createTileWidgets(_currentSlideValue,emptyIndex,createListTile(_currentSlideValue,image),isPlaying,_numbers);
shuffle(_currentDifficultyValue.toInt());
}else reset();
}else reset();
}
);
},
......@@ -279,7 +314,7 @@ class JeuDuTaquinState extends State<JeuDuTaquin> {
case 1: {
if((emptyIndex+1)%_currentSlideValue!=0) {
swapTiles(emptyIndex + 1, emptyIndex);;
swapTiles(emptyIndex + 1, emptyIndex);
}
else i--;
}
......@@ -311,7 +346,7 @@ class JeuDuTaquinState extends State<JeuDuTaquin> {
isPlaying=false;
count=0;
previousEmptyIndex=-1;
tiles=createTileWidgets(_currentSlideValue,emptyIndex,createListTile(_currentSlideValue),isPlaying,_numbers);
tiles=createTileWidgets(_currentSlideValue,emptyIndex,createListTile(_currentSlideValue,image),isPlaying,_numbers);
}
bool isWon(){
......
......@@ -65,7 +65,7 @@ class _MyHomePageState extends State<MyHomePage> {
trailing: Icon(Icons.play_arrow),
title: Text('Exercice 2'),
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:
# The following section is specific to Flutter.
flutter:
assets:
- assets/
# The following line ensures that the Material Icons font is
# 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