match_magic/lib/screens/game_over_screen.dart

154 lines
5.5 KiB
Dart

import 'package:flame_audio/flame_audio.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:match_magic/db/main_db.dart';
import 'package:match_magic/game/board.dart';
import 'package:match_magic/screens/main_menu_screen.dart';
import 'package:match_magic/widgets/gradient_button.dart';
import 'package:match_magic/widgets/overlays/game_overlay/hint_button.dart';
import 'package:match_magic/widgets/overlays/game_overlay/pause_button.dart';
import 'package:match_magic/widgets/overlays/game_overlay/restart_button.dart';
class GameOverMenu extends StatelessWidget {
static const String id = 'GameOverMenu';
final Board gameRef;
GameOverMenu({
super.key,
required this.gameRef,
});
@override
Widget build(BuildContext context) {
return Stack(
children: [
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color(0xFFEBEBEB).withOpacity(0.6),
Color(0xFFBFBEC0).withOpacity(0.6),
],
),
),
),
Container(
padding: const EdgeInsets.symmetric(vertical: 70, horizontal: 16),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// Game over title.
const Padding(
padding: EdgeInsets.symmetric(vertical: 50.0),
child: Text(
'Game Over',
style: TextStyle(
fontSize: 32.0,
fontWeight: FontWeight.w800,
color: Colors.black,
shadows: [
Shadow(
blurRadius: 20.0,
color: Colors.white,
offset: Offset(0, 0),
)
],
),
),
),
Stack(
children: [
Container(
margin: EdgeInsets.symmetric(horizontal: 64),
child: Image.asset('assets/images/game_over_score.png')),
Positioned.fill(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(height: 20),
Text(
'Score: ${Board.score}',
style: TextStyle(
fontSize: 24,
color: Colors.white,
),
),
SizedBox(height: 8),
FutureBuilder<int?>(
future: MainDB.instance.getHighScoreValue(),
builder: (context, snapshot) {
if (snapshot.connectionState ==
ConnectionState.waiting) {
return CircularProgressIndicator(); //
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else if (snapshot.hasData) {
return Text(
'High score: ${snapshot.data}',
style: TextStyle(
fontSize: 16, color: Colors.white),
);
} else {
return Text('No data');
}
},
),
],
),
),
],
),
Expanded(child: SizedBox()),
Row(
children: [
Expanded(
child: GradientButton(
onPressed: () async {
// AdManager.showInterstitialAd(context, () {});
// Pause
gameRef.overlays.remove(GameOverMenu.id);
gameRef.overlays.add(PauseButton.id);
gameRef.overlays.add(RestartButton.id);
gameRef.overlays.add(HintButton.id);
gameRef.newGame();
gameRef.resumeEngine();
},
buttonText: 'Play again'),
),
],
),
SizedBox(
height: 12,
),
// Exit button.
Row(
children: [
Expanded(
child: GradientButton(
onPressed: () {
FlameAudio.bgm.stop();
gameRef.overlays.remove(GameOverMenu.id);
gameRef.removed;
gameRef.resumeEngine();
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => MainMenuScreen(),
),
);
},
buttonText: 'Exit'),
)
],
),
],
),
),
],
);
}
}