liuyuqi-dellpc 1 year ago
parent
commit
356bdbc818

+ 0 - 0
.github/workflows/build.yml


+ 0 - 12
lib/factory/BlackThemeFactory.dart

@@ -1,12 +0,0 @@
-import 'BlackTheme.dart';
-import 'Theme.dart';
-import 'ThemeFactory.dart';
-
-class BlackThemeFactory extends ThemeFactory{
-  @override
-  Theme getTheme() {
-    return BlackTheme();
-  }
-
-  
-}

+ 0 - 10
lib/factory/BlueThemeFactory.dart

@@ -1,10 +0,0 @@
-import 'BlueTheme.dart';
-import 'Theme.dart';
-import 'ThemeFactory.dart';
-
-class BlueThemeFactory extends ThemeFactory{
-  @override
-  Theme getTheme() {
-    return BlueTheme();
-  }
-}

+ 0 - 5
lib/factory/ThemeFactory.dart

@@ -1,5 +0,0 @@
-import 'Theme.dart';
-
-abstract class ThemeFactory {
-  Theme getTheme();
-}

+ 0 - 1
lib/main.dart

@@ -1,7 +1,6 @@
 import 'package:flutter/material.dart';
 import 'package:flutter/services.dart';
 import 'package:gobang/pages/splash/splash_page.dart';
-import 'pages/home_page.dart';
 
 /// Description: enter point
 /// Time       : 02/21/2024 Wednesday

+ 3 - 5
lib/factory/BlackTheme.dart → lib/model/BlackTheme.dart

@@ -1,11 +1,9 @@
 import 'package:flutter/material.dart';
+import 'package:gobang/model/base_theme.dart';
 
-import 'Theme.dart' as t;
-
-class BlackTheme extends t.Theme{
-  
+class BlackTheme extends BaseTheme {
   @override
   Color getThemeColor() {
     return Colors.black;
   }
-}
+}

+ 3 - 4
lib/factory/BlueTheme.dart → lib/model/BlueTheme.dart

@@ -1,12 +1,11 @@
-import 'dart:ui';
 
 import 'package:flutter/material.dart';
 
-import 'Theme.dart' as t;
+import 'base_theme.dart' as t;
 
-class BlueTheme extends t.Theme{
+class BlueTheme extends t.BaseTheme {
   @override
   Color getThemeColor() {
     return Colors.blue;
   }
-}
+}

+ 2 - 2
lib/factory/Theme.dart → lib/model/base_theme.dart

@@ -1,5 +1,5 @@
 import 'dart:ui';
 
-abstract class Theme{
+abstract class BaseTheme {
   Color getThemeColor();
-}
+}

+ 13 - 10
lib/pages/home_page.dart

@@ -3,15 +3,16 @@ import 'dart:math';
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
 import 'package:gobang/ai/Ai.dart';
-import 'package:gobang/factory/ThemeFactory.dart';
 import 'package:gobang/flyweight/Chess.dart';
 import 'package:gobang/memorandum/Checkerboard.dart';
+import 'package:gobang/model/BlackTheme.dart';
+import 'package:gobang/model/BlueTheme.dart';
+import 'package:gobang/model/base_theme.dart';
 import 'package:gobang/utils/TipsDialog.dart';
 import 'package:gobang/viewModel/GameViewModel.dart';
 
 import '../bridge/CircleShape.dart';
-import '../factory/BlackThemeFactory.dart';
-import '../factory/BlueThemeFactory.dart';
+
 import '../flyweight/Position.dart';
 
 var width = 0.0;
@@ -20,12 +21,14 @@ var width = 0.0;
 /// Time       : 02/20/2024 Tuesday
 /// Author     : liuyuqi.gov@msn.cn
 class HomePage extends StatefulWidget {
+  const HomePage({Key? key}) : super(key: key);
+
   @override
   State<StatefulWidget> createState() => HomePageState();
 }
 
 class HomePageState extends State<HomePage> {
-  ThemeFactory? _themeFactory;
+  BaseTheme? _theme;
   GameViewModel _viewModel = GameViewModel.getInstance();
   Checkerboard _originator = Checkerboard.getInstance();
   Icon lightOn = Icon(Icons.lightbulb, color: Colors.amberAccent);
@@ -37,7 +40,7 @@ class HomePageState extends State<HomePage> {
   @override
   void initState() {
     currentLight = lightOn;
-    _themeFactory = BlueThemeFactory();
+    _theme = BlueTheme();
     currentShape = circle;
     super.initState();
   }
@@ -49,18 +52,18 @@ class HomePageState extends State<HomePage> {
     return Scaffold(
       appBar: AppBar(
         elevation: 0,
-        backgroundColor: _themeFactory!.getTheme().getThemeColor(),
+        backgroundColor: _theme!.getThemeColor(),
         title: Text("南瓜五子棋"),
         actions: [
           IconButton(
               onPressed: () {
                 setState(() {
-                  if (_themeFactory is BlackThemeFactory) {
+                  if (_theme is BlackTheme) {
                     currentLight = lightOn;
-                    _themeFactory = BlueThemeFactory();
+                    _theme = BlueTheme();
                   } else {
                     currentLight = lightOff;
-                    _themeFactory = BlackThemeFactory();
+                    _theme = BlackTheme();
                   }
                 });
               },
@@ -82,7 +85,7 @@ class HomePageState extends State<HomePage> {
         decoration: BoxDecoration(
             gradient: LinearGradient(
                 colors: [
-              _themeFactory!.getTheme().getThemeColor(),
+              _theme!.getThemeColor(),
               Colors.white,
             ],
                 stops: [

+ 14 - 17
lib/state/State.dart

@@ -9,7 +9,7 @@ abstract class State {
   int get reg => _reg;
   UserContext _userContext;
 
-  State(UserContext userContext):_userContext = userContext;
+  State(UserContext userContext) : _userContext = userContext;
 
   // 悔棋只能悔棋三次
   bool regretChess();
@@ -20,17 +20,15 @@ abstract class State {
   play() {
     _step++;
   }
-
 }
 
 /// [StartState] 开始状态
 class StartState extends State {
-
   StartState(UserContext userContext) : super(userContext);
 
   // 悔棋只能悔棋三次
   @override
-  bool regretChess(){
+  bool regretChess() {
     return false;
   }
 
@@ -42,11 +40,12 @@ class StartState extends State {
   @override
   play() {
     super.play();
-    if(_step >= 4) {
-      _userContext.setState(MidState(_userContext).._step = _step.._reg = _reg);
+    if (_step >= 4) {
+      _userContext.setState(MidState(_userContext)
+        .._step = _step
+        .._reg = _reg);
     }
   }
-
 }
 
 /// [MidState] 中场状态
@@ -54,17 +53,19 @@ class MidState extends State {
   MidState(UserContext userContext) : super(userContext);
 
   @override
-  int get _reg{
+  int get _reg {
     return super._reg;
   }
 
   // 悔棋只能悔棋三次
   @override
-  bool regretChess(){
+  bool regretChess() {
     _reg++;
-    if(_reg == 3) {
+    if (_reg == 3) {
       print('切换到白热化阶段');
-      _userContext.setState(EndState(_userContext).._step = _step.._reg = _reg);
+      _userContext.setState(EndState(_userContext)
+        .._step = _step
+        .._reg = _reg);
     }
     return true;
   }
@@ -73,18 +74,15 @@ class MidState extends State {
   bool surrender() {
     return true;
   }
-
 }
 
 /// [EndState] 结尾状态
 class EndState extends State {
   EndState(UserContext userContext) : super(userContext);
 
-
-
   // 悔棋只能悔棋三次
   @override
-  regretChess(){
+  regretChess() {
     return false;
   }
 
@@ -92,5 +90,4 @@ class EndState extends State {
   surrender() {
     return true;
   }
-
-}
+}

+ 6 - 2
pubspec.yaml

@@ -9,11 +9,15 @@ dependencies:
   flutter:
     sdk: flutter
   cupertino_icons: ^1.0.5
-
+  # dio: ^4.0.0
+  # provider: ^5.0.0
+  # shared_preferences: ^2.0.6
+  # fluttertoast: ^8.0.7
+  
 dev_dependencies:
   flutter_test:
     sdk: flutter
 flutter:
   uses-material-design: true
   assets:
-    - assets/images/
+    - assets/images/