Add: difficulty for level

This commit is contained in:
2019-01-06 15:37:00 +09:00
parent b2bc09469d
commit 113fb37f04
4 changed files with 127 additions and 38 deletions
+72 -18
View File
@@ -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;
@@ -48,7 +48,7 @@ function FlyingSaucer(lineIndex) {
FlyingSaucer.prototype.initVariables = function() {
this.isActivated = false;
this.wordLevel = 0;
this.wordLength = 0;
this.difficultyForLevel = 0;
this.standardScore = 0;
this.speed = FlyingSaucer.DEFAULT_SPEED;
this.jetStatus = FlyingSaucer.JET_STATUS_HIGH;
@@ -190,8 +190,12 @@ FlyingSaucer.prototype.moveInitialPos = function() {
FlyingSaucer.prototype.startAttack = function() {
this.wordLevel = this.gameLevelManager.getWordLevel();
this.wordLength = this.gameLevelManager.getWordLength(this.wordLevel);
this.word = this.extractWordManager.getWord(this.wordLevel, this.wordLength);
this.difficultyForLevel = this.gameLevelManager.getDifficultyForLevel();
// console.log("====");
// console.log("this.wordLevel : " + this.wordLevel);
// console.log("this.difficultyForLevel : " + this.difficultyForLevel);
this.word = this.extractWordManager.getWord(this.wordLevel, this.difficultyForLevel);
// console.log("this.word : " + this.word);
this.setWord(this.word);
this.standardScore = this.gameLevelManager.getStandardScore(this.wordLevel, this.speed);
// console.log(this.standardScore);
@@ -1,15 +1,19 @@
function GameLevelManager() {
this.wordLevel = 0;
this.wordLength = GameLevelManager.MIN_WORD_LENGTH;
this.clearPoint = 0.1;
this.clearedWordCountForLevel = [0, 0, 0, 0, 0];
this.difficultyForLevelList = [];
for(var i = 0; i < GameLevelManager.MAX_WORD_LEVEL; i++)
this.difficultyForLevelList[i] = ExtractWordManager.DIFFICULTY_EASY;
}
GameLevelManager.prototype.getWordLevel = function() {
return this.wordLevel;
}
GameLevelManager.prototype.getWordLength = function() {
return this.wordLength;
GameLevelManager.prototype.getDifficultyForLevel = function() {
return this.difficultyForLevelList[this.wordLevel];
}
GameLevelManager.prototype.getStandardScore = function(wordLevel, speed) {
@@ -18,31 +22,58 @@ GameLevelManager.prototype.getStandardScore = function(wordLevel, speed) {
GameLevelManager.prototype.clearWord = function(wordLevel, landingRatio) {
console.log("wordLevel : " + wordLevel);
console.log("landingRatio : " + landingRatio);
if(this.wordLevel == GameLevelManager.MAX_KOR_WORD_LEVEL || wordLevel < this.wordLevel) {
this.wordLength++;
// console.log("====");
// for(var i = 0; i < this.difficultyForLevelList.length; i++) {
// console.log("difficultyForLevelList[" + i + "] : " + this.difficultyForLevelList[i]);
// }
// console.log("wordLevel : " + wordLevel);
// console.log("landingRatio : " + landingRatio);
if(this.wordLevel == GameLevelManager.MAX_WORD_LEVEL || wordLevel < this.wordLevel) {
this.increaseClearedWordCountForLevel(wordLevel);
return;
}
if(landingRatio < GameLevelManager.LEVEL_UP_LANDING_RATIO) {
this.wordLength++;
if(wordLevel < this.wordLevel || landingRatio < GameLevelManager.LEVEL_UP_LANDING_RATIO) {
this.increaseClearedWordCountForLevel(wordLevel);
return;
}
this.goNextWordLevel();
}
GameLevelManager.prototype.increaseClearedWordCountForLevel = function(wordLevel) {
this.clearedWordCountForLevel[wordLevel]++;
var difficulty = this.difficultyForLevelList[wordLevel];
var clearedWordCount = this.clearedWordCountForLevel[wordLevel];
var clearedWordCountForNextLevel = GameLevelManager.CLEARED_WORD_COUNT_FOR_NEXT_LEVEL[difficulty];
// console.log("=============");
// console.log("difficulty : " + difficulty);
// console.log("clearedWordCount : " + clearedWordCount);
// console.log("clearedWordCountForNextLevel : " + clearedWordCountForNextLevel);
if(difficulty == ExtractWordManager.DIFFICULTY_EASY
&& clearedWordCount >= clearedWordCountForNextLevel) {
this.difficultyForLevelList[wordLevel] = ExtractWordManager.DIFFICULTY_HARD;
// console.log("level[" + wordLevel + "] : difficulty -> HARD");
}
}
GameLevelManager.prototype.goNextWordLevel = function() {
console.log("goNextWordLevel");
this.wordLevel++;
this.wordLength = 1;
console.log("goNextWordLevel to " + this.wordLevel);
}
GameLevelManager.LEVEL_UP_LANDING_RATIO = 0.7;
GameLevelManager.LEVEL_UP_LANDING_RATIO = 0.9;
GameLevelManager.WARNING_LANDING_RATIO = 0.1;
GameLevelManager.MAX_KOR_WORD_LEVEL = 5;
GameLevelManager.MAX_WORD_LEVEL = 6;
GameLevelManager.MIN_WORD_LENGTH = 2;
GameLevelManager.CLEARED_WORD_COUNT_FOR_NEXT_LEVEL = [5, 6, 7, 8, 9, 10];
GameLevelManager.KOREAN_WORD_LENGTH = [2, 3];
GameLevelManager.ENGLISH_WORD_LENGTH = [3, 6];;
+2 -2
View File
@@ -74,7 +74,7 @@
<script src="../../game/typing/word_list/korean_right_lower.js"></script>
<script src="../../game/typing/word_list/korean_left_upper_double.js"></script>
<script src="../../game/typing/word_list/korean_right_upper_double.js"></script>
<script src="../../game/typing/word_list/korean_word.js"></script>
<!-- <script src="../../game/typing/word_list/korean_word.js"></script> -->
<script src="../../game/typing/word_list/english_basic.js"></script>
<script src="../../game/typing/word_list/english_left_lower.js"></script>
@@ -82,7 +82,7 @@
<script src="../../game/typing/word_list/english_right_lower.js"></script>
<script src="../../game/typing/word_list/english_right_upper.js"></script>
<script src="../../game/typing/word_list/english_second_finger.js"></script>
<script src="../../game/typing/word_list/english_word.js"></script>
<!-- <script src="../../game/typing/word_list/english_word.js"></script> -->
<!-- Shoot down! flyingsaucer : source files -->
<script src="../../game/typing/lib/typing_content_bg.js"></script>