Add: difficulty for level
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
function ExtractWordManager() {
|
||||
this.init();
|
||||
this.initVariables();
|
||||
}
|
||||
|
||||
ExtractWordManager.prototype.init = function() {
|
||||
ExtractWordManager.prototype.initVariables = function() {
|
||||
this.koreanWordList = [];
|
||||
this.koreanWordList[0] = koreanBasicWordList;
|
||||
this.koreanWordList[1] = koreanLeftUpperWordList;
|
||||
@@ -27,29 +27,74 @@ ExtractWordManager.prototype.init = function() {
|
||||
}
|
||||
|
||||
|
||||
ExtractWordManager.prototype.getWord = function(wordLevel, wordLength) {
|
||||
if(isKoreanTypingApp())
|
||||
return this.getKoreanWord(wordLevel, wordLength);
|
||||
else
|
||||
return this.getEnglishWord(wordLevel, wordLength);
|
||||
ExtractWordManager.prototype.isValidWordForLevel = function(word, difficultyForLevel) {
|
||||
// console.log("word : " + word);
|
||||
// console.log("difficultyForLevel : " + difficultyForLevel);
|
||||
if(word == "")
|
||||
return false;
|
||||
|
||||
var wordLength = word.length;
|
||||
|
||||
if(difficultyForLevel == ExtractWordManager.DIFFICULTY_EASY) {
|
||||
var maxWordLength = 0;
|
||||
|
||||
if(isKoreanTypingApp()) {
|
||||
maxWordLength = ExtractWordManager.DIFFICULTY_EASY_KOREAN_WORD_LENGTH;
|
||||
} else {
|
||||
maxWordLength = ExtractWordManager.DIFFICULTY_EASY_ENGLISH_WORD_LENGTH;
|
||||
}
|
||||
|
||||
if(wordLength <= maxWordLength)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
} else {
|
||||
var minWordLength = 0;
|
||||
|
||||
if(isKoreanTypingApp()) {
|
||||
minWordLength = ExtractWordManager.DIFFICULTY_EASY_KOREAN_WORD_LENGTH;
|
||||
} else {
|
||||
minWordLength = ExtractWordManager.DIFFICULTY_EASY_ENGLISH_WORD_LENGTH;
|
||||
}
|
||||
|
||||
if(wordLength > minWordLength)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ExtractWordManager.prototype.getWord = function(wordLevel, difficultyForLevel) {
|
||||
// console.log("wordLevel : " + wordLevel);
|
||||
// console.log("difficultyForLevel : " + difficultyForLevel);
|
||||
var word = "";
|
||||
var wordLength = 0;
|
||||
var count = 0;
|
||||
while(word == "" || !this.isValidWordForLevel(word, difficultyForLevel)) {
|
||||
if(isKoreanTypingApp())
|
||||
word = this.getRandomWord(this.koreanWordList[wordLevel]);
|
||||
else
|
||||
word = this.getRandomWord(this.englishWordList[wordLevel]);
|
||||
|
||||
// console.log(word);
|
||||
count++;
|
||||
if(count > 100) {
|
||||
console.log("warning : infinity loop!!!");
|
||||
return "???";
|
||||
}
|
||||
}
|
||||
return word;
|
||||
}
|
||||
|
||||
ExtractWordManager.prototype.getRandomWord = function(wordList) {
|
||||
var index = Math.floor(Math.random() * wordList.length);
|
||||
return wordList[index];
|
||||
var randomIndex = Math.floor(Math.random() * wordList.length);
|
||||
return wordList[randomIndex];
|
||||
}
|
||||
|
||||
|
||||
ExtractWordManager.prototype.getKoreanWord = function(wordLevel, wordLength) {
|
||||
return this.getRandomWord(this.koreanWordList[wordLevel]);
|
||||
}
|
||||
|
||||
ExtractWordManager.prototype.getEnglishWord = function(wordLevel, wordLength) {
|
||||
return this.getRandomWord(this.englishWordList[wordLevel]);
|
||||
}
|
||||
|
||||
ExtractWordManager.prototype.removeWord = function(wordLevel, word) {
|
||||
console.log("remove : " + wordLevel + ", " + word);
|
||||
// console.log("remove : " + wordLevel + ", " + word);
|
||||
}
|
||||
|
||||
|
||||
@@ -183,3 +228,12 @@ ExtractWordManager.ENGLISH_LETTER_RIGHT = [
|
||||
"h", "j", "k", "l",
|
||||
"n", "m"
|
||||
];
|
||||
|
||||
|
||||
|
||||
|
||||
ExtractWordManager.DIFFICULTY_EASY = 0;
|
||||
ExtractWordManager.DIFFICULTY_HARD = 1
|
||||
|
||||
ExtractWordManager.DIFFICULTY_EASY_KOREAN_WORD_LENGTH = 2;
|
||||
ExtractWordManager.DIFFICULTY_EASY_ENGLISH_WORD_LENGTH = 3;
|
||||
Reference in New Issue
Block a user