play.dart 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import 'package:flutter/material.dart';
  2. import 'chess.dart';
  3. import 'play_step.dart';
  4. import 'play_single_player.dart';
  5. import 'play_bot.dart';
  6. import 'play_player.dart';
  7. import '../global.dart';
  8. import '../widgets/tab_card.dart';
  9. import '../models/game_manager.dart';
  10. import '../models/play_mode.dart';
  11. import '../driver/player_driver.dart';
  12. /// 游戏布局框
  13. class PlayPage extends StatefulWidget {
  14. final PlayMode mode;
  15. const PlayPage({Key? key, required this.mode}) : super(key: key);
  16. @override
  17. State<StatefulWidget> createState() => PlayPageState();
  18. }
  19. class PlayPageState extends State<PlayPage> {
  20. final GameManager gamer = GameManager.instance;
  21. bool inited = false;
  22. @override
  23. void initState() {
  24. super.initState();
  25. }
  26. void initGame() async {
  27. if (inited) return;
  28. inited = true;
  29. gamer.newGame();
  30. if (widget.mode == PlayMode.modeRobot) {
  31. gamer.switchDriver(1, DriverType.robot);
  32. }
  33. gamer.next();
  34. }
  35. @override
  36. void dispose() {
  37. super.dispose();
  38. }
  39. @override
  40. Widget build(BuildContext context) {
  41. initGame();
  42. return MediaQuery.of(context).size.width < 980
  43. ? _mobileContainer()
  44. : _windowContainer();
  45. }
  46. Widget _mobileContainer() {
  47. return Column(
  48. mainAxisAlignment: MainAxisAlignment.spaceAround,
  49. children: [
  50. const PlaySinglePlayer(
  51. team: 1,
  52. ),
  53. SizedBox(
  54. width: gamer.skin.width * gamer.scale,
  55. height: gamer.skin.height * gamer.scale,
  56. child: const Chess(),
  57. ),
  58. const PlaySinglePlayer(
  59. team: 0,
  60. placeAt: Alignment.bottomCenter,
  61. ),
  62. ],
  63. );
  64. }
  65. Widget _windowContainer() {
  66. BoxDecoration decoration = BoxDecoration(
  67. border: Border.all(color: Colors.grey, width: 0.5),
  68. borderRadius: const BorderRadius.all(Radius.circular(2)),
  69. );
  70. return SizedBox(
  71. width: 980,
  72. height: 577,
  73. child: Row(
  74. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  75. crossAxisAlignment: CrossAxisAlignment.start,
  76. mainAxisSize: MainAxisSize.max,
  77. children: [
  78. const SizedBox(
  79. width: 521,
  80. child: Chess(),
  81. ),
  82. Container(
  83. width: 439,
  84. padding: const EdgeInsets.all(10),
  85. decoration: const BoxDecoration(
  86. color: Colors.white,
  87. borderRadius: BorderRadius.all(Radius.circular(2)),
  88. boxShadow: [
  89. BoxShadow(
  90. color: Color.fromRGBO(0, 0, 0, .1),
  91. offset: Offset(1, 1),
  92. blurRadius: 1.0,
  93. spreadRadius: 1.0,
  94. )
  95. ],
  96. ),
  97. child: Column(
  98. mainAxisSize: MainAxisSize.max,
  99. children: [
  100. Expanded(
  101. child: Row(
  102. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  103. children: [
  104. const PlayPlayer(),
  105. const SizedBox(width: 10),
  106. PlayStep(
  107. decoration: decoration,
  108. width: 180,
  109. ),
  110. ],
  111. ),
  112. ),
  113. const SizedBox(height: 10),
  114. Container(
  115. height: 180,
  116. decoration: decoration,
  117. child: TabCard(
  118. titleFit: FlexFit.tight,
  119. titlePadding: const EdgeInsets.symmetric(
  120. vertical: 10,
  121. horizontal: 30,
  122. ),
  123. titles: [
  124. Text(context.l10n.recommendMove),
  125. Text(context.l10n.remark)
  126. ],
  127. bodies: [
  128. const PlayBot(),
  129. Center(
  130. child: Text(context.l10n.noRemark),
  131. )
  132. ],
  133. ),
  134. )
  135. ],
  136. ),
  137. ),
  138. ],
  139. ),
  140. );
  141. }
  142. }