Skip to content
Snippets Groups Projects
Select Git revision
  • 48f25e351686878bc69e5e8f24173a9f581f6a2b
  • master default protected
  • 104-add-hard-grids
  • 84-improve-app-metadata
  • 82-fix-colors
  • 23-add-timer
  • 65-update-icons
  • Release_0.10.3_90 protected
  • Release_0.10.2_89 protected
  • Release_0.10.1_88 protected
  • Release_0.10.0_87 protected
  • Release_0.9.2_86 protected
  • Release_0.9.1_85 protected
  • Release_0.9.0_84 protected
  • Release_0.8.0_83 protected
  • Release_0.7.0_82 protected
  • Release_0.6.0_81 protected
  • Release_0.5.2_80 protected
  • Release_0.5.1_79 protected
  • Release_0.5.0_78 protected
  • Release_0.4.1_77 protected
  • Release_0.4.0_76 protected
  • Release_0.3.1_75 protected
  • Release_0.3.0_74 protected
  • Release_0.2.1_73 protected
  • Release_0.2.0_72 protected
  • Release_0.1.22_71 protected
27 results

game_cubit.dart

Blame
  • game_cubit.dart 4.22 KiB
    import 'dart:async';
    import 'dart:math';
    
    import 'package:equatable/equatable.dart';
    import 'package:flutter/material.dart';
    import 'package:hydrated_bloc/hydrated_bloc.dart';
    import 'package:sudoku/config/default_global_settings.dart';
    import 'package:sudoku/models/cell.dart';
    
    import 'package:sudoku/models/cell_location.dart';
    import 'package:sudoku/models/game.dart';
    import 'package:sudoku/models/settings_game.dart';
    import 'package:sudoku/models/settings_global.dart';
    import 'package:sudoku/utils/board_animate.dart';
    
    part 'game_state.dart';
    
    class GameCubit extends HydratedCubit<GameState> {
      GameCubit()
          : super(GameState(
              game: Game.createNull(),
            ));
    
      void updateState(Game game) {
        emit(GameState(
          game: game,
        ));
      }
    
      void refresh() {
        updateState(Game(
          gameSettings: state.game.gameSettings,
          globalSettings: state.game.globalSettings,
          board: state.game.board,
          solvedBoard: state.game.solvedBoard,
          isRunning: state.game.isRunning,
          isFinished: state.game.isFinished,
          blockSizeHorizontal: state.game.blockSizeHorizontal,
          blockSizeVertical: state.game.blockSizeVertical,
          boardSize: state.game.boardSize,
          shuffledCellValues: state.game.shuffledCellValues,
          boardConflicts: state.game.boardConflicts,
          selectedCell: state.game.selectedCell,
          showConflicts: state.game.showConflicts,
          givenTipsCount: state.game.givenTipsCount,
          buttonTipsCountdown: state.game.buttonTipsCountdown,
          animationInProgress: state.game.animationInProgress,
          boardAnimated: state.game.boardAnimated,
        ));
      }
    
      void startNewGame({
        required GameSettings gameSettings,
        required GlobalSettings globalSettings,
      }) {
        final Game newGame = Game.createNew(
          gameSettings: gameSettings,
          globalSettings: globalSettings,
        );
    
        newGame.dump();
    
        updateState(newGame);
        refresh();
    
        BoardAnimate.startAnimation(this, 'start');
      }
    
      void selectCell(CellLocation location) {
        state.game.selectedCell = state.game.board.get(location);