UserContext.dart 490 B

12345678910111213141516171819202122232425262728293031323334
  1. import 'package:gobang/state/State.dart';
  2. class UserContext {
  3. late State _state;
  4. State get state => _state;
  5. UserContext(){
  6. _state = StartState(this);
  7. }
  8. play() {
  9. _state.play();
  10. }
  11. // 悔棋只能悔棋三次
  12. bool regretChess() {
  13. return _state.regretChess();
  14. }
  15. // 认输10步之内不能认输
  16. bool surrender() {
  17. return _state.surrender();
  18. }
  19. setState(State state){
  20. _state = state;
  21. }
  22. void reset() {
  23. _state = StartState(this);
  24. }
  25. }