status_panel.dart 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. import 'package:tetris/gamer/block.dart';
  4. import 'package:tetris/gamer/gamer.dart';
  5. import 'package:tetris/generated/i18n.dart';
  6. import 'package:tetris/material/briks.dart';
  7. import 'package:tetris/material/images.dart';
  8. class StatusPanel extends StatelessWidget {
  9. @override
  10. Widget build(BuildContext context) {
  11. return Container(
  12. padding: const EdgeInsets.all(8),
  13. child: Column(
  14. crossAxisAlignment: CrossAxisAlignment.start,
  15. children: <Widget>[
  16. Text(S.of(context).points,
  17. style: TextStyle(fontWeight: FontWeight.bold)),
  18. SizedBox(height: 4),
  19. Number(number: GameState.of(context).points),
  20. SizedBox(height: 10),
  21. Text(S.of(context).cleans,
  22. style: TextStyle(fontWeight: FontWeight.bold)),
  23. SizedBox(height: 4),
  24. Number(number: GameState.of(context).cleared),
  25. SizedBox(height: 10),
  26. Text(S.of(context).level,
  27. style: TextStyle(fontWeight: FontWeight.bold)),
  28. SizedBox(height: 4),
  29. Number(number: GameState.of(context).level),
  30. SizedBox(height: 10),
  31. Text(S.of(context).next,
  32. style: TextStyle(fontWeight: FontWeight.bold)),
  33. SizedBox(height: 4),
  34. _NextBlock(),
  35. Spacer(),
  36. _GameStatus(),
  37. ],
  38. ),
  39. );
  40. }
  41. }
  42. class _NextBlock extends StatelessWidget {
  43. @override
  44. Widget build(BuildContext context) {
  45. List<List<int>> data = [List.filled(4, 0), List.filled(4, 0)];
  46. final next = BLOCK_SHAPES[GameState.of(context).next.type];
  47. for (int i = 0; i < next.length; i++) {
  48. for (int j = 0; j < next[i].length; j++) {
  49. data[i][j] = next[i][j];
  50. }
  51. }
  52. return Column(
  53. children: data.map((list) {
  54. return Row(
  55. children: list.map((b) {
  56. return b == 1 ? const Brik.normal() : const Brik.empty();
  57. }).toList(),
  58. );
  59. }).toList(),
  60. );
  61. }
  62. }
  63. class _GameStatus extends StatefulWidget {
  64. @override
  65. _GameStatusState createState() {
  66. return _GameStatusState();
  67. }
  68. }
  69. class _GameStatusState extends State<_GameStatus> {
  70. Timer _timer;
  71. bool _colonEnable = true;
  72. int _minute;
  73. int _hour;
  74. @override
  75. void initState() {
  76. super.initState();
  77. _timer = Timer.periodic(const Duration(seconds: 1), (timer) {
  78. final now = DateTime.now();
  79. setState(() {
  80. _colonEnable = !_colonEnable;
  81. _minute = now.minute;
  82. _hour = now.hour;
  83. });
  84. });
  85. }
  86. @override
  87. void dispose() {
  88. _timer?.cancel();
  89. super.dispose();
  90. }
  91. @override
  92. Widget build(BuildContext context) {
  93. return Row(
  94. children: <Widget>[
  95. IconSound(enable: GameState.of(context).muted),
  96. SizedBox(width: 4),
  97. IconPause(enable: GameState.of(context).states == GameStates.paused),
  98. Spacer(),
  99. Number(number: _hour, length: 2, padWithZero: true),
  100. IconColon(enable: _colonEnable),
  101. Number(number: _minute, length: 2, padWithZero: true),
  102. ],
  103. );
  104. }
  105. }