Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
org.benoitharrault.puzzlegame
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
android
org.benoitharrault.puzzlegame
Commits
4be19b09
Commit
4be19b09
authored
3 years ago
by
Benoît Harrault
Browse files
Options
Downloads
Plain Diff
Merge branch '7-add-check-tiles-ordering-feature' into 'master'
Resolve "Add check tiles ordering feature" Closes
#7
See merge request
!14
parents
e5ac2049
4884ca0e
No related branches found
No related tags found
1 merge request
!14
Resolve "Add check tiles ordering feature"
Pipeline
#1252
passed
3 years ago
Stage: update
Stage: build-debug
Changes
4
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
android/gradle.properties
+2
-2
2 additions, 2 deletions
android/gradle.properties
lib/entities/tile.dart
+2
-3
2 additions, 3 deletions
lib/entities/tile.dart
lib/provider/data.dart
+8
-0
8 additions, 0 deletions
lib/provider/data.dart
lib/screens/home.dart
+47
-9
47 additions, 9 deletions
lib/screens/home.dart
with
59 additions
and
14 deletions
android/gradle.properties
+
2
−
2
View file @
4be19b09
org.gradle.jvmargs
=
-Xmx1536M
org.gradle.jvmargs
=
-Xmx1536M
android.useAndroidX
=
true
android.useAndroidX
=
true
android.enableJetifier
=
true
android.enableJetifier
=
true
app.versionName
=
0.0.1
0
app.versionName
=
0.0.1
1
app.versionCode
=
1
0
app.versionCode
=
1
1
This diff is collapsed.
Click to expand it.
lib/entities/tile.dart
+
2
−
3
View file @
4be19b09
...
@@ -6,8 +6,8 @@ import '../provider/data.dart';
...
@@ -6,8 +6,8 @@ import '../provider/data.dart';
class
Tile
{
class
Tile
{
final
Image
image
;
final
Image
image
;
final
double
size
;
final
double
size
;
final
int
currentCol
;
int
currentCol
;
final
int
currentRow
;
int
currentRow
;
final
int
originalCol
;
final
int
originalCol
;
final
int
originalRow
;
final
int
originalRow
;
...
@@ -72,7 +72,6 @@ class Tile {
...
@@ -72,7 +72,6 @@ class Tile {
);
);
},
},
onAccept:
(
List
<
int
>
data
)
{
onAccept:
(
List
<
int
>
data
)
{
print
(
data
.
toString
());
myProvider
.
swapTiles
(
myProvider
.
swapTiles
(
[
this
.
currentCol
,
this
.
currentRow
],
[
this
.
currentCol
,
this
.
currentRow
],
data
data
...
...
This diff is collapsed.
Click to expand it.
lib/provider/data.dart
+
8
−
0
View file @
4be19b09
...
@@ -58,6 +58,14 @@ class Data extends ChangeNotifier {
...
@@ -58,6 +58,14 @@ class Data extends ChangeNotifier {
_tiles
[
indexTile1
]
=
_tiles
[
indexTile2
];
_tiles
[
indexTile1
]
=
_tiles
[
indexTile2
];
_tiles
[
indexTile2
]
=
swap
;
_tiles
[
indexTile2
]
=
swap
;
int
swapCol
=
_tiles
[
indexTile1
]
.
currentCol
;
_tiles
[
indexTile1
]
.
currentCol
=
_tiles
[
indexTile2
]
.
currentCol
;
_tiles
[
indexTile2
]
.
currentCol
=
swapCol
;
int
swapRow
=
_tiles
[
indexTile1
]
.
currentRow
;
_tiles
[
indexTile1
]
.
currentRow
=
_tiles
[
indexTile2
]
.
currentRow
;
_tiles
[
indexTile2
]
.
currentRow
=
swapRow
;
notifyListeners
();
notifyListeners
();
}
}
...
...
This diff is collapsed.
Click to expand it.
lib/screens/home.dart
+
47
−
9
View file @
4be19b09
import
'dart:typed_data'
;
import
'dart:typed_data'
;
import
'dart:math'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
show
rootBundle
;
import
'package:flutter/services.dart'
show
rootBundle
;
...
@@ -143,6 +144,30 @@ class Home extends StatelessWidget {
...
@@ -143,6 +144,30 @@ class Home extends StatelessWidget {
);
);
}
}
List
<
Tile
>
shuffleTiles
(
List
<
Tile
>
tiles
)
{
var
random
=
new
Random
();
int
tilesCount
=
tiles
.
length
;
for
(
int
i
=
0
;
i
<
40
;
i
++
)
{
int
indexTile1
=
random
.
nextInt
(
tilesCount
);
int
indexTile2
=
random
.
nextInt
(
tilesCount
);
Tile
swap
=
tiles
[
indexTile1
];
tiles
[
indexTile1
]
=
tiles
[
indexTile2
];
tiles
[
indexTile2
]
=
swap
;
int
swapCol
=
tiles
[
indexTile1
]
.
currentCol
;
tiles
[
indexTile1
]
.
currentCol
=
tiles
[
indexTile2
]
.
currentCol
;
tiles
[
indexTile2
]
.
currentCol
=
swapCol
;
int
swapRow
=
tiles
[
indexTile1
]
.
currentRow
;
tiles
[
indexTile1
]
.
currentRow
=
tiles
[
indexTile2
]
.
currentRow
;
tiles
[
indexTile2
]
.
currentRow
=
swapRow
;
}
return
tiles
;
}
Future
<
List
<
Tile
>>
splitImageInTiles
(
Data
myProvider
)
async
{
Future
<
List
<
Tile
>>
splitImageInTiles
(
Data
myProvider
)
async
{
String
imageAsset
=
getImageAssetName
(
myProvider
.
image
);
String
imageAsset
=
getImageAssetName
(
myProvider
.
image
);
Uint8List
imageData
=
(
await
rootBundle
.
load
(
imageAsset
))
Uint8List
imageData
=
(
await
rootBundle
.
load
(
imageAsset
))
...
@@ -176,14 +201,27 @@ class Home extends StatelessWidget {
...
@@ -176,14 +201,27 @@ class Home extends StatelessWidget {
y
+=
height
;
y
+=
height
;
}
}
tiles
.
shuffle
();
return
shuffleTiles
(
tiles
);
}
return
tiles
;
bool
_checkTilesetIsOrdered
(
List
<
Tile
>
tiles
)
{
for
(
Tile
tile
in
tiles
)
{
if
(
(
tile
.
currentRow
!=
tile
.
originalRow
)
||
(
tile
.
currentCol
!=
tile
.
originalCol
)
)
{
return
false
;
}
}
return
true
;
}
}
Container
_buildTilesetWidget
(
Data
myProvider
)
{
Container
_buildTilesetWidget
(
Data
myProvider
)
{
List
tiles
=
myProvider
.
tiles
;
List
tiles
=
myProvider
.
tiles
;
Color
borderColor
=
_checkTilesetIsOrdered
(
tiles
)
?
Colors
.
green
:
Colors
.
orange
;
int
tileIndex
=
0
;
int
tileIndex
=
0
;
Table
tileset
=
Table
(
Table
tileset
=
Table
(
...
@@ -204,14 +242,14 @@ class Home extends StatelessWidget {
...
@@ -204,14 +242,14 @@ class Home extends StatelessWidget {
);
);
return
Container
(
return
Container
(
margin:
EdgeInsets
.
all
(
4
),
margin:
EdgeInsets
.
all
(
8
),
padding:
EdgeInsets
.
all
(
4
),
padding:
EdgeInsets
.
all
(
8
),
decoration:
BoxDecoration
(
decoration:
BoxDecoration
(
color:
Colors
.
blue
,
color:
borderColor
,
borderRadius:
BorderRadius
.
circular
(
4
),
borderRadius:
BorderRadius
.
circular
(
8
),
border:
Border
.
all
(
border:
Border
.
all
(
color:
Colors
.
green
,
color:
borderColor
,
width:
4
,
width:
8
,
),
),
),
),
child:
tileset
,
child:
tileset
,
...
@@ -226,7 +264,7 @@ class Home extends StatelessWidget {
...
@@ -226,7 +264,7 @@ class Home extends StatelessWidget {
color:
Colors
.
blue
,
color:
Colors
.
blue
,
borderRadius:
BorderRadius
.
circular
(
4
),
borderRadius:
BorderRadius
.
circular
(
4
),
border:
Border
.
all
(
border:
Border
.
all
(
color:
Colors
.
green
,
color:
Colors
.
blue
,
width:
4
,
width:
4
,
),
),
),
),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment