Skip to content
Snippets Groups Projects
Commit a509302a authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Remove debug, clean some code

parent 00960f90
No related branches found
No related tags found
1 merge request!7Resolve "Remove debug"
Pipeline #3583 passed
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
app.versionName=0.0.21
app.versionCode=21
app.versionName=0.0.22
app.versionCode=22
Remove debug, clean some code
Suppression d'écritures de debug, nettoyage de code
......@@ -77,11 +77,8 @@ class Data extends ChangeNotifier {
void currentGuessSubmitWord() {
if (_currentGuess.length == int.parse(_length)) {
print('check word: ' + _currentGuess);
if (_currentGuess != _word) {
print('wrong');
} else {
print('ok found');
if (_currentGuess == _word) {
print('Word found!');
_foundWord = true;
}
addGuess(_currentGuess);
......@@ -90,13 +87,11 @@ class Data extends ChangeNotifier {
}
void currentGuessSubmitWrongWord() {
print('Adding unknown word');
addGuess(_currentGuess);
notifyListeners();
}
void addGuess(String word) {
print('addGuess(' + word + ')');
_guesses.add(word);
_currentGuess = '';
}
......@@ -108,7 +103,6 @@ class Data extends ChangeNotifier {
void addFoundLetter(String letter, int i) {
_foundLetters = _foundLetters.substring(0, i) + letter + _foundLetters.substring(i + 1);
print('Found a "' + letter + '" => "' + _foundLetters + '".');
}
bool get gameWon => _foundWord;
......
......@@ -7,9 +7,13 @@ class GameUtils {
}
static Future<void> startGame(Data myProvider) async {
print('Starting game');
print('- lang: ' + myProvider.lang);
print('- length: ' + myProvider.length);
print('Starting game (' +
myProvider.lang +
' / ' +
myProvider.length +
' / ' +
myProvider.level +
' )');
myProvider.resetGame();
......@@ -41,16 +45,12 @@ class GameUtils {
print('Picked word: ' + word);
}
static bool addLetter(Data myProvider, String letter) {
print('addLetter: ' + letter);
static void addLetter(Data myProvider, String letter) {
myProvider.currentGuessAddLetter(letter);
return true;
}
static bool removeLetter(Data myProvider) {
print('removeLetter');
static void removeLetter(Data myProvider) {
myProvider.currentGuessRemoveLetter();
return true;
}
static List<String> getTips(Data myProvider, String candidate) {
......@@ -69,13 +69,9 @@ class GameUtils {
return oldString.substring(0, index) + newChar + oldString.substring(index + 1);
}
print('getTips: candidate "' + candidate + '" / word "' + word + '"');
// Check correctly placed letters
print('Check correctly placed letters');
for (int i = 0; i < wordLength; i++) {
if ((tips[i] == '') && (word[i] == candidate[i])) {
print('Found "' + word[i] + '" on the right place: ' + (i + 1).toString());
myProvider.addFoundLetter(word[i], i);
word = replaceCharAt(word, i, ' ');
candidate = replaceCharAt(candidate, i, ' ');
......@@ -84,16 +80,9 @@ class GameUtils {
}
// Check misplaced letters
print('Check misplaced letters');
for (int i = 0; i < wordLength; i++) {
for (int j = 0; j < wordLength; j++) {
if ((candidate[j] != ' ') && (candidate[j] == word[i])) {
print('Found "' +
candidate[j] +
'" on the wrong place: ' +
(j + 1).toString() +
' instead of ' +
(i + 1).toString());
word = replaceCharAt(word, i, ' ');
candidate = replaceCharAt(candidate, j, ' ');
tips[j] = 'misplaced';
......@@ -101,29 +90,20 @@ class GameUtils {
}
}
print('Finished check letters: ' + tips.toString());
return tips;
}
static bool submitWord(Data myProvider) {
print('submitWord');
static void submitWord(Data myProvider) {
if (GameUtils.checkCurrentlyGuessedWordExists(myProvider)) {
print('Ok word allowed');
print('Ok word allowed: "' + myProvider.currentGuess + '".');
myProvider.currentGuessSubmitWord();
} else {
print('Unknown word');
print('Unknown word: "' + myProvider.currentGuess + '".');
myProvider.currentGuessSubmitWrongWord();
}
return true;
}
static bool checkCurrentlyGuessedWordExists(Data myProvider) {
String guessedWord = myProvider.currentGuess;
print('Checking word "' + guessedWord + '"...');
return RandomPickWord.checkWordExists(guessedWord);
return RandomPickWord.checkWordExists(myProvider.currentGuess);
}
}
......@@ -33,7 +33,7 @@ class RandomPickWord {
String wordBaseFilename = 'words-' + length.toString() + '-' + lang;
// Get full dictionary (eligible words)
print('Reload dictionary / ' + lang + ' / ' + length.toString());
print('Reload dictionary (' + lang + ' / ' + length.toString() + ')');
try {
String wordsFile = wordBaseFilename + '-' + 'dictionary';
var data = await rootBundle.loadString('assets/files/' + wordsFile + '.txt');
......@@ -47,7 +47,7 @@ class RandomPickWord {
}
// Get guessable words list (will pick random word from)
print('Reload words list / ' + lang + ' / ' + length.toString() + ' / ' + level);
print('Reload words list (' + lang + ' / ' + length.toString() + ' / ' + level + ')');
try {
String wordsFile = wordBaseFilename + '-' + level;
var data = await rootBundle.loadString('assets/files/' + wordsFile + '.txt');
......@@ -77,8 +77,6 @@ class RandomPickWord {
final _random = new Random();
_word = wordList.elementAt(_random.nextInt(wordList.length));
}
print('Picked word: ' + _word);
}
static bool checkWordExists(String word) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment