123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- import 'package:battle/button/button_controller.dart';
- import 'package:battle/data/card.dart';
- import 'package:flutter/material.dart';
- import 'package:widget/widget.dart';
- import '../button/button_painter.dart';
- import 'game/count_second.dart';
- import 'summary_page.dart';
- import 'view/count_down_dialog.dart';
- class GamePage extends StatefulWidget {
- final CardItem card;
- const GamePage({
- super.key,
- required this.card,
- });
- @override
- State<GamePage> createState() => _GamePageState();
- }
- class _GamePageState extends State<GamePage> with SingleTickerProviderStateMixin {
- late GameController _controller;
- @override
- void initState() {
- super.initState();
- _controller = GameController(widget.card, vsync: this);
- _controller.addStatusListener(_listenStatus);
- }
- void _listenStatus(GameStatus status) {
- if (status == GameStatus.end) {
- if (mounted) {
- showScore(context, score: _controller.score, time: _controller.count);
- }
- }
- }
- @override
- void dispose() {
- _controller.clearStatusListener();
- _controller.dispose();
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- body: Stack(
- children: [
- Positioned.fill(
- child: ColorFiltered(
- colorFilter: const ColorFilter.matrix(<double>[
- 0.299, 0.587, 0.114, 0, 0, //r
- 0.299, 0.587, 0.114, 0, 0, //g
- 0.299, 0.587, 0.114, 0, 0, //b
- 0, 0, 0, 0.1, 0, //a
- ]),
- child: Image.asset(
- 'assets/images/background.png',
- repeat: ImageRepeat.repeat,
- cacheWidth: 182,
- cacheHeight: 52,
- ),
- ),
- ),
- Positioned.fill(
- child: SafeArea(
- top: true,
- bottom: true,
- child: Column(
- mainAxisSize: MainAxisSize.min,
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- child: Align(
- alignment: Alignment.centerRight,
- child: AnimatedBuilder(
- animation: _controller,
- builder: (_, value) {
- return CountSecond(second: Duration(seconds: _controller.count).inSeconds);
- },
- ),
- ),
- ),
- const SizedBox(height: 16),
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 40),
- child: BattleBoard(
- card: ClipRRect(
- borderRadius: BorderRadius.circular(8),
- child: Container(
- width: double.infinity,
- height: double.infinity,
- color: Colors.grey,
- child: Image.asset(
- widget.card.assetPath,
- fit: BoxFit.cover,
- ),
- ),
- ),
- button: CustomPaint(
- painter: ButtonPainter(controller: _controller),
- child: const SizedBox.expand(),
- ),
- ),
- ),
- const SizedBox(height: 32),
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- child: ButtonBar(
- alignment: MainAxisAlignment.spaceAround,
- children: [
- FilledButton(
- style: const ButtonStyle(
- fixedSize: WidgetStatePropertyAll<Size>(Size(180, 66)),
- ),
- onPressed: () {
- _controller.stop();
- showCountDown(context).then((_) {
- _controller.startOrReset();
- });
- },
- child: const Text(
- '开始/重新开始',
- style: TextStyle(
- fontSize: 18,
- ),
- ),
- ),
- ],
- ),
- ),
- ],
- ),
- ),
- ),
- ],
- ),
- );
- }
- }
|