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

Add initial tip, repeat found letters on new guess

parent 06266e09
Branches
Tags
1 merge request!8Resolve "Add initial tip, repeat on new guess"
Pipeline #3569 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.19 app.versionName=0.0.20
app.versionCode=19 app.versionCode=20
Add initial tip, repeat found letters on new guess
Propose la première lettre et répète les lettres trouvées à chaque nouvelle ligne
...@@ -10,7 +10,8 @@ class Board { ...@@ -10,7 +10,8 @@ class Board {
int maxGuessesCount = myProvider.maxGuessesCount; int maxGuessesCount = myProvider.maxGuessesCount;
int wordLength = int.parse(myProvider.length); int wordLength = int.parse(myProvider.length);
Widget buildCellWidget(String cellValue, String cellTip, bool hasFocus) { Widget buildCellWidget(
String cellValue, String cellTip, bool hasFocus, String foundLetter) {
Color textColor = Colors.white; Color textColor = Colors.white;
Color focusBorderColor = Colors.yellow.shade700; Color focusBorderColor = Colors.yellow.shade700;
Color defaultBorderColor = Colors.white; Color defaultBorderColor = Colors.white;
...@@ -20,6 +21,11 @@ class Board { ...@@ -20,6 +21,11 @@ class Board {
cellImage = cellTip; cellImage = cellTip;
} }
if ((foundLetter != ' ') && (cellValue == ' ')) {
cellValue = foundLetter;
cellImage = 'good';
}
Image imageWidget = Image( Image imageWidget = Image(
image: AssetImage('assets/skins/' + skin + '_' + cellImage + '.png'), image: AssetImage('assets/skins/' + skin + '_' + cellImage + '.png'),
fit: BoxFit.fill, fit: BoxFit.fill,
...@@ -84,7 +90,13 @@ class Board { ...@@ -84,7 +90,13 @@ class Board {
(lineIndex == guesses.length) && (lineIndex == guesses.length) &&
(colIndex == word.length); (colIndex == word.length);
tableCells.add(TableCell(child: buildCellWidget(cellValue, cellTip, hasFocus))); 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)); tableRows.add(TableRow(children: tableCells));
......
...@@ -31,6 +31,7 @@ class Data extends ChangeNotifier { ...@@ -31,6 +31,7 @@ class Data extends ChangeNotifier {
List _recentWords = []; List _recentWords = [];
List<String> _guesses = []; List<String> _guesses = [];
String _currentGuess = ''; String _currentGuess = '';
String _foundLetters = '';
int _maxGuessesCount = 7; int _maxGuessesCount = 7;
String get lang => _lang; String get lang => _lang;
...@@ -100,6 +101,16 @@ class Data extends ChangeNotifier { ...@@ -100,6 +101,16 @@ class Data extends ChangeNotifier {
_currentGuess = ''; _currentGuess = '';
} }
String get foundLetters => _foundLetters;
void initFoundLetters() {
_foundLetters = _word.substring(0, 1).padRight(_word.length, ' ');
}
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; bool get gameWon => _foundWord;
getParameterValue(String parameterCode) { getParameterValue(String parameterCode) {
...@@ -204,6 +215,7 @@ class Data extends ChangeNotifier { ...@@ -204,6 +215,7 @@ class Data extends ChangeNotifier {
_recentWords.insert(0, word); _recentWords.insert(0, word);
_recentWords = _recentWords.take(_recentWordsCount).toList(); _recentWords = _recentWords.take(_recentWordsCount).toList();
} }
initFoundLetters();
notifyListeners(); notifyListeners();
} }
......
...@@ -76,6 +76,7 @@ class GameUtils { ...@@ -76,6 +76,7 @@ class GameUtils {
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()); print('Found "' + word[i] + '" on the right place: ' + (i + 1).toString());
myProvider.addFoundLetter(word[i], i);
word = replaceCharAt(word, i, ' '); word = replaceCharAt(word, i, ' ');
candidate = replaceCharAt(candidate, i, ' '); candidate = replaceCharAt(candidate, i, ' ');
tips[i] = 'good'; tips[i] = 'good';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment