Skip to content
Snippets Groups Projects
Select Git revision
  • 93a028e2318ba11bc8b803c1c11b7dedf5f788b3
  • master default protected
  • 21-improve-app-metadata
  • Release_0.9.2_42 protected
  • Release_0.9.1_41 protected
  • Release_0.9.0_40 protected
  • Release_0.8.2_39 protected
  • Release_0.8.1_38 protected
  • Release_0.8.0_37 protected
  • Release_0.7.0_36 protected
  • Release_0.6.0_35 protected
  • Release_0.5.0_34 protected
  • Release_0.4.2_33 protected
  • Release_0.4.1_32 protected
  • Release_0.4.0_31 protected
  • Release_0.3.1_30 protected
  • Release_0.3.0_29 protected
  • Release_0.2.1_28 protected
  • Release_0.2.0_27 protected
  • Release_0.1.2_26 protected
  • Release_0.1.1_25 protected
  • Release_0.1.0_24 protected
  • Release_0.0.23_23 protected
23 results

game_state.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);