Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Mobile Development Workshop 2022
# Mobile Development Workshop 2023

## Prerequisities

Expand Down
117 changes: 1 addition & 116 deletions mem_game/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'Flutter Demo',
home: HomeScreen(),
);
}
}

class HomeScreen extends StatefulWidget {
Expand All @@ -27,112 +20,4 @@ class HomeScreen extends StatefulWidget {
State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
Game game = Game();

int turns = 0;
int pairsFound = 0;

@override
void initState() {
super.initState();
game.initGame();
}

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFF3A405A),
body: Column(
children: <Widget>[
const SizedBox(
height: 30,
),
const Header(),
Expanded(
child: Center(
child: AspectRatio(
aspectRatio: 9 / 10,
child: GridView.builder(
itemCount: game.cardPaths.length,
gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4,
crossAxisSpacing: 16.0,
mainAxisSpacing: 16.0,
),
padding: const EdgeInsets.all(16.0),
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
setState(() {
turns += 1;
game.selectedCards.add(index);
});

// Player selected two cards
if (game.selectedCards.length == 2) {
int firstCard = game.selectedCards.elementAt(0);
int secondCard = game.selectedCards.elementAt(1);

if (game.cardPaths[firstCard] ==
game.cardPaths[secondCard] &&
firstCard != secondCard) {
// The two cards match!

game.isCardFlipped[firstCard] = true;
game.isCardFlipped[secondCard] = true;
pairsFound += 1;

if (pairsFound == 8) {
game.initGame();
pairsFound = 0;
turns = 0;
}

game.selectedCards.clear();
} else {
Future.delayed(const Duration(milliseconds: 250),
() {
setState(() {
game.selectedCards.clear();
});
});
}
}
},
child: Container(
decoration: BoxDecoration(
color: const Color(0xFF99B2DD),
borderRadius: BorderRadius.circular(12.0),
image: DecorationImage(
image: AssetImage((() {
if (game.isCardFlipped[index] == true ||
game.selectedCards.contains(index)) {
return game.cardPaths[index];
} else {
return game.questionCardPath;
}
})()),
fit: BoxFit.cover,
),
),
),
);
}),
),
),
),
Row(
//mainAxisAlignment: MainAxisAlignment.spaceAround,
//crossAxisAlignment: CrossAxisAlignment.center,
children: [
CustomCard("Turns", "$turns"),
CustomCard("Pairs Found", "$pairsFound"),
],
),
],
),
);
}
}
class _HomeScreenState extends State<HomeScreen> {}
39 changes: 1 addition & 38 deletions mem_game/lib/widgets/custom_card.dart
Original file line number Diff line number Diff line change
@@ -1,40 +1,3 @@
import 'package:flutter/material.dart';

class CustomCard extends StatelessWidget {
final String title;
final String value;

const CustomCard(this.title, this.value, {Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Expanded(
child: Container(
margin: const EdgeInsets.all(15.0),
child: Column(
children: [
Text(
title,
style: const TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
const SizedBox(
height: 5.0,
),
Text(
value,
style: const TextStyle(
fontSize: 50.0,
fontWeight: FontWeight.w900,
color: Colors.white,
),
),
],
),
),
);
}
}
class CustomCard extends StatelessWidget {}
19 changes: 1 addition & 18 deletions mem_game/lib/widgets/header.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
import 'package:flutter/material.dart';

class Header extends StatelessWidget {
const Header({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return const Center(
child: Text(
"Mem Game",
style: TextStyle(
fontSize: 40.0,
fontWeight: FontWeight.bold,
color: Colors.white,
fontFamily: 'Pacifico',
),
),
);
}
}
class Header extends StatelessWidget {}