Skip to content
Snippets Groups Projects
Select Git revision
  • a74f498972b2e4b5c86f6b47d2c47fd608aa4944
  • 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
  • cell.dart 2.55 KiB
    import 'package:flutter/material.dart';
    
    import '../provider/data.dart';
    import '../utils/board_utils.dart';
    
    class Cell {
      bool isMined = false;
      bool isExplored = false;
      bool isMarked = false;
      bool isExploded = false;
      int minesCountAround = 0;
    
      Cell(
        @required this.isMined,
      );
    
      Container widget(Data myProvider, int row, int col) {
        bool showSolution = myProvider.gameWin || myProvider.gameFail;
    
        Color backgroundColor = this.getBackgroundColor(myProvider);
        String imageAsset = this.getImageAssetName(myProvider.skin, showSolution);
    
        return Container(
          decoration: BoxDecoration(
            color: backgroundColor,
            border: Border.all(
              color: Colors.grey,
              width: 1,
            ),
          ),
          child: GestureDetector(
            child: Image(
              image: AssetImage(imageAsset),
              fit: BoxFit.fill,
            ),
            onTap: () {
              if (!(myProvider.gameWin || myProvider.gameFail)) {
                if (myProvider.reportMode) {
                  BoardUtils.reportCell(myProvider, row, col);
                } else {
                  BoardUtils.walkOnCell(myProvider, row, col);
                }
              }
              BoardUtils.checkGameIsFinished(myProvider);
            },
          ),
        );
      }
    
      String getImageAssetName(String skin, bool showSolution) {
        String imageAsset = 'assets/skins/' + skin + '_tile_unknown.png';
    
        if (!showSolution) {
          // Running game
          if (this.isExplored) {
            if (this.isMined) {
              // Boom
              imageAsset = 'assets/skins/' + skin + '_tile_mine.png';
            } else {
              // Show mines count around
              imageAsset = 'assets/skins/' + skin + '_tile_' + this.minesCountAround.toString() + '.png';
            }
          } else {
            if (this.isMarked) {
              // Danger!
              imageAsset = 'assets/skins/' + skin + '_tile_flag.png';
            }
          }
        } else {
          // Finished game