Skip to content
Snippets Groups Projects
Commit 7202a264 authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Add minimal gameplay

parent bf0748f6
No related branches found
No related tags found
1 merge request!21Resolve "Add minimal gameplay"
Pipeline #1057 passed
org.gradle.jvmargs=-Xmx1536M org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
app.versionName=0.0.20 app.versionName=0.0.21
app.versionCode=20 app.versionCode=21
...@@ -12,6 +12,10 @@ class GamePickWordPage extends StatelessWidget { ...@@ -12,6 +12,10 @@ class GamePickWordPage extends StatelessWidget {
await pickData(context, myProvider); await pickData(context, myProvider);
} }
Future<void> nextWord(BuildContext context, Data myProvider) async {
await pickData(context, myProvider);
}
Future<void> pickData(BuildContext context, Data myProvider) async { Future<void> pickData(BuildContext context, Data myProvider) async {
List words; List words;
List images; List images;
...@@ -48,6 +52,12 @@ class GamePickWordPage extends StatelessWidget { ...@@ -48,6 +52,12 @@ class GamePickWordPage extends StatelessWidget {
} }
} }
Future<void> checkWord(BuildContext context, Data myProvider, word) async {
if (myProvider.word == word) {
nextWord(context, myProvider);
}
}
Container _buildImageContainer(String image, Color color) { Container _buildImageContainer(String image, Color color) {
String imageAsset = 'assets/placeholder.png'; String imageAsset = 'assets/placeholder.png';
if (image != null) { if (image != null) {
...@@ -67,7 +77,7 @@ class GamePickWordPage extends StatelessWidget { ...@@ -67,7 +77,7 @@ class GamePickWordPage extends StatelessWidget {
Color color = Colors.black; Color color = Colors.black;
if ((images == null) || (images.length != _count)) { if ((images == null) || (images.length != _count)) {
images = List(_count); return Column();
} }
return Column( return Column(
...@@ -94,7 +104,7 @@ class GamePickWordPage extends StatelessWidget { ...@@ -94,7 +104,7 @@ class GamePickWordPage extends StatelessWidget {
); );
} }
Container _buildTextContainer(String word, Color color) { Container _buildTextContainer(BuildContext context, Data myProvider, String word, Color color) {
return Container( return Container(
child: RaisedButton( child: RaisedButton(
color: Colors.green, color: Colors.green,
...@@ -107,14 +117,18 @@ class GamePickWordPage extends StatelessWidget { ...@@ -107,14 +117,18 @@ class GamePickWordPage extends StatelessWidget {
color: color, color: color,
), ),
), ),
onPressed: () { print("button text: " + word); }, onPressed: () { checkWord(context, myProvider, word); },
), ),
); );
} }
Column _buildTextItemsBlock(String word, List otherWords) { Column _buildTextItemsBlock(BuildContext context, Data myProvider, String word, List otherWords) {
Color color = Colors.white; Color color = Colors.white;
if ((word == null) || (otherWords.length != (_count - 1))) {
return Column();
}
List words = [ List words = [
word, word,
otherWords.length > 0 ? otherWords[0] : null, otherWords.length > 0 ? otherWords[0] : null,
...@@ -132,9 +146,9 @@ class GamePickWordPage extends StatelessWidget { ...@@ -132,9 +146,9 @@ class GamePickWordPage extends StatelessWidget {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
_buildTextContainer(words[0], color), _buildTextContainer(context, myProvider, words[0], color),
SizedBox(width: 10), SizedBox(width: 10),
_buildTextContainer(words[1], color), _buildTextContainer(context, myProvider, words[1], color),
], ],
), ),
SizedBox(height: 10), SizedBox(height: 10),
...@@ -142,15 +156,39 @@ class GamePickWordPage extends StatelessWidget { ...@@ -142,15 +156,39 @@ class GamePickWordPage extends StatelessWidget {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
_buildTextContainer(words[2], color), _buildTextContainer(context, myProvider, words[2], color),
SizedBox(width: 10), SizedBox(width: 10),
_buildTextContainer(words[3], color), _buildTextContainer(context, myProvider, words[3], color),
], ],
) )
], ],
); );
} }
Row _buildStartGameButton(BuildContext context, Data myProvider) {
return Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
child: RaisedButton(
color: Colors.orange,
padding: EdgeInsets.all(35),
child: Text(
"🔀",
style: TextStyle(
fontSize: 60,
fontWeight: FontWeight.w600,
color: Colors.black,
),
),
onPressed: () => startGame(context, myProvider),
),
)
],
);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Data _myProvider = Provider.of<Data>(context); Data _myProvider = Provider.of<Data>(context);
...@@ -167,20 +205,10 @@ class GamePickWordPage extends StatelessWidget { ...@@ -167,20 +205,10 @@ class GamePickWordPage extends StatelessWidget {
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: <Widget>[ children: <Widget>[
_buildImageItemsBlock(_myProvider.images), _buildImageItemsBlock(_myProvider.images),
SizedBox(height: 10), ((_myProvider.word == null) || (_myProvider.word == '')) ?
FlatButton( _buildStartGameButton(context, _myProvider) :
onPressed: () => startGame(context, _myProvider), SizedBox(height: 15),
color: Colors.orange, _buildTextItemsBlock(context, _myProvider, _myProvider.word, _myProvider.otherWords),
padding: EdgeInsets.all(10.0),
child: Row(
children: <Widget>[
Icon(Icons.shuffle),
Text("Nouveau mot")
],
),
),
SizedBox(height: 10),
_buildTextItemsBlock(_myProvider.word, _myProvider.otherWords),
], ],
), ),
), ),
......
...@@ -22,7 +22,7 @@ class Home extends StatelessWidget { ...@@ -22,7 +22,7 @@ class Home extends StatelessWidget {
color: Colors.green, color: Colors.green,
padding: EdgeInsets.all(15), padding: EdgeInsets.all(15),
child: Text( child: Text(
'🧑', '🖼️ ➡️ 💬',
style: Theme.of(context) style: Theme.of(context)
.textTheme .textTheme
.display1 .display1
......
...@@ -23,7 +23,7 @@ class RandomPickImage { ...@@ -23,7 +23,7 @@ class RandomPickImage {
} }
// Check we have enough images // Check we have enough images
if (imageList.length < count) { if ((imageList == null) || (imageList.length < count)) {
print('Not enough images in list for word "'+word+'".'); print('Not enough images in list for word "'+word+'".');
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment