Skip to content
Snippets Groups Projects
Select Git revision
  • 62756e34083d60c42554b463cd51966ce570ce75
  • master default protected
  • 101-upgrade-framework-and-dependencies
  • 84-improve-app-metadata
  • 82-fix-colors
  • 23-add-timer
  • 65-update-icons
  • 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
  • Release_0.1.21_70 protected
  • Release_0.1.20_69 protected
  • Release_0.1.19_68 protected
27 results

AppDelegate.h

Blame
  • game_utils.dart 3.01 KiB
    import '../provider/data.dart';
    import '../utils/random_pick_word.dart';
    
    class GameUtils {
      static Future<void> quitGame(Data myProvider) async {
        myProvider.updateGameIsRunning(false);
      }
    
      static Future<void> startGame(Data myProvider) async {
        print('Starting game (${myProvider.lang} / ${myProvider.length} / ${myProvider.level} )');
    
        myProvider.resetGame();
    
        await pickWord(myProvider);
    
        myProvider.updateGameIsRunning(true);
      }
    
      static Future<void> pickWord(Data myProvider) async {
        RandomPickWord randomPickWord;
        String word = '';
    
        int attempts = 0;
        do {
          randomPickWord = RandomPickWord();
          int wordLength = int.parse(myProvider.length);
          await randomPickWord.init(myProvider.lang, wordLength, myProvider.level);
    
          if (randomPickWord.word != '') {
            word = randomPickWord.word;
          }
          attempts++;
    
          if ((word != '') && !myProvider.isRecentlyPicked(word)) {
            myProvider.updateWord(word);
          }
        } while (myProvider.word != word && attempts < 10);
    
        print('Picked word: $word');
      }
    
      static void addLetter(Data myProvider, String letter) {
        myProvider.currentGuessAddLetter(letter);
      }
    
      static void removeLetter(Data myProvider) {
        myProvider.currentGuessRemoveLetter();
      }
    
      static List<String> getTips(Data myProvider, String candidate) {
        String word = myProvider.word;
        int wordLength = int.parse(myProvider.length);
    
        List<String> tips = List<String>.filled(wordLength, '', growable: false);
    
        if ((word.length != wordLength) ||
            (candidate.length != wordLength) ||
            (!RandomPickWord.checkWordExists(candidate))) {
          return List<String>.filled(wordLength, 'wrong', growable: false);
        }
    
        String replaceCharAt(String oldString, int index, String newChar) {
          return oldString.substring(0, index) + newChar + oldString.substring(index + 1);
        }
    
        // Check correctly placed letters
        for (int i = 0; i < wordLength; i++) {
          if ((tips[i] == '') && (word[i] == candidate[i])) {
            myProvider.addFoundLetter(word[i], i);
            word = replaceCharAt(word, i, ' ');