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

settings_global_cubit.dart

Blame
  • board.dart 1.67 KiB
    import 'dart:math';
    
    import 'package:flutter_custom_toolbox/flutter_toolbox.dart';
    
    import 'package:jeweled/models/activity/cell.dart';
    import 'package:jeweled/models/settings/settings_activity.dart';
    
    class Board {
      final List<List<Cell>> cells;
    
      Board({
        required this.cells,
      });
    
      factory Board.createEmpty() {
        return Board(cells: []);
      }
    
      factory Board.createRandom(ActivitySettings activitySettings) {
        final int boardSizeHorizontal = activitySettings.boardSizeValue;
        final int boardSizeVertical = activitySettings.boardSizeValue;
        final int maxValue = activitySettings.colorsCountValue;
    
        final rand = Random();
    
        List<List<Cell>> cells = [];
        for (int rowIndex = 0; rowIndex < boardSizeVertical; rowIndex++) {
          List<Cell> row = [];
          for (int colIndex = 0; colIndex < boardSizeHorizontal; colIndex++) {
            int value = 1 + rand.nextInt(maxValue);
            row.add(Cell(value));
          }
          cells.add(row);
        }
    
        return Board(
          cells: cells,
        );
      }
    
      void dump() {
        String horizontalRule = '----';
        for (int i = 0; i < cells[0].length; i++) {
          horizontalRule += '-';
        }
    
        printlog('Board:');
        printlog(horizontalRule);
    
        for (int rowIndex = 0; rowIndex < cells.length; rowIndex++) {
          String row = '| ';
          for (int colIndex = 0; colIndex < cells[rowIndex].length; colIndex++) {
            row += cells[rowIndex][colIndex].value.toString();
          }
          row += ' |';
    
          printlog(row);
        }
    
        printlog(horizontalRule);
      }
    
      @override
      String toString() {
        return 'Board(${toJson()})';
      }
    
      Map<String, dynamic>? toJson() {
        return <String, dynamic>{
          'cells': cells.toString(),