123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- import 'dart:async';
- import 'package:flutter/material.dart';
- import 'package:tetris/gamer/block.dart';
- import 'package:tetris/gamer/gamer.dart';
- import 'package:tetris/generated/l10n.dart';
- import 'package:tetris/material/briks.dart';
- import 'package:tetris/material/images.dart';
- class StatusPanel extends StatelessWidget {
- const StatusPanel({super.key});
- @override
- Widget build(BuildContext context) {
- return Container(
- padding: const EdgeInsets.all(8),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Text(S.of(context).points,
- style: const TextStyle(fontWeight: FontWeight.bold)),
- const SizedBox(height: 4),
- Number(number: GameState.of(context).points),
- const SizedBox(height: 10),
- Text(S.of(context).cleans,
- style: const TextStyle(fontWeight: FontWeight.bold)),
- const SizedBox(height: 4),
- Number(number: GameState.of(context).cleared),
- const SizedBox(height: 10),
- Text(S.of(context).level,
- style: const TextStyle(fontWeight: FontWeight.bold)),
- const SizedBox(height: 4),
- Number(number: GameState.of(context).level),
- const SizedBox(height: 10),
- Text(S.of(context).next,
- style: const TextStyle(fontWeight: FontWeight.bold)),
- const SizedBox(height: 4),
- _NextBlock(),
- const Spacer(),
- _GameStatus(),
- ],
- ),
- );
- }
- }
- class _NextBlock extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- List<List<int>> data = [List.filled(4, 0), List.filled(4, 0)];
- final next = blockShapes[GameState.of(context).next.type]!;
- for (int i = 0; i < next.length; i++) {
- for (int j = 0; j < next[i].length; j++) {
- data[i][j] = next[i][j];
- }
- }
- return Column(
- children: data.map((list) {
- return Row(
- children: list.map((b) {
- return b == 1 ? const Brik.normal() : const Brik.empty();
- }).toList(),
- );
- }).toList(),
- );
- }
- }
- class _GameStatus extends StatefulWidget {
- @override
- _GameStatusState createState() {
- return _GameStatusState();
- }
- }
- class _GameStatusState extends State<_GameStatus> {
- Timer? _timer;
- bool _colonEnable = true;
- int _minute = 0;
- int _hour = 0;
- @override
- void initState() {
- super.initState();
- _timer = Timer.periodic(const Duration(seconds: 1), (timer) {
- final now = DateTime.now();
- setState(() {
- _colonEnable = !_colonEnable;
- _minute = now.minute;
- _hour = now.hour;
- });
- });
- }
- @override
- void dispose() {
- _timer?.cancel();
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- return Row(
- children: <Widget>[
- IconSound(enable: GameState.of(context).muted),
- const SizedBox(width: 4),
- IconPause(enable: GameState.of(context).states == GameStates.paused),
- const Spacer(),
- Number(number: _hour, length: 2, padWithZero: true),
- IconColon(enable: _colonEnable),
- Number(number: _minute, length: 2, padWithZero: true),
- ],
- );
- }
- }
|