diff --git a/assets/pics/background-day.png b/assets/pics/0.png similarity index 100% rename from assets/pics/background-day.png rename to assets/pics/0.png diff --git a/assets/pics/background-night.png b/assets/pics/1.png similarity index 100% rename from assets/pics/background-night.png rename to assets/pics/1.png diff --git a/assets/pics/background-after-night.png b/assets/pics/2.png similarity index 100% rename from assets/pics/background-after-night.png rename to assets/pics/2.png diff --git a/assets/pics/blue.png b/assets/pics/blue.png new file mode 100644 index 0000000..0ffd36b Binary files /dev/null and b/assets/pics/blue.png differ diff --git a/assets/pics/bluebird.png b/assets/pics/bluebird.png deleted file mode 100644 index 900d012..0000000 Binary files a/assets/pics/bluebird.png and /dev/null differ diff --git a/assets/pics/greenBird.png b/assets/pics/greenBird.png new file mode 100644 index 0000000..9dce6cd Binary files /dev/null and b/assets/pics/greenBird.png differ diff --git a/assets/pics/redbird.png b/assets/pics/redbird.png deleted file mode 100644 index f9ed856..0000000 Binary files a/assets/pics/redbird.png and /dev/null differ diff --git a/lib/Constant/constant.dart b/lib/Constant/constant.dart index da46538..26cba32 100644 --- a/lib/Constant/constant.dart +++ b/lib/Constant/constant.dart @@ -1,3 +1,6 @@ +// ignore_for_file: prefer_const_constructors + +import 'package:flappy_bird/Database/database.dart'; import 'package:flappy_bird/Layouts/Pages/page_settings.dart'; import 'package:flappy_bird/Layouts/Widgets/widget_Button.dart'; import 'package:flappy_bird/Layouts/Widgets/widget_bird.dart'; @@ -54,17 +57,12 @@ enum Navigation{ home, settings, leaderBord } String about = "The game is a side-scroller where the player" " controls a bird, attempting to fly between " " columns of green pipes without hitting them"; - -late BoxDecoration gameBackground; -int indicator = 0; -String background(int index){ - String image = ""; - if(index == 0){ - image = "assets/pics/background-day.png"; - }else if(index == 1){ - image = "assets/pics/background-night.png"; - }else{ - image = "assets/pics/background-after-night.png"; - } - return image; -} \ No newline at end of file +String im = "0"; +BoxDecoration background(String y){ + return BoxDecoration( + image: DecorationImage( + image: AssetImage("assets/pics/$y.png"), + fit: BoxFit.fill), + ); +} +String bird = "assets/pics/bird.png"; \ No newline at end of file diff --git a/lib/Database/database.dart b/lib/Database/database.dart index f37841f..0799469 100644 --- a/lib/Database/database.dart +++ b/lib/Database/database.dart @@ -25,6 +25,20 @@ int read(int id){ return myBox.get(id); } +void writeBackground(int id, String image){ + myBox.put(0, image); + print("WriteBackground func is Activated"); +} + +String readBackground(int id){ + print("Read func is Activated"); + if(myBox.get(id) == null){ + print("0 has been returned"); + return "0 has been returned"; + } + return myBox.get(id); +} + void delete(){ print("delete func is Activated"); } \ No newline at end of file diff --git a/lib/Layouts/Pages/page_home.dart b/lib/Layouts/Pages/page_home.dart index 0fa6209..26a6f8e 100644 --- a/lib/Layouts/Pages/page_home.dart +++ b/lib/Layouts/Pages/page_home.dart @@ -1,17 +1,15 @@ -// ignore_for_file: prefer_const_constructors +// ignore_for_file: prefer_const_constructors, prefer_const_constructors_in_immutables, avoid_unnecessary_containers import 'dart:async'; import 'package:flappy_bird/Database/database.dart'; import 'package:flappy_bird/Layouts/Pages/page_start_screen.dart'; import 'package:flappy_bird/Layouts/Widgets/widget_bird.dart'; -import 'package:flappy_bird/Layouts/Widgets/widget_score.dart'; import 'package:flappy_bird/Layouts/Widgets/widget_barrier.dart'; import 'package:flappy_bird/Layouts/Widgets/widget_cover.dart'; -import 'package:flappy_bird/constant/constant.dart'; import 'package:flutter/material.dart'; import 'package:lottie/lottie.dart'; import 'package:audioplayers/audioplayers.dart'; - +import '../../Constant/constant.dart'; class HomePage extends StatefulWidget { HomePage({Key? key}) : super(key: key); @@ -20,21 +18,9 @@ class HomePage extends StatefulWidget { } class _HomePageState extends State { - - String setTheme() { - if (theme == true) { - return "assets/pics/background-day.png"; - } - else { - return "assets/pics/background-night.png"; - } - } - - @override void initState(){ super.initState(); - setAudio(); audioPlayer.onPlayerStateChanged.listen((state) { @@ -69,12 +55,12 @@ class _HomePageState extends State { } @override - void dispose(){ audioPlayer.dispose(); super.dispose(); } + @override Widget build(BuildContext context) { @@ -85,10 +71,7 @@ class _HomePageState extends State { Expanded( flex: 3, child: Container( - decoration: BoxDecoration( - image: DecorationImage( - image: AssetImage(setTheme()), - fit: BoxFit.cover)), + decoration: background(im), child: Stack( children: [ Bird(yAxis, birdWidth, birdHeight), @@ -104,16 +87,26 @@ class _HomePageState extends State { Barrier( barrierHeight[0][1], barrierWidth, barrierX[0], false), Barrier(barrierHeight[1][0], barrierWidth, barrierX[1], true), - Barrier( - barrierHeight[1][1], barrierWidth, barrierX[1], false), - + Barrier(barrierHeight[1][1], barrierWidth, barrierX[1], false), + Positioned( + bottom: 1, + right: 1, + left: 1, + child: Container(child: Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + Text("Score : $SCORE",style: TextStyle(color: Colors.white,fontSize: 30,fontFamily: "Magic4"),), // Best TEXT + Text("Best : $TOP_SCORE",style: TextStyle(color: Colors.white,fontSize: 30,fontFamily: "Magic4")), + ], + ),), + ), ], ), ), ), Expanded( flex: 1, - child: gameHasStarted ? Score() : Cover(), + child: Cover(), ), ]), ), @@ -156,7 +149,6 @@ class _HomePageState extends State { if (birdIsDead()) { timer.cancel(); _showDialog(); - } time += 0.032; }); @@ -173,6 +165,7 @@ class _HomePageState extends State { write(1, TOP_SCORE); } SCORE++; + // print("Score : $SCORE, Best: $TOP_SCORE"); }); } }); diff --git a/lib/Layouts/Pages/page_leader_board.dart b/lib/Layouts/Pages/page_leader_board.dart index a8bc2ac..ff629f0 100644 --- a/lib/Layouts/Pages/page_leader_board.dart +++ b/lib/Layouts/Pages/page_leader_board.dart @@ -1,10 +1,12 @@ -// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables, avoid_unnecessary_containers +// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables, avoid_unnecessary_containers, avoid_print import 'package:flappy_bird/Constant/constant.dart'; import 'package:flappy_bird/Layouts/Pages/page_share_app.dart'; import 'package:flutter/material.dart'; import 'package:hive_flutter/hive_flutter.dart'; +import '../../Database/database.dart'; + class LeaderBoard extends StatefulWidget { const LeaderBoard({Key? key}) : super(key: key); @@ -15,15 +17,16 @@ class LeaderBoard extends StatefulWidget { class _LeaderBoardState extends State { @override Widget build(BuildContext context) { + try { + TOP_SCORE = read(1); + }catch(error){ + print('$error'); + } return Scaffold( body: Container( width: MediaQuery.of(context).size.width, height: MediaQuery.of(context).size.height, - decoration: BoxDecoration( - image: DecorationImage( - image: AssetImage("assets/pics/background-day.png"), - fit: BoxFit.fill), - ), + decoration: background(im), child: Column( children: [ Expanded(flex: 1, child: Container( diff --git a/lib/Layouts/Pages/page_settings.dart b/lib/Layouts/Pages/page_settings.dart index 6d88785..bea42bd 100644 --- a/lib/Layouts/Pages/page_settings.dart +++ b/lib/Layouts/Pages/page_settings.dart @@ -1,7 +1,9 @@ // ignore_for_file: prefer_const_constructors, sized_box_for_whitespace // ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables, avoid_unnecessary_containers -import 'package:flappy_bird/Layouts/Pages/page_share_app.dart'; +import 'package:flappy_bird/Database/database.dart'; +import 'package:flappy_bird/Layouts/Pages/page_start_screen.dart'; import 'package:flutter/material.dart'; +import '../../Constant/constant.dart'; class Settings extends StatefulWidget { const Settings({Key? key}) : super(key: key); @@ -16,11 +18,7 @@ class _SettingsState extends State { body: Container( width: MediaQuery.of(context).size.width, height: MediaQuery.of(context).size.height, - decoration: BoxDecoration( - image: DecorationImage( - image: AssetImage("assets/pics/background-day.png"), - fit: BoxFit.fill), - ), + decoration: background(im), child: Column( children: [ Expanded(flex: 1, child: Container( @@ -49,15 +47,15 @@ class _SettingsState extends State { child: Column( children: [ Text("Setting",style: TextStyle(fontSize: 35,fontFamily: "Magic4")), - SizedBox(height: 50,), + SizedBox(height: 40,), Center(child: Text("Characters",style: TextStyle(fontSize: 20,fontFamily: "Magic4")),), SizedBox(height: 10,), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - Image.asset("assets/pics/bluebird.png",width: 63,height: 60,), - Image.asset("assets/pics/bluebird.png",width: 63,height: 60,), - Image.asset("assets/pics/redbird.png",width: 63,height: 60,), + GestureDetector(onTap: (){bird = "assets/pics/bird.png";},child: Container(width: 75,height: 75,child: Image.asset("assets/pics/bird.png",fit: BoxFit.cover,))), + GestureDetector(onTap: (){bird = "assets/pics/blue.png";},child: Container(width: 75,height: 75,child: Image.asset("assets/pics/blue.png",fit: BoxFit.cover,))), + GestureDetector(onTap: (){bird = "assets/pics/greenBird.png";},child: Container(width: 75,height: 75,child: Image.asset("assets/pics/greenBird.png",fit: BoxFit.cover,))), ], ), Center(child: Text("Themes",style: TextStyle(fontSize: 20,fontFamily: "Magic4")),), @@ -65,9 +63,24 @@ class _SettingsState extends State { Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - Image.asset("assets/pics/background-day.png",width: 73,height: 70,), - Image.asset("assets/pics/background-night.png",width: 73,height: 70,), - Image.asset("assets/pics/background-after-night.png",width: 63,height: 66,), + GestureDetector(onTap: (){setState(() { + setState(() { + im = "0"; + background(im); + }); + });},child: Image.asset("assets/pics/0.png",width: 73,height: 70,)), + GestureDetector(onTap: (){setState(() { + setState(() { + im = "1"; + background(im); + }); + });},child: Image.asset("assets/pics/1.png",width: 73,height: 70,)), + GestureDetector(onTap: (){ + setState(() { + im = "2"; + background(im); + }); + },child: Image.asset("assets/pics/2.png",width: 63,height: 66,)), ], ), SizedBox(height: 20,), @@ -76,8 +89,12 @@ class _SettingsState extends State { Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - Icon(Icons.music_note_rounded,size: 40,), - Icon(Icons.music_off_rounded,size: 40), + GestureDetector(onTap: (){ + //TODO: play Music + },child: Icon(Icons.music_note_rounded,size: 40,)), + GestureDetector(onTap: (){ + //TODO: play Music + },child: Icon(Icons.music_off_rounded,size: 40)), ], ), SizedBox(height: 40,), @@ -86,9 +103,9 @@ class _SettingsState extends State { primary: Colors.cyan.shade300, ), onPressed: (){ - Navigator.push(context, MaterialPageRoute(builder: (context) => ShareApp(),),); + writeBackground(0, im); + Navigator.push(context, MaterialPageRoute(builder: (context) => StartScreen(),),); }, child: Text("Apply",style: TextStyle(fontFamily: "Magic4",fontSize: 30),) ), - ], ), ), diff --git a/lib/Layouts/Pages/page_start_screen.dart b/lib/Layouts/Pages/page_start_screen.dart index fa7d4f6..abe9e46 100644 --- a/lib/Layouts/Pages/page_start_screen.dart +++ b/lib/Layouts/Pages/page_start_screen.dart @@ -4,6 +4,7 @@ import 'package:flappy_bird/Layouts/Pages/page_share_app.dart'; import 'package:flappy_bird/Layouts/Widgets/widget_alert.dart'; import 'package:flappy_bird/Layouts/Widgets/widget_bird.dart'; import 'package:flutter/material.dart'; +import '../../Database/database.dart'; import '../Widgets/widget_Button.dart'; class StartScreen extends StatefulWidget { @@ -23,11 +24,7 @@ class _StartScreenState extends State { body: Container( width: size.width, height: size.height, - decoration: BoxDecoration( - image: DecorationImage( - image: AssetImage("assets/pics/background-day.png"), - fit: BoxFit.fill), - ), + decoration: background(im), child: Column( children: [ Expanded(flex: 3, diff --git a/lib/Layouts/Widgets/widget_bird.dart b/lib/Layouts/Widgets/widget_bird.dart index 7485e3b..c094376 100644 --- a/lib/Layouts/Widgets/widget_bird.dart +++ b/lib/Layouts/Widgets/widget_bird.dart @@ -1,33 +1,21 @@ // ignore_for_file: sized_box_for_whitespace, prefer_const_constructors, prefer_const_constructors_in_immutables, use_key_in_widget_constructors +import 'package:flappy_bird/Constant/constant.dart'; import 'package:flutter/material.dart'; -import '../../constant/constant.dart'; - class Bird extends StatelessWidget { final double yAxis; final double birdWidth; final double birdHeight; Bird(this.yAxis, this.birdWidth, this.birdHeight); - String setbird(){ - if(c==Colors.yellow){ - return"assets/pics/bird.png"; - } - else if(c==Colors.blue){ - return"assets/pics/bluebird.png"; - } - else - return"assets/pics/redbird.png"; - } @override Widget build(BuildContext context) { Size size = MediaQuery.of(context).size; return AnimatedContainer( alignment: Alignment(0, (2 * yAxis + birdHeight) / (2- birdHeight)), duration: Duration(milliseconds: 0), - child: Image.asset( - setbird(), + child: Image.asset(bird, width: size.width * birdWidth, height: size.height * birdHeight, fit: BoxFit.cover, diff --git a/lib/Layouts/Widgets/widget_menu.dart b/lib/Layouts/Widgets/widget_menu.dart deleted file mode 100644 index 2490487..0000000 --- a/lib/Layouts/Widgets/widget_menu.dart +++ /dev/null @@ -1,156 +0,0 @@ -// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables, prefer_const_constructors_in_immutables - -import 'package:dropdown_button2/dropdown_button2.dart'; -import 'package:flutter/material.dart'; - -import '../Pages/page_home.dart'; -import '../Pages/page_settings.dart'; -import '../Pages/page_share_app.dart'; - - -class Ddb2 extends StatefulWidget { - Ddb2({Key? key}) : super(key: key); - - @override - State createState() => _Ddb2State(); -} - -class _Ddb2State extends State { - @override - Widget build(BuildContext context) { - return DropdownButtonHideUnderline( - child: DropdownButton2( - customButton: Icon( - Icons.list, - size: 46, - color: Colors.white, - ), - customItemsIndexes: [3], - customItemsHeight: 8, - items: [ - ...MenuItems.firstItems.map( - (item) => DropdownMenuItem( - value: item, - child: MenuItems.buildItem(item), - ), - ), - DropdownMenuItem( - enabled: false, - child: Divider(), - ), - ...MenuItems.secondItems.map( - (item) => DropdownMenuItem( - value: item, - child: MenuItems.buildItem(item), - ), - ), - ], - onChanged: (value) { - MenuItems.onChanged(context, value as MenuItem); - }, - itemHeight: 48, - itemPadding: EdgeInsets.only(left: 16, right: 16), - dropdownWidth: 160, - dropdownPadding: EdgeInsets.symmetric(vertical: 6), - dropdownDecoration: BoxDecoration( - borderRadius: BorderRadius.circular(4), - color: Color.fromRGBO(78, 192, 202, 1), - ), - dropdownElevation: 8, - offset: Offset(0, 8), - ), - ); - } -} - -class MenuItem { - final String text; - final IconData icon; - - const MenuItem({ - required this.text, - required this.icon, - }); -} - -class MenuItems { - static const List firstItems = [play, share, settings]; - static const List secondItems = [aboutUs]; - - static const play = MenuItem(text: 'PLAY', icon: Icons.start); - static const share = MenuItem(text: 'Share', icon: Icons.share); - static const settings = MenuItem(text: 'Settings', icon: Icons.settings); - static const aboutUs = MenuItem(text: 'AboutUs', icon: Icons.info); - - static Widget buildItem(MenuItem item) { - return Row( - children: [ - Icon(item.icon, color: Colors.white, size: 22), - SizedBox( - width: 10, - ), - Text( - item.text, - style: TextStyle( - color: Colors.white, - ), - ), - ], - ); - } - - static onChanged(BuildContext context, MenuItem item) { - switch (item) { - case MenuItems.play: - Navigator.push( - context, - MaterialPageRoute(builder: (context) => HomePage()), - ); - break; - - case MenuItems.settings: - Navigator.push( - context, - MaterialPageRoute(builder: (context) => Settings()), - ); - break; - - case MenuItems.share: - Navigator.push( - context, - MaterialPageRoute(builder: (context) => ShareApp()), - ); - break; - - case MenuItems.aboutUs: - buildAboutUs(context); - break; - } - } - - static void buildAboutUs(BuildContext context) { - showDialog( - context: context, - builder: (ctx) => AlertDialog( - title: Text("About Flappy Bird"), - content: Text( - "The game is a side-scroller where the player" - " controls a bird, attempting to fly between " - " columns of green pipes without hitting them", - ), - actions: [ - TextButton( - onPressed: () { - //Navigator.of(ctx).pop(); - }, - child: Container( - color: Colors.grey, - padding: EdgeInsets.all(14), - child: Text("okay"), - ), - ), - ], - ), - ); - } -} diff --git a/lib/Layouts/Widgets/widget_score.dart b/lib/Layouts/Widgets/widget_score.dart deleted file mode 100644 index 122e6ac..0000000 --- a/lib/Layouts/Widgets/widget_score.dart +++ /dev/null @@ -1,43 +0,0 @@ -// ignore_for_file: prefer_const_literals_to_create_immutables, prefer_const_constructors, prefer_const_constructors_in_immutables -import 'package:flutter/material.dart'; -import '../../Database/database.dart'; -import '../../constant/constant.dart'; - -class Score extends StatefulWidget { - Score({Key? key}) : super(key: key); - @override - State createState() => _ScoreState(); -} - -class _ScoreState extends State { - @override - Widget build(BuildContext context) { - // TODO: update the score - try { - TOP_SCORE = read(1); - }catch(error){ - print('$error'); - } - return Container(color: Colors.brown,child: Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Column( - // Score TEXT - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text("Score",style: TextStyle(color: Colors.white,fontSize: 30,fontFamily: "Magic4"),), - SizedBox(height: 10,), - Text(SCORE.toString(),style: TextStyle(color: Colors.white,fontSize: 30,fontFamily: "Magic4")), - ],), - // Best TEXT - Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text("Best",style: TextStyle(color: Colors.white,fontSize: 30,fontFamily: "Magic4")), - SizedBox(height: 10,), - Text(TOP_SCORE.toString(),style: TextStyle(color: Colors.white,fontSize: 30,fontFamily: "Magic4")), - ],), - ], - ),); - } -} \ No newline at end of file