fish 3 months ago
parent
commit
8d9685e80c

+ 2 - 10
lib/ai/Ai.dart

@@ -1,9 +1,5 @@
 //下棋业务核心类,与界面棋盘对应,业务放在这里,可以和界面代码分离
 import 'dart:core';
-
-import 'dart:core';
-
-import 'package:gobang/bridge/ChessShape.dart';
 import 'package:gobang/flyweight/ChessFlyweightFactory.dart';
 import 'package:gobang/flyweight/Position.dart';
 
@@ -242,7 +238,6 @@ class Ai {
         humanChessmanNum = 0; //五元组中的黑棋数量
         machineChessmanNum = 0; //五元组中的白棋数量
         tupleScoreTmp = 0; //五元组得分临时变量
-
       }
     }
 
@@ -273,7 +268,6 @@ class Ai {
         humanChessmanNum = 0; //五元组中的黑棋数量
         machineChessmanNum = 0; //五元组中的白棋数量
         tupleScoreTmp = 0; //五元组得分临时变量
-
       }
     }
 
@@ -305,7 +299,6 @@ class Ai {
         humanChessmanNum = 0; //五元组中的黑棋数量
         machineChessmanNum = 0; //五元组中的白棋数量
         tupleScoreTmp = 0; //五元组得分临时变量
-
       }
     }
 
@@ -337,7 +330,6 @@ class Ai {
         humanChessmanNum = 0; //五元组中的黑棋数量
         machineChessmanNum = 0; //五元组中的白棋数量
         tupleScoreTmp = 0; //五元组得分临时变量
-
       }
     }
 
@@ -353,12 +345,12 @@ class Ai {
     }
 
     if (goalX != -1 && goalY != -1) {
-      return new Position(goalX.toDouble(), goalY.toDouble(),
+      return Position(goalX.toDouble(), goalY.toDouble(),
           ChessFlyweightFactory.getInstance().getChess(""));
     }
 
     //没找到坐标说明平局了,笔者不处理平局
-    return new Position(
+    return Position(
         -1, -1, ChessFlyweightFactory.getInstance().getChess(""));
   }
 

+ 1 - 3
lib/bridge/ChessShape.dart

@@ -1,8 +1,6 @@
-abstract class ChessShape{
+abstract class ChessShape {
   int? _shape;
-
   int get shape => _shape!;
-
   set shape(int value) {
     _shape = value;
   }

+ 1 - 0
lib/factory/BlackTheme.dart

@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
 import 'Theme.dart' as t;
 
 class BlackTheme extends t.Theme{
+  
   @override
   Color getThemeColor() {
     return Colors.black;

+ 1 - 1
lib/factory/BlackThemeFactory.dart

@@ -5,6 +5,6 @@ import 'ThemeFactory.dart';
 class BlackThemeFactory extends ThemeFactory{
   @override
   Theme getTheme() {
-    return new BlackTheme();
+    return BlackTheme();
   }
 }

+ 1 - 1
lib/factory/BlueThemeFactory.dart

@@ -5,6 +5,6 @@ import 'ThemeFactory.dart';
 class BlueThemeFactory extends ThemeFactory{
   @override
   Theme getTheme() {
-    return new BlueTheme();
+    return BlueTheme();
   }
 }

+ 0 - 1
lib/flyweight/Chess.dart

@@ -1,4 +1,3 @@
-import 'dart:ui';
 
 import 'package:flutter/material.dart';
 import 'package:gobang/bridge/ChessShape.dart';

+ 9 - 15
lib/GamePage.dart → lib/home_page.dart

@@ -3,13 +3,9 @@ import 'dart:math';
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
 import 'package:gobang/ai/Ai.dart';
-import 'package:gobang/bridge/ChessShape.dart';
 import 'package:gobang/factory/ThemeFactory.dart';
-import 'package:gobang/factory/BlueTheme.dart';
 import 'package:gobang/flyweight/Chess.dart';
-import 'package:gobang/flyweight/ChessFlyweightFactory.dart';
 import 'package:gobang/memorandum/Checkerboard.dart';
-import 'package:gobang/state/UserContext.dart';
 import 'package:gobang/utils/TipsDialog.dart';
 import 'package:gobang/viewModel/GameViewModel.dart';
 
@@ -21,12 +17,12 @@ import 'flyweight/Position.dart';
 var width = 0.0;
 
 ///简单的实现五子棋效果
-class GamePage extends StatefulWidget {
+class HomePage extends StatefulWidget {
   @override
-  State<StatefulWidget> createState() => GamePageState();
+  State<StatefulWidget> createState() => HomePageState();
 }
 
-class GamePageState extends State<GamePage> {
+class HomePageState extends State<HomePage> {
   ThemeFactory? _themeFactory;
   GameViewModel _viewModel = GameViewModel.getInstance();
   Checkerboard _originator = Checkerboard.getInstance();
@@ -47,6 +43,7 @@ class GamePageState extends State<GamePage> {
   @override
   Widget build(BuildContext context) {
     width = MediaQuery.of(context).size.width * 0.8;
+
     return Scaffold(
       appBar: AppBar(
         elevation: 0,
@@ -80,8 +77,8 @@ class GamePageState extends State<GamePage> {
         ],
       ),
       body: Container(
-        decoration: new BoxDecoration(
-            gradient: new LinearGradient(
+        decoration: BoxDecoration(
+            gradient: LinearGradient(
                 colors: [
               _themeFactory!.getTheme().getThemeColor(),
               Colors.white,
@@ -176,8 +173,7 @@ class GamePageState extends State<GamePage> {
                       IconButton(
                           onPressed: () {
                             TipsDialog.showByChoose(
-                                context, "提示", "是否重新开局?", "是", "否",
-                                (value) {
+                                context, "提示", "是否重新开局?", "是", "否", (value) {
                               if (value) {
                                 setState(() {
                                   ChessPainter._position = null;
@@ -204,7 +200,6 @@ class GamePageState extends State<GamePage> {
 
   /// Ai 下棋
   void turnAi() {
-    // print("Ai下棋");
     if (ChessPainter._position!.chess is WhiteChess &&
         Ai.getInstance().isWin(ChessPainter._position!.dx ~/ (width / 15),
             ChessPainter._position!.dy ~/ (width / 15), 1)) {
@@ -231,7 +226,6 @@ class GamePageState extends State<GamePage> {
 }
 
 class ChessPainter extends CustomPainter {
-  static int _state = 0;
   static Position? _position;
   final Function _function;
   Checkerboard _originator = Checkerboard.getInstance();
@@ -244,7 +238,7 @@ class ChessPainter extends CustomPainter {
       return;
     }
     bool add = false;
-    double mWidth = size.width / 15;
+    double mWidth = size.width / 15;   // 每行/列 15 个
     double mHeight = size.height / 15;
     var mPaint = Paint();
     //求两个点之间的距离,让棋子正确的显示在坐标轴上面
@@ -365,4 +359,4 @@ class CrossOverBean {
   double _dy;
 
   CrossOverBean(this._dx, this._dy);
-}
+}

+ 12 - 11
lib/main.dart

@@ -1,9 +1,19 @@
+import 'dart:io';
+
 import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
 
-import 'GamePage.dart';
+import 'home_page.dart';
 
 void main() {
+  WidgetsFlutterBinding.ensureInitialized();
   runApp(MyApp());
+  SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
+    statusBarColor: Colors.transparent,
+    statusBarIconBrightness: Brightness.dark,
+    systemNavigationBarColor: Colors.transparent,
+    systemNavigationBarIconBrightness: Brightness.dark,
+  ));
 }
 
 class MyApp extends StatelessWidget {
@@ -14,18 +24,9 @@ class MyApp extends StatelessWidget {
       debugShowCheckedModeBanner: false,
       title: '南瓜五子棋',
       theme: ThemeData(
-        // This is the theme of your application.
-        //
-        // Try running your application with "flutter run". You'll see the
-        // application has a blue toolbar. Then, without quitting the app, try
-        // changing the primarySwatch below to Colors.green and then invoke
-        // "hot reload" (press "r" in the console where you ran "flutter run",
-        // or simply save your changes to "hot reload" in a Flutter IDE).
-        // Notice that the counter didn't reset back to zero; the application
-        // is not restarted.
         primarySwatch: Colors.blue,
       ),
-      home: GamePage(),
+      home: HomePage(),
     );
   }
 }

+ 1 - 2
lib/memorandum/Checkerboard.dart

@@ -1,4 +1,3 @@
-import 'package:gobang/flyweight/Chess.dart';
 import 'package:gobang/flyweight/Position.dart';
 import 'package:gobang/memorandum/CareTaker.dart';
 
@@ -40,7 +39,7 @@ class Checkerboard {
   }
 
   Memo _save() {
-    return new Memo()..state.addAll(this._state);
+    return Memo()..state.addAll(this._state);
   }
 
   clean(){

+ 3 - 0
lib/routes.dart

@@ -0,0 +1,3 @@
+class Routes {
+  static const String index = "/index";
+}

+ 27 - 32
lib/utils/TipsDialog.dart

@@ -1,23 +1,21 @@
 import 'package:flutter/material.dart';
 
-class TipsDialog{
-  static show(BuildContext context,String title,tips) async {
+class TipsDialog {
+  static show(BuildContext context, String title, tips) async {
     await showDialog<Null>(
       context: context,
       barrierDismissible: false,
       builder: (BuildContext context) {
-        return new AlertDialog(
-          title: new Text(title),
-          content: new SingleChildScrollView(
-            child: new ListBody(
-              children: <Widget>[
-                Text(tips)
-              ],
+        return AlertDialog(
+          title: Text(title),
+          content: SingleChildScrollView(
+            child: ListBody(
+              children: <Widget>[Text(tips)],
             ),
           ),
           actions: <Widget>[
-            new TextButton(
-              child: new Text('确定'),
+            TextButton(
+              child: Text('确定'),
               onPressed: () {
                 Navigator.of(context).pop();
               },
@@ -28,18 +26,16 @@ class TipsDialog{
     );
   }
 
-  static wait(BuildContext context,String title,tips) async {
+  static wait(BuildContext context, String title, tips) async {
     await showDialog<Null>(
       context: context,
       barrierDismissible: false,
       builder: (BuildContext context) {
-        return new AlertDialog(
-          title: new Text(title),
-          content: new SingleChildScrollView(
-            child: new ListBody(
-              children: <Widget>[
-                Text(tips)
-              ],
+        return AlertDialog(
+          title: Text(title),
+          content: SingleChildScrollView(
+            child: ListBody(
+              children: <Widget>[Text(tips)],
             ),
           ),
         );
@@ -47,29 +43,28 @@ class TipsDialog{
     );
   }
 
-  static showByChoose(BuildContext context,String title,tips,yes,no,Function f) async {
+  static showByChoose(
+      BuildContext context, String title, tips, yes, no, Function f) async {
     await showDialog<Null>(
       context: context,
       barrierDismissible: false,
       builder: (BuildContext context) {
-        return new AlertDialog(
-          title: new Text(title),
-          content: new SingleChildScrollView(
-            child: new ListBody(
-              children: <Widget>[
-                Text(tips)
-              ],
+        return AlertDialog(
+          title: Text(title),
+          content: SingleChildScrollView(
+            child: ListBody(
+              children: <Widget>[Text(tips)],
             ),
           ),
           actions: <Widget>[
-            new TextButton(
-              child: new Text(no),
+            TextButton(
+              child: Text(no),
               onPressed: () {
                 f(false);
               },
             ),
-            new TextButton(
-              child: new Text(yes),
+            TextButton(
+              child: Text(yes),
               onPressed: () {
                 f(true);
               },
@@ -79,4 +74,4 @@ class TipsDialog{
       },
     );
   }
-}
+}

+ 6 - 6
lib/viewModel/GameViewModel.dart

@@ -1,4 +1,3 @@
-import 'package:flutter/material.dart';
 import 'package:gobang/bridge/ChessShape.dart';
 import 'package:gobang/bridge/CircleShape.dart';
 import 'package:gobang/bridge/RectShape.dart';
@@ -24,9 +23,10 @@ class GameViewModel {
   Chess play(bool current) {
     _userContext.play();
     Chess chess;
+
     /// 设置棋子外观
     ChessShape shape = RectShape();
-    if(current){
+    if (current) {
       shape = CircleShape();
     }
     chess = ChessFlyweightFactory.getInstance().getChess("white");
@@ -38,12 +38,12 @@ class GameViewModel {
     return _userContext.regretChess();
   }
 
-  get state{
-    if(_userContext.state is StartState){
+  get state {
+    if (_userContext.state is StartState) {
       return "热身阶段,不能悔棋,不能投降";
-    } else if(_userContext.state is MidState) {
+    } else if (_userContext.state is MidState) {
       return "入神阶段,可以悔棋且剩余${3 - _userContext.state.reg}次,可以投降";
-    } else if(_userContext.state is EndState) {
+    } else if (_userContext.state is EndState) {
       return "白热化阶段,悔棋次数已用完,但可以投降";
     }
   }

+ 13 - 13
pubspec.lock

@@ -37,10 +37,10 @@ packages:
     dependency: transitive
     description:
       name: collection
-      sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
+      sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "1.18.0"
+    version: "1.17.2"
   cupertino_icons:
     dependency: "direct main"
     description:
@@ -87,10 +87,10 @@ packages:
     dependency: transitive
     description:
       name: meta
-      sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
+      sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "1.10.0"
+    version: "1.9.1"
   path:
     dependency: transitive
     description:
@@ -116,18 +116,18 @@ packages:
     dependency: transitive
     description:
       name: stack_trace
-      sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
+      sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "1.11.1"
+    version: "1.11.0"
   stream_channel:
     dependency: transitive
     description:
       name: stream_channel
-      sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
+      sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "2.1.2"
+    version: "2.1.1"
   string_scanner:
     dependency: transitive
     description:
@@ -148,10 +148,10 @@ packages:
     dependency: transitive
     description:
       name: test_api
-      sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
+      sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "0.6.1"
+    version: "0.6.0"
   vector_math:
     dependency: transitive
     description:
@@ -164,9 +164,9 @@ packages:
     dependency: transitive
     description:
       name: web
-      sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
+      sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "0.3.0"
+    version: "0.1.4-beta"
 sdks:
-  dart: ">=3.2.0-194.0.dev <4.0.0"
+  dart: ">=3.1.0-185.0.dev <4.0.0"