diff --git a/README.md b/README.md index a9787bc..b6ae24a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Mobile Development Workshop 2022 +# Mobile Development Workshop 2023 ## Prerequisities diff --git a/mem_game/lib/main.dart b/mem_game/lib/main.dart index 54b48c4..2fd5a72 100644 --- a/mem_game/lib/main.dart +++ b/mem_game/lib/main.dart @@ -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 { @@ -27,112 +20,4 @@ class HomeScreen extends StatefulWidget { State createState() => _HomeScreenState(); } -class _HomeScreenState extends State { - 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: [ - 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 {} diff --git a/mem_game/lib/widgets/custom_card.dart b/mem_game/lib/widgets/custom_card.dart index eca9f89..97e4f9b 100644 --- a/mem_game/lib/widgets/custom_card.dart +++ b/mem_game/lib/widgets/custom_card.dart @@ -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 {} diff --git a/mem_game/lib/widgets/header.dart b/mem_game/lib/widgets/header.dart index 6a5216e..70a1ebc 100644 --- a/mem_game/lib/widgets/header.dart +++ b/mem_game/lib/widgets/header.dart @@ -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 {}