From 113fb37f043036b8b2898ae972d3eb10bfbe21bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Sun, 6 Jan 2019 15:37:00 +0900 Subject: [PATCH] Add: difficulty for level --- src/game/typing/lib/extract_word_manager.js | 90 +++++++++++++++---- .../typing/word_flyingsaucer/flyingsaucer.js | 10 ++- .../word_flyingsaucer/game_level_manager.js | 61 +++++++++---- src/web/client/word_flyingsaucer.html | 4 +- 4 files changed, 127 insertions(+), 38 deletions(-) diff --git a/src/game/typing/lib/extract_word_manager.js b/src/game/typing/lib/extract_word_manager.js index 17645f8..75585b0 100644 --- a/src/game/typing/lib/extract_word_manager.js +++ b/src/game/typing/lib/extract_word_manager.js @@ -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; \ No newline at end of file diff --git a/src/game/typing/word_flyingsaucer/flyingsaucer.js b/src/game/typing/word_flyingsaucer/flyingsaucer.js index 0cbfad0..69d6458 100644 --- a/src/game/typing/word_flyingsaucer/flyingsaucer.js +++ b/src/game/typing/word_flyingsaucer/flyingsaucer.js @@ -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); diff --git a/src/game/typing/word_flyingsaucer/game_level_manager.js b/src/game/typing/word_flyingsaucer/game_level_manager.js index 4d186c2..495ea46 100644 --- a/src/game/typing/word_flyingsaucer/game_level_manager.js +++ b/src/game/typing/word_flyingsaucer/game_level_manager.js @@ -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; \ No newline at end of file +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];; \ No newline at end of file diff --git a/src/web/client/word_flyingsaucer.html b/src/web/client/word_flyingsaucer.html index af8b658..2d2d559 100644 --- a/src/web/client/word_flyingsaucer.html +++ b/src/web/client/word_flyingsaucer.html @@ -74,7 +74,7 @@ - + @@ -82,7 +82,7 @@ - +