Chess.dart 714 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import 'package:flutter/material.dart';
  2. import 'package:gobang/bridge/ChessShape.dart';
  3. /// 棋子的抽象类
  4. /// 使用了桥接模式,外观和颜色是两个不同的维度
  5. abstract class Chess{
  6. Color? _color;
  7. Color get color => _color!;
  8. ChessShape? _chessShape;
  9. ChessShape get chessShape => _chessShape!;
  10. set chessShape(ChessShape? __chessShape);
  11. }
  12. class BlackChess extends Chess{
  13. BlackChess() {
  14. _color = Colors.black;
  15. }
  16. set chessShape(ChessShape? __chessShape) {
  17. super._chessShape = __chessShape;
  18. }
  19. }
  20. class WhiteChess extends Chess{
  21. WhiteChess() {
  22. _color = Colors.white;
  23. }
  24. set chessShape(ChessShape? __chessShape) {
  25. super._chessShape = __chessShape;
  26. }
  27. }