Skip to content
Snippets Groups Projects
Select Git revision
  • 56d02932ce0849276f479b7db2d8bc3f2b21a030
  • master default protected
  • 61-upgrade-framework-and-dependencies
  • 44-improve-app-metadata
  • Release_0.10.0_57 protected
  • Release_0.9.2_56 protected
  • Release_0.9.1_55 protected
  • Release_0.9.0_54 protected
  • Release_0.8.0_53 protected
  • Release_0.7.0_52 protected
  • Release_0.6.0_51 protected
  • Release_0.5.3_50 protected
  • Release_0.5.2_49 protected
  • Release_0.5.1_48 protected
  • Release_0.5.0_47 protected
  • Release_0.4.1_46 protected
  • Release_0.4.0_45 protected
  • Release_0.3.1_44 protected
  • Release_0.3.0_43 protected
  • Release_0.2.1_42 protected
  • Release_0.2.0_41 protected
  • Release_0.1.19_40 protected
  • Release_0.1.18_39 protected
  • Release_0.1.17_38 protected
24 results

board_animate.dart

Blame
  • board.dart 3.36 KiB
    import 'package:flutter/material.dart';
    
    import '../provider/data.dart';
    import '../utils/game_utils.dart';
    
    class Board {
      static Container buildGameBoard(Data myProvider) {
        String skin = myProvider.skin;
    
        int maxGuessesCount = myProvider.maxGuessesCount;
        int wordLength = int.parse(myProvider.length);
    
        Widget buildCellWidget(
            String cellValue, String cellTip, bool hasFocus, String foundLetter) {
          Color textColor = Colors.white;
          Color focusBorderColor = Colors.yellow.shade700;
          Color defaultBorderColor = Colors.white;
    
          String cellImage = 'empty';
          if (cellTip != '') {
            cellImage = cellTip;
          }
    
          if ((foundLetter != ' ') && (cellValue == ' ')) {
            cellValue = foundLetter;
            cellImage = 'good';
          }
    
          Image imageWidget = Image(
            image: AssetImage('assets/skins/' + skin + '_' + cellImage + '.png'),
            fit: BoxFit.fill,
          );
    
          Widget cellBackground = Container(
            decoration: BoxDecoration(
              border: Border.all(
                width: 4.0,
                color: hasFocus ? focusBorderColor : defaultBorderColor,
                style: BorderStyle.solid,
              ),
            ),
            child: imageWidget,
          );
    
          Text textWidget = Text(
            cellValue,
            style: TextStyle(
              color: textColor,
              fontSize: 40.0,
              fontWeight: FontWeight.w900,
            ),
            textAlign: TextAlign.center,
          );
    
          return Stack(
            alignment: Alignment.center,
            children: <Widget>[
              cellBackground,
              Center(child: textWidget),
            ],
          );
        }
    
        List<String> guesses = myProvider.guesses;
    
        List<TableRow> tableRows = [];
        for (int lineIndex = 0; lineIndex < maxGuessesCount; lineIndex++) {
          String word = '';
          if (lineIndex < guesses.length) {
            word = guesses[lineIndex];
          } else if (lineIndex == guesses.length) {
            word = myProvider.currentGuess;
          }
    
          List<String> tips = GameUtils.getTips(myProvider, word);
    
          List<TableCell> tableCells = [];
          for (int colIndex = 0; colIndex < wordLength; colIndex++) {
            String cellValue = ' ';
            if (word.length > colIndex) {
              cellValue = word[colIndex];
            }
    
            String cellTip = '';
            if (lineIndex < guesses.length) {
              cellTip = tips[colIndex];
            }
    
            bool hasFocus = (!myProvider.gameWon) &&
                (lineIndex == guesses.length) &&
                (colIndex == word.length);
    
            String foundLetter = ((!myProvider.gameWon) && (lineIndex == guesses.length))
                ? myProvider.foundLetters.substring(colIndex, colIndex + 1)
                : ' ';
    
            tableCells.add(TableCell(
              child: buildCellWidget(cellValue, cellTip, hasFocus, foundLetter),
            ));
          }
    
          tableRows.add(TableRow(children: tableCells));
        }
    
        double horizontalMargins = 20;
        if (wordLength < 6) {
          horizontalMargins = 40;
          if (wordLength < 5) {
            horizontalMargins = 60;
          }
        }
    
        return Container(
          margin: EdgeInsets.symmetric(horizontal: horizontalMargins),
          padding: EdgeInsets.all(2),
          child: Table(
            defaultVerticalAlignment: TableCellVerticalAlignment.middle,
            border: TableBorder.all(
              color: Colors.white,
              style: BorderStyle.none,
            ),
            children: tableRows,
          ),
        );
      }
    }