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

Merge branch '2-check-submitted-word-is-allowed' into 'master'

Resolve "Check submitted word is allowed"

Closes #2

See merge request !2
parents 34018b1f 3b645b36
No related branches found
No related tags found
1 merge request!2Resolve "Check submitted word is allowed"
Pipeline #2572 passed
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
app.versionName=0.0.3
app.versionCode=3
app.versionName=0.0.4
app.versionCode=4
assets/skins/default_wrong.png

824 B

......@@ -51,6 +51,7 @@ function build_icon_for_skin() {
build_icon ${CURRENT_DIR}/skins/${SKIN_CODE}/empty.svg ${BASE_DIR}/assets/skins/${SKIN_CODE}_empty.png
build_icon ${CURRENT_DIR}/skins/${SKIN_CODE}/good.svg ${BASE_DIR}/assets/skins/${SKIN_CODE}_good.png
build_icon ${CURRENT_DIR}/skins/${SKIN_CODE}/misplaced.svg ${BASE_DIR}/assets/skins/${SKIN_CODE}_misplaced.png
build_icon ${CURRENT_DIR}/skins/${SKIN_CODE}/wrong.svg ${BASE_DIR}/assets/skins/${SKIN_CODE}_wrong.png
}
# Game icons
......
<?xml version="1.0" encoding="UTF-8"?>
<svg enable-background="new 0 0 100 100" version="1.1" viewBox="0 0 100 100" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><defs><linearGradient id="linearGradient1569" x1="26.688" x2="77.95" y1=".40612" y2="99.665" gradientUnits="userSpaceOnUse"><stop stop-color="#b9b9b9" offset="0"/><stop stop-color="#767676" offset="1"/></linearGradient></defs><rect width="100" height="100" ry="2" fill="none"/><rect width="100" height="100" fill="url(#linearGradient1569)" stroke="#5d5d5d" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"/></svg>
......@@ -84,6 +84,11 @@ class Data extends ChangeNotifier {
notifyListeners();
}
}
void currentGuessSubmitWrongWord() {
print('Adding unknown word');
addGuess(_currentGuess);
notifyListeners();
}
void addGuess(String word) {
print('addGuess('+word+')');
_guesses.add(word);
......
......@@ -61,8 +61,12 @@ class GameUtils {
List<String> tips = List<String>.filled(wordLength, '', growable: false);
if ((word.length != wordLength) || (candidate.length != wordLength)) {
return tips;
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) {
......@@ -102,11 +106,25 @@ class GameUtils {
static bool submitWord(Data myProvider) {
print('submitWord');
// TODO: check this word is allowed
if (GameUtils.checkCurrentlyGuessedWordExists(myProvider)) {
print('Ok word allowed');
myProvider.currentGuessSubmitWord();
} else {
print('Unknown word');
myProvider.currentGuessSubmitWrongWord();
}
return true;
}
static bool checkCurrentlyGuessedWordExists(Data myProvider) {
String guessedWord = myProvider.currentGuess;
print('Checking word "' + guessedWord + '"...');
return RandomPickWord.checkWordExists(guessedWord);
}
static bool isGameFinished(Data myProvider) {
print('isGameFinished');
......
......@@ -30,10 +30,10 @@ class RandomPickWord {
String wordBaseFilename = 'words-' + length.toString() + '-' + lang;
// Get full dictionnary (eligible words)
// Get full dictionary (eligible words)
print('Reload dictionary');
try {
String wordsFile = wordBaseFilename + '-' + 'dictionnary';
String wordsFile = wordBaseFilename + '-' + 'dictionary';
var data = await rootBundle.loadString('assets/files/' + wordsFile + '.txt');
LineSplitter.split(data).forEach((line) {
if (line.length == length) {
......@@ -74,4 +74,8 @@ class RandomPickWord {
print('Picked word: ' + _word);
}
static bool checkWordExists(String word) {
return dictionary.contains(word);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment