diff --git a/assets/Dice-1.png b/assets/Dice-1.png new file mode 100644 index 0000000..e7e5396 Binary files /dev/null and b/assets/Dice-1.png differ diff --git a/assets/Dice-2.png b/assets/Dice-2.png new file mode 100644 index 0000000..969271f Binary files /dev/null and b/assets/Dice-2.png differ diff --git a/assets/Dice-3.png b/assets/Dice-3.png new file mode 100644 index 0000000..ca7f019 Binary files /dev/null and b/assets/Dice-3.png differ diff --git a/assets/Dice-4.png b/assets/Dice-4.png new file mode 100644 index 0000000..186a29d Binary files /dev/null and b/assets/Dice-4.png differ diff --git a/assets/Dice-5.png b/assets/Dice-5.png new file mode 100644 index 0000000..c8ce0ab Binary files /dev/null and b/assets/Dice-5.png differ diff --git a/assets/Dice-6.png b/assets/Dice-6.png new file mode 100644 index 0000000..044510d Binary files /dev/null and b/assets/Dice-6.png differ diff --git a/lib/main.dart b/lib/main.dart index 5edb603..64a5341 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,5 @@ import 'package:bharat_mystery/screens/homepage.dart'; +import 'package:bharat_mystery/screens/mainGame.dart'; import 'package:bharat_mystery/screens/selectMonument.dart'; import 'package:bharat_mystery/screens/theme_provider.dart'; import 'package:flutter/material.dart'; @@ -43,7 +44,8 @@ class MyApp extends StatelessWidget { '/register-page': (_) => RegisterPage(), '/home-page': (_) => HomePage(), '/forgot-password-page': (_) => ForgotPage(), - '/select-monument': (_) => SelectMonument() + '/select-monument': (_) => SelectMonument(), + '/main-game': (_) => MainGame(), }); }, ), diff --git a/lib/screens/game.dart b/lib/screens/game.dart new file mode 100644 index 0000000..d09f0ca --- /dev/null +++ b/lib/screens/game.dart @@ -0,0 +1,199 @@ +import 'package:flutter/services.dart'; +import 'package:bharat_mystery/screens/mainGame.dart'; +import 'package:flutter/material.dart'; + +class Game extends StatefulWidget { + const Game({Key pagekey, this.title}) : super(key: pagekey); + final String title; + + @override + _GameState createState() => _GameState(); +} + +class _GameState extends State<Game> with AutomaticKeepAliveClientMixin { + Future<bool> _onWillPop() { + return showDialog( + context: context, + builder: (context) => AlertDialog( + title: Text('Are you sure?'), + content: Text('Do you want to exit the app?'), + actions: <Widget>[ + TextButton( + onPressed: () => Navigator.of(context).pop(false), + child: Text('No'), + ), + TextButton( + onPressed: () => SystemNavigator.pop(), + child: Text('Yes'), + ), + ], + ), + ) ?? + false; + } + + @override + Widget build(BuildContext context) { + super.build(context); + //exit app on back pressed + return WillPopScope(onWillPop: _onWillPop, child: GameContent()); + } + + @override + // TODO: implement wantKeepAlive + bool get wantKeepAlive => true; +} + +class GameContent extends StatefulWidget { + @override + _GameContentState createState() => _GameContentState(); +} + +class _GameContentState extends State<GameContent> { + String _player1Name, _player2Name; + final GlobalKey<FormState> _formKey = GlobalKey<FormState>(); + List players = []; + + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: Theme.of(context).focusColor, + body: SingleChildScrollView( + child: Container( + width: MediaQuery.of(context).size.width, + height: MediaQuery.of(context).size.height, + decoration: BoxDecoration( + color: Theme.of(context).accentColor, + ), + child: Stack( + children: <Widget>[ + Padding( + padding: const EdgeInsets.fromLTRB(10.0, 200.0, 10.0, 20.0), + child: Column( + children: <Widget>[ + Text( + "Player Info", + style: TextStyle( + color: Theme.of(context).highlightColor, + fontFamily: 'LexendDeca', + fontSize: 25.0, + fontWeight: FontWeight.bold, + ), + ), + SizedBox( + height: 30.0, + ), + Form( + key: _formKey, + child: Column( + children: <Widget>[ + //textfield player1 + TextFormField( + autocorrect: false, + autofocus: false, + validator: (input) { + if (input.isEmpty) { + return "Please provide Player's Name"; + } + return null; + }, + style: TextStyle(color: Colors.black), + decoration: InputDecoration( + hintText: "Player 1 Name", + hintStyle: TextStyle(color: Colors.grey), + border: OutlineInputBorder( + borderSide: + BorderSide(color: Colors.grey[50]), + borderRadius: BorderRadius.circular(30.0), + ), + fillColor: Colors.white, + filled: true, + contentPadding: EdgeInsets.all(20.0)), + onSaved: (input) => _player1Name = input, + keyboardType: TextInputType.emailAddress, + ), + SizedBox( + height: 20.0, + ), + + //textfield player1 + TextFormField( + autocorrect: false, + autofocus: false, + validator: (input) { + if (input.isEmpty) { + return "Please provide Player's Name"; + } + return null; + }, + style: TextStyle(color: Colors.black), + decoration: InputDecoration( + hintText: "Player 2 Name", + hintStyle: TextStyle(color: Colors.grey), + border: OutlineInputBorder( + borderSide: + BorderSide(color: Colors.grey[50]), + borderRadius: BorderRadius.circular(30.0), + ), + fillColor: Colors.white, + filled: true, + contentPadding: EdgeInsets.all(20.0)), + onSaved: (input) => _player2Name = input, + keyboardType: TextInputType.emailAddress, + ), + SizedBox( + height: 20.0, + ), + + MaterialButton( + onPressed: addUser, + height: 50.0, + padding: EdgeInsets.symmetric(horizontal: 40.0), + shape: StadiumBorder(), + child: Text( + "Start Game", + style: TextStyle( + fontFamily: 'LexendDeca', + fontSize: 16.0, + color: Theme.of(context).cardColor), + ), + color: Theme.of(context).highlightColor, + ), + ], + ), + ), + ], + ), + ), + Positioned( + bottom: 0, + child: Container( + width: MediaQuery.of(context).size.width, + height: 20.0, + color: Theme.of(context).focusColor, + ), + ), + ], + ), + ), + ), + ); + } + + void addUser() { + final formState = _formKey.currentState; + if (formState.validate()) { + formState.save(); + players.add(_player1Name); + players.add(_player2Name); + + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => MainGame( + players: players, + ), + )); + } + } +} diff --git a/lib/screens/homepage.dart b/lib/screens/homepage.dart index 36e801d..6ade341 100644 --- a/lib/screens/homepage.dart +++ b/lib/screens/homepage.dart @@ -1,6 +1,7 @@ import 'package:bharat_mystery/screens/profile.dart'; import 'package:bharat_mystery/screens/selectMonument.dart'; import 'package:bharat_mystery/screens/theme_provider.dart'; +import 'package:bharat_mystery/screens/game.dart'; import 'package:flutter/material.dart'; import 'package:curved_navigation_bar/curved_navigation_bar.dart'; import 'package:provider/provider.dart'; @@ -14,6 +15,7 @@ class _HomePageState extends State<HomePage> { PageController _pageController = PageController(); List<Widget> _screens = [ SelectMonument(), + Game(), Profile(), ]; @@ -48,6 +50,11 @@ class _HomePageState extends State<HomePage> { size: 20.0, color: Theme.of(context).highlightColor, ), + Icon( + Icons.gamepad, + size: 20.0, + color: Theme.of(context).highlightColor, + ), Icon( Icons.settings, size: 20.0, diff --git a/lib/screens/mainGame.dart b/lib/screens/mainGame.dart new file mode 100644 index 0000000..6db8a12 --- /dev/null +++ b/lib/screens/mainGame.dart @@ -0,0 +1,201 @@ +import 'package:flutter/material.dart'; +import 'dart:math'; + +class MainGame extends StatefulWidget { + final List players; + MainGame({this.players}); + + @override + _MainGameState createState() => _MainGameState(); +} + +class _MainGameState extends State<MainGame> { + String player1Initials; + String player2Initials; + + @override + void initState() { + // TODO: implement initState + super.initState(); + var nameparts1 = widget.players[0].split(" "); + var p1I = nameparts1[0][0].toUpperCase() + nameparts1[1][0].toUpperCase(); + player1Initials = p1I; + + var nameparts2 = widget.players[1].split(" "); + var p2I = nameparts2[0][0].toUpperCase() + nameparts2[1][0].toUpperCase(); + player2Initials = p2I; + } + + int newDiceImage = 1; + Color activeColor1 = Colors.blue; + Color activeColor2 = Colors.black; + + @override + Widget build(BuildContext context) { + return Scaffold( + body: SingleChildScrollView( + child: Container( + width: MediaQuery.of(context).size.width, + height: MediaQuery.of(context).size.height, + decoration: BoxDecoration( + color: Theme.of(context).accentColor, + ), + child: Padding( + padding: const EdgeInsets.fromLTRB(20, 50, 20, 10), + child: Column( + children: <Widget>[ + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: <Widget>[ + CircleAvatar( + backgroundColor: activeColor1, + radius: 50, + child: CircleAvatar( + backgroundColor: Theme.of(context).highlightColor, + radius: 45, + child: Text( + player1Initials, + style: TextStyle( + fontFamily: 'Lexend Deca', + fontSize: 30.0, + fontWeight: FontWeight.bold, + ), + ), + ), + ), + CircleAvatar( + backgroundColor: activeColor2, + radius: 50, + child: CircleAvatar( + backgroundColor: Theme.of(context).highlightColor, + radius: 45, + child: Text( + player2Initials, + style: TextStyle( + fontFamily: 'Lexend Deca', + fontSize: 30.0, + fontWeight: FontWeight.bold, + ), + ), + ), + ), + ], + ), + SizedBox( + height: 40.0, + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: <Widget>[ + Container( + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(10.0)), + height: 100.0, + width: 100.0, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Image.asset('assets/Dice-$newDiceImage.png'), + ), + ), + ], + ), + SizedBox( + height: 30.0, + ), + MaterialButton( + onPressed: () { + setState(() { + newDiceImage = Random().nextInt(6) + 1; + if (activeColor1 == Colors.blue) { + activeColor1 = Colors.black; + activeColor2 = Colors.blue; + } else { + activeColor1 = Colors.blue; + activeColor2 = Colors.black; + } + }); + }, + height: 40.0, + padding: EdgeInsets.symmetric(horizontal: 30.0), + shape: StadiumBorder(), + child: Text( + "Roll Dice", + style: TextStyle( + fontFamily: 'LexendDeca', + fontSize: 16.0, + color: Theme.of(context).cardColor), + ), + color: Theme.of(context).highlightColor, + ), + SizedBox( + height: 30.0, + ), + MaterialButton( + onPressed: () { + setState(() { + newDiceImage = Random().nextInt(6) + 1; + }); + }, + height: 50.0, + padding: EdgeInsets.symmetric(horizontal: 40.0), + shape: StadiumBorder(), + child: Text( + "Available Monuments", + style: TextStyle( + fontFamily: 'LexendDeca', + fontSize: 16.0, + color: Theme.of(context).cardColor), + ), + color: Theme.of(context).highlightColor, + ), + SizedBox( + height: 20.0, + ), + MaterialButton( + onPressed: () { + setState(() { + newDiceImage = Random().nextInt(6) + 1; + }); + }, + height: 50.0, + padding: EdgeInsets.symmetric(horizontal: 40.0), + shape: StadiumBorder(), + child: Text( + "My Monuments", + style: TextStyle( + fontFamily: 'LexendDeca', + fontSize: 16.0, + color: Theme.of(context).cardColor), + ), + color: Theme.of(context).highlightColor, + ), + SizedBox( + height: 30.0, + ), + MaterialButton( + onPressed: () { + setState(() { + newDiceImage = Random().nextInt(6) + 1; + }); + }, + height: 50.0, + padding: EdgeInsets.symmetric(horizontal: 40.0), + shape: StadiumBorder(), + child: Text( + "End Game", + style: TextStyle( + fontFamily: 'LexendDeca', + fontSize: 16.0, + color: Theme.of(context).cardColor), + ), + color: Theme.of(context).highlightColor, + ), + ], + ), + ), + ), + ), + ); + } +} diff --git a/lib/screens/profile.dart b/lib/screens/profile.dart index f85a693..b838985 100644 --- a/lib/screens/profile.dart +++ b/lib/screens/profile.dart @@ -8,7 +8,6 @@ import 'package:flutter/services.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:provider/provider.dart'; -import 'package:flutter_phoenix/flutter_phoenix.dart'; class Profile extends StatefulWidget { @override @@ -60,7 +59,7 @@ class _ProfileState extends State<Profile> with AutomaticKeepAliveClientMixin { children: <Widget>[ Padding( padding: const EdgeInsets.fromLTRB( - 20.0, 300.0, 20.0, 0), //text username + 20.0, 200.0, 20.0, 0), //text username child: Column( children: <Widget>[ new Text( diff --git a/pubspec.yaml b/pubspec.yaml index 14cc417..61aa4d4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -61,8 +61,8 @@ flutter: uses-material-design: true # To add assets to your application, add an assets section, like this: - # assets: - # - assets/images/logo.png + assets: + - assets/ # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware.