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