Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
JeuDeTaquin
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
Benjamin LEROUX
JeuDeTaquin
Commits
ac03a5a4
Commit
ac03a5a4
authored
Feb 16, 2021
by
Benjamin LEROUX
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fin exo6
parent
7c849a6c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
44 deletions
+52
-44
Plateau.dart
lib/Plateau.dart
+3
-16
exo6.dart
lib/exo6.dart
+49
-28
No files found.
lib/Plateau.dart
View file @
ac03a5a4
...
@@ -3,19 +3,6 @@ import 'package:flutter/material.dart';
...
@@ -3,19 +3,6 @@ import 'package:flutter/material.dart';
import
'Tile.dart'
;
import
'Tile.dart'
;
class
Plateau
{
List
<
Tile
>
listTile
;
double
size
;
Plateau
({
this
.
listTile
,
this
.
size
});
List
<
Tile
>
getListTile
(){
return
listTile
;
}
}
int
size
=
5
;
class
DisplayPlateauWidget
extends
StatefulWidget
{
class
DisplayPlateauWidget
extends
StatefulWidget
{
@override
@override
_DisplayPlateauWidgetState
createState
()
=>
_DisplayPlateauWidgetState
();
_DisplayPlateauWidgetState
createState
()
=>
_DisplayPlateauWidgetState
();
...
@@ -50,7 +37,7 @@ class _DisplayPlateauWidgetState extends State<DisplayPlateauWidget> {
...
@@ -50,7 +37,7 @@ class _DisplayPlateauWidgetState extends State<DisplayPlateauWidget> {
onChanged:
(
double
value
)
{
onChanged:
(
double
value
)
{
setState
(()
{
_currentSliderValue
=
value
;});
setState
(()
{
_currentSliderValue
=
value
;});
}
}
),
),
),
),
]
]
),
),
...
@@ -82,9 +69,9 @@ class _DisplayPlateauWidgetState extends State<DisplayPlateauWidget> {
...
@@ -82,9 +69,9 @@ 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
(
imageURL:
'https://picsum.photos/512/1024'
,
alignment:
Alignment
(
j
,
i
),
size:
size
));
j
+=(
1
/((
size
-
1
)/
2
));
j
+=(
2
/(
size
-
1
));
}
}
i
+=(
1
/((
size
-
1
)/
2
));
i
+=(
2
/(
size
-
1
));
}
}
return
res
;
return
res
;
}
}
...
...
lib/exo6.dart
View file @
ac03a5a4
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'dart:math'
as
math
;
// ==============
// Models
// ==============
math
.
Random
random
=
new
math
.
Random
();
class
Tile
{
class
Tile
{
Color
color
;
Color
color
;
...
@@ -14,14 +7,11 @@ class Tile {
...
@@ -14,14 +7,11 @@ class Tile {
Tile
(
this
.
index
,
this
.
color
);
Tile
(
this
.
index
,
this
.
color
);
}
}
// ==============
// Widgets
// ==============
class
TileWidget
extends
StatelessWidget
{
class
TileWidget
extends
StatelessWidget
{
final
Tile
tile
;
Tile
tile
;
bool
isUsable
=
false
;
TileWidget
(
this
.
tile
);
TileWidget
(
this
.
tile
,
this
.
isUsable
);
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
...
@@ -39,19 +29,33 @@ class TileWidget extends StatelessWidget {
...
@@ -39,19 +29,33 @@ class TileWidget extends StatelessWidget {
}
}
}
}
int
emptyIndex
=
0
;
BoxDecoration
myBoxDecoration
(
bool
isUsable
)
{
BoxDecoration
res
=
BoxDecoration
();
if
(
isUsable
){
res
=
BoxDecoration
(
border:
Border
.
all
(
color:
Colors
.
red
,
width:
5.0
,
),
);
}
return
res
;
}
List
<
Widget
>
createTileWidgets
(
double
slide
){
List
<
TileWidget
>
createTileWidgets
(
double
slide
,
int
emptyIndex
){
List
<
Widget
>
tiles
=
<
Widget
>[];
List
<
TileWidget
>
tiles
=
<
Tile
Widget
>[];
int
max
=
slide
.
toInt
()*
slide
.
toInt
();
int
max
=
slide
.
toInt
()*
slide
.
toInt
();
tiles
.
add
(
TileWidget
(
Tile
(
"Vide"
,
Colors
.
white
)));
for
(
int
i
=
0
;
i
<
max
;
i
++){
for
(
int
i
=
0
;
i
<
max
-
1
;
i
++){
if
(
i
==
emptyIndex
){
tiles
.
add
(
TileWidget
(
Tile
((
i
+
1
).
toString
(),
Colors
.
grey
)));
tiles
.
add
(
TileWidget
(
Tile
(
"Vide"
,
Colors
.
white
),
false
));
}
else
if
(
i
==
emptyIndex
+
1
||
i
==
emptyIndex
+
slide
.
toInt
()){
tiles
.
add
(
TileWidget
(
Tile
((
i
).
toString
(),
Colors
.
grey
),
true
));
}
else
tiles
.
add
(
TileWidget
(
Tile
((
i
).
toString
(),
Colors
.
grey
),
false
));
}
}
return
tiles
;
return
tiles
;
}
}
void
main
(
)
=>
runApp
(
new
MaterialApp
(
home:
PositionedTiles
()));
void
main
(
)
=>
runApp
(
new
MaterialApp
(
home:
PositionedTiles
()));
class
PositionedTiles
extends
StatefulWidget
{
class
PositionedTiles
extends
StatefulWidget
{
...
@@ -63,7 +67,8 @@ class PositionedTilesState extends State<PositionedTiles> {
...
@@ -63,7 +67,8 @@ class PositionedTilesState extends State<PositionedTiles> {
TextStyle
textStyle
=
TextStyle
(
fontSize:
16
,
fontWeight:
FontWeight
.
bold
,);
TextStyle
textStyle
=
TextStyle
(
fontSize:
16
,
fontWeight:
FontWeight
.
bold
,);
var
appBar
=
AppBar
(
title:
Text
(
'Exo 6'
),);
var
appBar
=
AppBar
(
title:
Text
(
'Exo 6'
),);
double
_currentSlideValue
=
4
;
double
_currentSlideValue
=
4
;
List
<
Widget
>
tiles
=
createTileWidgets
(
4
);
List
<
TileWidget
>
tiles
=
createTileWidgets
(
4
,
0
);
int
emptyIndex
=
0
;
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
...
@@ -81,11 +86,14 @@ class PositionedTilesState extends State<PositionedTiles> {
...
@@ -81,11 +86,14 @@ class PositionedTilesState extends State<PositionedTiles> {
mainAxisSpacing:
5.0
,
mainAxisSpacing:
5.0
,
),
),
itemBuilder:
(
BuildContext
context
,
int
index
)
{
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
InkWell
(
return
Container
(
child:
tiles
[
index
],
decoration:
myBoxDecoration
(
tiles
[
index
].
isUsable
),
onTap:
(){
child:
InkWell
(
swapTiles
(
index
,
emptyIndex
);
child:
tiles
[
index
],
},
onTap:
(){
swapTiles
(
index
,
emptyIndex
);
},
),
);
);
},
},
),
),
...
@@ -99,7 +107,7 @@ class PositionedTilesState extends State<PositionedTiles> {
...
@@ -99,7 +107,7 @@ class PositionedTilesState extends State<PositionedTiles> {
onChanged:
(
double
value
)
{
onChanged:
(
double
value
)
{
setState
(()
{
setState
(()
{
_currentSlideValue
=
value
;
_currentSlideValue
=
value
;
tiles
=
createTileWidgets
(
_currentSlideValue
);
tiles
=
createTileWidgets
(
_currentSlideValue
,
emptyIndex
);
//initialSize=_currentSlideValue;
//initialSize=_currentSlideValue;
});
});
}
}
...
@@ -114,10 +122,18 @@ class PositionedTilesState extends State<PositionedTiles> {
...
@@ -114,10 +122,18 @@ class PositionedTilesState extends State<PositionedTiles> {
swapTiles
(
int
current
,
int
empty
)
{
swapTiles
(
int
current
,
int
empty
)
{
setState
(()
{
setState
(()
{
//print(current);
//RESET bordures des cases apres deplacements
for
(
int
i
=
0
;
i
<
tiles
.
length
;
i
++){
if
(
i
!=
empty
)
tiles
[
i
].
isUsable
=
false
;
}
if
(
current
==
empty
+
1
&&
current
%
_currentSlideValue
!=
0
){
if
(
current
==
empty
+
1
&&
current
%
_currentSlideValue
!=
0
){
emptyIndex
=
current
;
emptyIndex
=
current
;
tiles
.
insert
(
empty
,
tiles
.
removeAt
(
current
));
tiles
.
insert
(
empty
,
tiles
.
removeAt
(
current
));
// tiles[empty].isUsable=true;
// tiles[empty+2].isUsable=true;
// tiles[empty+_currentSlideValue.toInt()+1].isUsable=true;
}
else
if
(
current
==
empty
-
1
&&
empty
%
_currentSlideValue
!=
0
){
}
else
if
(
current
==
empty
-
1
&&
empty
%
_currentSlideValue
!=
0
){
emptyIndex
=
current
;
emptyIndex
=
current
;
tiles
.
insert
(
empty
,
tiles
.
removeAt
(
current
));
tiles
.
insert
(
empty
,
tiles
.
removeAt
(
current
));
...
@@ -131,6 +147,11 @@ class PositionedTilesState extends State<PositionedTiles> {
...
@@ -131,6 +147,11 @@ class PositionedTilesState extends State<PositionedTiles> {
tiles
.
insert
(
current
,
tiles
.
removeAt
(
empty
));
tiles
.
insert
(
current
,
tiles
.
removeAt
(
empty
));
tiles
.
insert
(
empty
,
tiles
.
removeAt
(
current
+
1
));
tiles
.
insert
(
empty
,
tiles
.
removeAt
(
current
+
1
));
}
else
print
(
"Can't move this"
);
}
else
print
(
"Can't move this"
);
if
(
emptyIndex
>=
_currentSlideValue
)
tiles
[
emptyIndex
-
_currentSlideValue
.
toInt
()].
isUsable
=
true
;
if
(
emptyIndex
<(
_currentSlideValue
*(
_currentSlideValue
-
1
)))
tiles
[
emptyIndex
+
_currentSlideValue
.
toInt
()].
isUsable
=
true
;
if
((
emptyIndex
+
1
)%
_currentSlideValue
!=
0
)
tiles
[
emptyIndex
+
1
].
isUsable
=
true
;
if
(
emptyIndex
%
_currentSlideValue
!=
0
)
tiles
[
emptyIndex
-
1
].
isUsable
=
true
;
});
});
}
}
...
...
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