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