Skip to content
Snippets Groups Projects
Select Git revision
  • 5b8fca201e5e4154b9391760d6bba22f65a699a8
  • master default protected
  • 100-upgrade-framework-and-dependencies
  • 65-improve-app-metadata
  • Release_1.8.0_80 protected
  • Release_1.7.2_79 protected
  • Release_1.7.1_78 protected
  • Release_1.7.0_77 protected
  • Release_1.6.0_76 protected
  • Release_1.5.0_75 protected
  • Release_1.4.0_74 protected
  • Release_1.3.2_73 protected
  • Release_1.3.1_72 protected
  • Release_1.3.0_71 protected
  • Release_1.2.1_70 protected
  • Release_1.2.0_69 protected
  • Release_1.1.3_68 protected
  • Release_1.1.2_67 protected
  • Release_1.1.1_66 protected
  • Release_1.1.0_65 protected
  • Release_1.0.63_64 protected
  • Release_1.0.62_63 protected
  • Release_1.0.61_62 protected
  • Release_1.0.60_61 protected
24 results

AppDelegate.h

Blame
  • board_utils.dart 6.76 KiB
    import '../entities/cell.dart';
    import '../provider/data.dart';
    
    class BoardUtils {
    
      static printGrid(List cells) {
        final String IS_MINED = 'X';
        final String IS_SAFE = '.';
    
        final String MINE_FOUND = '#';
        final String WRONG_MARKED_CELL = '0';
        final String EXPLORED_SAFE_CELL = '.';
        final String UNKNOWN_STATE = ' ';
    
        print('');
        String line = '--';
        for (var i = 0; i < cells[0].length; i++) {
          line += '-';
        }
        print(line + '  ' + line);
        for (var rowIndex = 0; rowIndex < cells.length; rowIndex++) {
          String currentLine = '';
          String solvedLine = '';
          for (var colIndex = 0; colIndex < cells[rowIndex].length; colIndex++) {
            solvedLine += cells[rowIndex][colIndex].isMined ? IS_MINED : IS_SAFE;
    
            String cellString = UNKNOWN_STATE;
            if (cells[rowIndex][colIndex].isExplored) {
              cellString = EXPLORED_SAFE_CELL;
            }
            if (cells[rowIndex][colIndex].isMarked) {
              if (cells[rowIndex][colIndex].isMined) {
                cellString = MINE_FOUND;
              } else {
                cellString = WRONG_MARKED_CELL;
              }
            }
            currentLine += cellString;
          }
          print('|' + currentLine + '|  |' + solvedLine + '|');
        }
        print(line + '  ' + line);
        print('');
      }
    
      static List createEmptyBoard(int sizeHorizontal, int sizeVertical) {
        int index = 0;
        List cells = [];
        for (var rowIndex = 0; rowIndex < sizeVertical; rowIndex++) {
          List row = [];
          for (var colIndex = 0; colIndex < sizeHorizontal; colIndex++) {
            row.add(Cell(false));
          }
          cells.add(row);
        }
    
        return cells;
      }
    
      static int getMinesCount(int sizeHorizontal, int sizeVertical, String level) {
        int minesCountRatio = 0;
        switch(level) {
          case 'easy': {
            minesCountRatio = 5;
          }
          break;
          case 'medium': {
            minesCountRatio = 10;
          }
          break;