408 lines
11 KiB
JavaScript
408 lines
11 KiB
JavaScript
/////////////////////////////
|
|
// TypingPractice
|
|
|
|
class TypingPractice {
|
|
|
|
create() {
|
|
self = this;
|
|
|
|
this.isOnStage = false;
|
|
|
|
this.initTypingData();
|
|
sessionStorageManager.isNewBestRecrd = false;
|
|
|
|
game.stage.backgroundColor = '#4d4d4d';
|
|
|
|
// top
|
|
let backButton = new BackButton( () => {
|
|
sessionStorageManager.resetPlayingAppData();
|
|
|
|
location.href = '../../web/client/menu_typing_practice.html';
|
|
});
|
|
|
|
// this.animalOnTitle = new Animal(Animal.TYPE_ON_TITLE, game.world.centerX - 200, 30);
|
|
this.animalOnTitle = new Animal(Animal.TYPE_ON_TITLE, game.world.centerX, 90);
|
|
this.animalOnTitle.setSpecies(Animal.SPECIES_DATA[0]);
|
|
this.animalOnTitle.startAnimation();
|
|
|
|
this.typingScore = new TypingScore();
|
|
|
|
this.stageTimer = new StageTimer( TypingPractice.STAGE_TIMER_SEC, () => {
|
|
self.isOnStage = false;
|
|
|
|
// self.goResult();
|
|
self.gameOver();
|
|
});
|
|
|
|
let fullscreenButton = new FullscreenButton(game);
|
|
|
|
|
|
// typing content
|
|
let typingContentBG = new TypingContentBG();
|
|
typingContentBG.makePracticeContentBG();
|
|
|
|
let TYPING_CONTENT_Y = 200;
|
|
|
|
textStyleBasic.font = "bold 84px Times New Roman";
|
|
this.textTypingContent = game.add.text(game.world.centerX, TYPING_CONTENT_Y, "", textStyleBasic)
|
|
.setShadow(3, 3, 'rgba(0, 0, 0, 1)', 2)
|
|
.addColor(TypingPractice.COLOR_CONTENT_INPUT, 0);
|
|
this.textTypingContent.anchor.set(0.5);
|
|
|
|
this.textTypingBracket = game.add.text(game.world.centerX, TYPING_CONTENT_Y, "[ ]", textStyleBasic)
|
|
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2)
|
|
.addColor(TypingPractice.COLOR_BRACKET, 0);
|
|
this.textTypingBracket.anchor.set(0.5);
|
|
|
|
|
|
// textStyleBasic.font = "32px Arial";
|
|
let OFFSET_WORD_X = 70;
|
|
|
|
let textDoneColor = [ '#99994d', '#77774d', '#66664d' ];
|
|
this.textTypingContentsDone = [];
|
|
for(let i = 0; i < TypingPractice.TYPING_CONTENT_DONE_COUNT; i++) {
|
|
this.textTypingContentsDone[i] = game.add.text(
|
|
game.world.centerX - 200 - i * OFFSET_WORD_X, TYPING_CONTENT_Y,
|
|
"", textStyleBasic
|
|
);
|
|
this.textTypingContentsDone[i].addColor(textDoneColor[0], 0);
|
|
this.textTypingContentsDone[i].anchor.set(0.5);
|
|
}
|
|
|
|
let textPreviewColor = [ '#666666', '#888888', '#777777' ];
|
|
this.textTypingContentPreview = [];
|
|
for(let i = 0; i < TypingPractice.TYPING_CONTENT_PREVIEW_COUNT; i++) {
|
|
this.textTypingContentPreview[i] = game.add.text(
|
|
game.world.centerX + 200 + i * OFFSET_WORD_X,
|
|
TYPING_CONTENT_Y, "", textStyleBasic
|
|
);
|
|
this.textTypingContentPreview[i].addColor(textPreviewColor[0], 0);
|
|
this.textTypingContentPreview[i].anchor.set(0.5);
|
|
}
|
|
|
|
// keyboard
|
|
this.keyMapper = new KeyMapper();
|
|
this.keyboard = null;
|
|
if(sessionStorageManager.playingAppName.indexOf("korean") > 0)
|
|
this.keyboard = new Keyboard(this.keyMapper, Keyboard.KOREAN);
|
|
else
|
|
this.keyboard = new Keyboard(this.keyMapper, Keyboard.ENGLISH);
|
|
|
|
game.input.keyboard.processKeyPress = () => {
|
|
if(self.isOnStage === false)
|
|
return;
|
|
|
|
self.checkTypingContents(event);
|
|
}
|
|
this.shiftKey = game.input.keyboard.addKey(Phaser.Keyboard.SHIFT);
|
|
|
|
// hands
|
|
this.leftHand = new LeftHand(this.keyMapper);
|
|
this.rightHand = new RightHand(this.keyMapper);
|
|
|
|
|
|
|
|
// bottom
|
|
let screenBottom = new ScreenBottom();
|
|
// screenBottom.printBottomLeftText("");
|
|
screenBottom.printBottomCenterText(sessionStorageManager.playingAppKoreanName);
|
|
screenBottom.printBottomRightText(sessionStorageManager.playerName);
|
|
|
|
|
|
this.startGame();
|
|
// this.countDown();
|
|
}
|
|
|
|
startGame() {
|
|
this.isOnStage = true;
|
|
this.stageTimer.start();
|
|
|
|
this.showTypingPracticeContents();
|
|
this.showHighlightKey();
|
|
this.moveHands();
|
|
}
|
|
|
|
gameOver() {
|
|
this.isOnStage = false;
|
|
|
|
for(let i = 0; i < TypingPractice.TYPING_CONTENT_DONE_COUNT; i++) {
|
|
this.textTypingContentsDone[i].text = "";
|
|
}
|
|
|
|
this.textTypingBracket.text = "";
|
|
|
|
this.textTypingContent.clearColors();
|
|
this.textTypingContent.addColor(TypingPractice.COLOR_CONTENT_RIGHT, 0);
|
|
this.textTypingContent.text = "= 연습 끝 =";
|
|
|
|
for(let i = 0; i < TypingPractice.TYPING_CONTENT_PREVIEW_COUNT; i++) {
|
|
this.textTypingContentPreview[i].text = "";
|
|
}
|
|
|
|
this.leftHand.moveToDefaultPosition();
|
|
this.rightHand.moveToDefaultPosition();
|
|
|
|
this.animalOnTitle.stopAnimation();
|
|
|
|
let gameOverText = new GameOverText();
|
|
game.time.events.add(Phaser.Timer.SECOND * 2, this.goResult, this);
|
|
}
|
|
|
|
goResult() {
|
|
sessionStorageManager.record = this.typingScore.score();
|
|
if(sessionStorageManager.record > sessionStorageManager.bestRecord)
|
|
sessionStorageManager.bestRecord = sessionStorageManager.record;
|
|
|
|
location.href = '../../web/client/result.html';
|
|
}
|
|
|
|
initTypingData() {
|
|
let typingTextMan = new TypingTextManager();
|
|
|
|
let typingPracticeContents = this.loadPracticeContent();
|
|
// console.log(typingPracticeContents);
|
|
typingTextMan.makePracticeContents(typingPracticeContents, 30);
|
|
this.typingRandomContents = typingTextMan.getContents();
|
|
// console.log(this.typingRandomContents);
|
|
this.typingContentLength = this.typingRandomContents.length;
|
|
this.typingIndex = 0;
|
|
|
|
this.playingAnimalIndex = 0;
|
|
}
|
|
|
|
|
|
loadPracticeContent() {
|
|
let appName = "";
|
|
if(isTypingTestStage())
|
|
appName = sessionStorageManager.playingAppName.substring(5);
|
|
else if(isTypingPracticeStage())
|
|
appName = sessionStorageManager.playingAppName.substring(9);
|
|
|
|
let testContent = [];
|
|
|
|
switch(appName) {
|
|
case "korean_basic":
|
|
testContent = koreanBasicWordList;
|
|
break;
|
|
case "korean_left_upper":
|
|
testContent = koreanLeftUpperWordList;
|
|
break;
|
|
case "korean_second_finger":
|
|
testContent = koreanSecondFingerWordList;
|
|
break;
|
|
case "korean_right_upper":
|
|
testContent = koreanRightUpperWordList;
|
|
break;
|
|
case "korean_left_lower":
|
|
testContent = koreanLeftLowerWordList;
|
|
break;
|
|
case "korean_right_lower":
|
|
testContent = koreanRightLowerWordList;
|
|
break;
|
|
case "korean_left_upper_double":
|
|
testContent = koreanLeftUpperDoubleWordList;
|
|
break;
|
|
case "korean_right_upper_double":
|
|
testContent = koreanRightUpperDoubleWordList;
|
|
break;
|
|
case "korean_word":
|
|
testContent = koreanWordList;
|
|
break;
|
|
case "korean_sentence":
|
|
testContent = koreanSentenceList;
|
|
break;
|
|
|
|
case "english_basic":
|
|
testContent = englishBasicWordList;
|
|
/*
|
|
testContent = [
|
|
"a",
|
|
"C",
|
|
"n",
|
|
"J",
|
|
"t",
|
|
"e",
|
|
"s",
|
|
"X",
|
|
"v",
|
|
"b",
|
|
"D",
|
|
"i",
|
|
"k",
|
|
"N",
|
|
];
|
|
*/
|
|
break;
|
|
case "english_left_upper":
|
|
testContent = englishLeftUpperWordList;
|
|
break;
|
|
case "english_second_finger":
|
|
testContent = englishSecondFingerWordList;
|
|
break;
|
|
case "english_right_upper":
|
|
testContent = englishRightUpperWordList;
|
|
break;
|
|
case "english_left_lower":
|
|
testContent = englishLeftLowerWordList;
|
|
break;
|
|
case "english_right_lower":
|
|
testContent = englishRightLowerWordList;
|
|
break;
|
|
case "english_upper_lower":
|
|
testContent = englishUpperLowerWordList;
|
|
break;
|
|
case "english_word":
|
|
testContent = englishWordList;
|
|
break;
|
|
case "english_sentence":
|
|
testContent = englishSentenceList;
|
|
break;
|
|
}
|
|
|
|
return testContent;
|
|
}
|
|
|
|
showTypingPracticeContents() {
|
|
for(let i = 0; i < TypingPractice.TYPING_CONTENT_DONE_COUNT; i++) {
|
|
let doneIndex = this.typingIndex - i - 1;
|
|
if(doneIndex < 0) {
|
|
this.textTypingContentsDone[i].text = "";
|
|
} else {
|
|
this.textTypingContentsDone[i].text = this.typingRandomContents[doneIndex];
|
|
}
|
|
}
|
|
|
|
if(this.typingIndex == this.typingContentLength) {
|
|
this.textTypingContent.text = "";
|
|
return;
|
|
}
|
|
|
|
this.textTypingContent.text = this.typingRandomContents[this.typingIndex];
|
|
|
|
for(let i = 0; i < TypingPractice.TYPING_CONTENT_PREVIEW_COUNT; i++) {
|
|
let previewIndex = this.typingIndex + i + 1;
|
|
if(previewIndex < this.typingRandomContents.length)
|
|
this.textTypingContentPreview[i].text = this.typingRandomContents[previewIndex];
|
|
else
|
|
this.textTypingContentPreview[i].text = "";
|
|
}
|
|
}
|
|
|
|
hideHighlightKey() {
|
|
let prevText = this.typingRandomContents[this.typingIndex];
|
|
if(prevText === undefined)
|
|
return;
|
|
|
|
this.keyboard.hideHighlight(prevText);
|
|
}
|
|
|
|
showHighlightKey() {
|
|
let typingText = this.typingRandomContents[this.typingIndex];
|
|
if(typingText === undefined)
|
|
return;
|
|
|
|
this.keyboard.showHighlight(typingText, this.leftHand, this.rightHand);
|
|
}
|
|
|
|
moveHands() {
|
|
let typingText = this.typingRandomContents[this.typingIndex];
|
|
if(typingText === undefined)
|
|
return;
|
|
|
|
let key = this.keyboard.getKeyOfText(typingText);
|
|
let handSide = key.handSide;
|
|
if(handSide === KeyButton.LEFT_HAND) {
|
|
this.leftHand.moveTo(key);
|
|
|
|
if(this.keyMapper.isShiftText(typingText)) {
|
|
let shiftRightKey = this.keyboard.getKey("ShiftRight");
|
|
shiftRightKey.showHighlight();
|
|
this.rightHand.moveTo(shiftRightKey);
|
|
} else {
|
|
this.rightHand.moveToDefaultPosition();
|
|
}
|
|
} else {
|
|
this.rightHand.moveTo(key);
|
|
|
|
if(this.keyMapper.isShiftText(typingText)) {
|
|
let shiftLeftKey = this.keyboard.getKey("ShiftLeft");
|
|
shiftLeftKey.showHighlight();
|
|
this.leftHand.moveTo(shiftLeftKey);
|
|
} else {
|
|
this.leftHand.moveToDefaultPosition();
|
|
}
|
|
}
|
|
}
|
|
|
|
getKeyCode(text) {
|
|
return this.keyMapper.getKeyIDOfText(text);
|
|
}
|
|
|
|
isKeyPressed(inputContent, typingContent) {
|
|
let inputContentKeyCode = this.getKeyCode(inputContent);
|
|
let typingContentKeyCode = this.getKeyCode(typingContent);
|
|
|
|
if(inputContentKeyCode !== typingContentKeyCode)
|
|
return false;
|
|
|
|
let isShiftInputContent = this.shiftKey.isDown;
|
|
let isShiftTypingContent = this.keyMapper.isShiftText(typingContent);
|
|
|
|
if(isShiftInputContent !== isShiftTypingContent)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
checkTypingContents(evnet) {
|
|
let inputContent = event.key;
|
|
let typingContent = this.typingRandomContents[this.typingIndex];
|
|
|
|
if(this.isKeyPressed(inputContent, typingContent)) {
|
|
this.typingScore.increase();
|
|
let animalLevelID = Animal.animalLevelIDByRecord(this.typingScore.score(), Animal.TYPE_PRACTICE);
|
|
if(animalLevelID > this.playingAnimalIndex) {
|
|
this.playingAnimalIndex = animalLevelID;
|
|
this.animalOnTitle.setSpecies(Animal.SPECIES_DATA[this.playingAnimalIndex]);;
|
|
this.animalOnTitle.tweenAnimation(Animal.ANIMATION_TYPE_CHANGE);
|
|
this.animalOnTitle.startAnimation();
|
|
}
|
|
this.playNextContent();
|
|
|
|
if(this.typingIndex === this.typingContentLength) {
|
|
// this.goResult();
|
|
}
|
|
} else {
|
|
this.typingScore.reset();
|
|
|
|
this.playingAnimalIndex = 0;
|
|
this.animalOnTitle.setSpecies(Animal.SPECIES_DATA[this.playingAnimalIndex]);;
|
|
this.animalOnTitle.startAnimation();
|
|
this.animalOnTitle.tweenAnimation(Animal.ANIMATION_TYPE_DAMAGE);
|
|
}
|
|
}
|
|
|
|
|
|
playNextContent() {
|
|
this.hideHighlightKey();
|
|
|
|
this.typingIndex++;
|
|
this.showTypingPracticeContents();
|
|
this.showHighlightKey();
|
|
this.moveHands();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
TypingPractice.TYPING_CONTENT_PREVIEW_COUNT = 3;
|
|
TypingPractice.TYPING_CONTENT_DONE_COUNT = 3;
|
|
TypingPractice.TYPING_COUNT_PLUS_ENTER = 1;
|
|
|
|
TypingPractice.OFFSET_RIGHT_ALIGN = 10;
|
|
|
|
TypingPractice.STAGE_TIMER_SEC = 30;
|
|
|
|
TypingPractice.COLOR_CONTENT_INPUT = "#dddddd";
|
|
TypingPractice.COLOR_BRACKET = "#dddd70";
|
|
TypingPractice.COLOR_CONTENT_RIGHT = "#ffff4d"; |