Add: test and practice

This commit is contained in:
2018-06-07 17:40:52 +09:00
parent 72853fe9fd
commit 63bc872ee6
19 changed files with 432 additions and 71 deletions
+40
View File
@@ -51,4 +51,44 @@ function isTypingGame() {
return true;
}
function isTypingPracticeStage() {
let appName = sessionStorageManager.playingAppName;
console.log(appName);
console.log(appName.indexOf("practice_"));
if(appName.indexOf("practice_") > -1)
return true;
return false;
}
function isTypingTestStage() {
let appName = sessionStorageManager.playingAppName;
console.log(appName.indexOf("test_"));
if(appName.indexOf("test_") > -1)
return true;
return false;
}
function isTypingWordStage() {
let appName = sessionStorageManager.playingAppName;
if((isTypingPracticeStage() || isTypingTestStage()) && appName.indexOf("_word") > -1)
return true;
return false;
}
function isTypingSentenceStage() {
let appName = sessionStorageManager.playingAppName;
if((isTypingPracticeStage() || isTypingTestStage()) && appName.indexOf("_sentence") > -1)
return true;
return false;
}
let textStyleBasic = { font: "bold 32px Arial", fill: "#fff", align: "center", boundsAlignH: "center", boundsAlignV: "middle" };
+17
View File
@@ -134,6 +134,23 @@ class DBConnectManager {
xhr.send("maestro_id=" + maestroID);
}
requestTypingTestAppList(maestroID, onSucceededListener, onFailedListener) {
let xhr = new XMLHttpRequest();
xhr.open("POST", this.phpPath + "server/app/menu_active_typing_test_app_list.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && xhr.status == 200) {
let replyJSON = JSON.parse(xhr.responseText);
if(replyJSON != null)
onSucceededListener(replyJSON);
else
onFailedListener(replyJSON);
}
};
xhr.send("maestro_id=" + maestroID);
}
requestPlayerHistory(maestroID, date, listener) {
let historyRecordManager = new HistoryRecordManager();
+12
View File
@@ -0,0 +1,12 @@
/////////////////////////////
// Main game
const CONTENT_ID = "Menu";
let game = new Phaser.Game(
GAME_SCREEN_SIZE.x, GAME_SCREEN_SIZE.y,
Phaser.CANVAS, CONTENT_ID
);
game.state.add('MenuTypingTest', MenuTypingTest);
game.state.start('MenuTypingTest');
+46 -19
View File
@@ -47,7 +47,11 @@ class MenuApp {
// console.log(replyJSON);
self.makeMouseAppButtons(replyJSON.MouseAppList);
self.makeTypingButtons(replyJSON.TypingPracticeAppCount, replyJSON.TypingAppList);
self.makeTypingButtons(
replyJSON.TypingPracticeAppCount,
replyJSON.TypingTestAppCount,
replyJSON.TypingAppList
);
}
makeMouseAppButtons(mouseAppJSON) {
@@ -73,12 +77,17 @@ class MenuApp {
}
}
makeTypingButtons(typingPracticeAppCount, typingAppJSON) {
// console.log(typingPracticeAppCount);
// console.log(typingAppJSON);
makeTypingButtons(typingPracticeAppCount, typingTestAppCount, typingAppJSON) {
console.log(typingPracticeAppCount);
console.log(typingTestAppCount);
console.log(typingAppJSON);
let isTypingPracticeAppExist = typingPracticeAppCount > 0 ? true : false;
let typingAppTotalCount = Object.keys(typingAppJSON).length + (isTypingPracticeAppExist ? 1 : 0);
let isTypingTestAppExist = typingTestAppCount > 0 ? true : false;
let typingAppTotalCount = Object.keys(typingAppJSON).length
+ (isTypingPracticeAppExist ? 1 : 0)
+ (isTypingTestAppExist ? 1 : 0);
let typingAppIndex = 0;
for(let typingButtonIndex = 0; typingButtonIndex < typingAppTotalCount; typingButtonIndex++) {
@@ -90,32 +99,50 @@ class MenuApp {
typingButtonIndex, typingAppTotalCount, GameAppButton.BUTTON_LOWER_POS_Y
);
if(typingButtonIndex == 0 && isTypingPracticeAppExist) {
if(isTypingPracticeAppExist) {
isTypingPracticeAppExist = false;
new GameAppButton(
posX, posY, AppButton.TYPE_TYPING_PRACTICE,
"", "타자 연습\n(임시)",
"", "타자 연습",
() => {
location.href = '../../web/client/menu_typing_practice.html';
}
);
} else {
let app = typingAppJSON[typingAppIndex];
let isKoreanTypingApp = app.AppID < 32 ? true : false;
continue;
}
if(isTypingTestAppExist) {
isTypingTestAppExist = false;
new GameAppButton(
posX, posY, AppButton.TYPE_TYPING_APP,
"icon_fullscreen",
// (isKoreanTypingApp ? "(한글)" : "(영문)") + "\n" + app.KoreanName,
app.KoreanName,
posX, posY, AppButton.TYPE_TYPING_PRACTICE,
"", "타자 시험",
() => {
sessionStorageManager.playingAppID = app.AppID;
sessionStorageManager.playingAppName = app.AppName;
sessionStorageManager.playingAppKoreanName = app.KoreanName;
location.href = '../../web/client/start.html';
location.href = '../../web/client/menu_typing_test.html';
}
);
typingAppIndex++;
continue;
}
let app = typingAppJSON[typingAppIndex];
let isKoreanTypingApp = app.AppID < 32 ? true : false;
new GameAppButton(
posX, posY, AppButton.TYPE_TYPING_APP,
"icon_fullscreen",
// (isKoreanTypingApp ? "(한글)" : "(영문)") + "\n" + app.KoreanName,
app.KoreanName,
() => {
sessionStorageManager.playingAppID = app.AppID;
sessionStorageManager.playingAppName = app.AppName;
sessionStorageManager.playingAppKoreanName = app.KoreanName;
location.href = '../../web/client/start.html';
}
);
typingAppIndex++;
}
}
+4 -5
View File
@@ -1,5 +1,5 @@
/////////////////////////////
// MenuApp
// MenuTypingPractice
class MenuTypingPractice {
@@ -23,7 +23,7 @@ class MenuTypingPractice {
let screenBottom = new ScreenBottom();
screenBottom.makeBottomLine();
// screenBottom.printBottomLeftText("게임 진행 정보");
screenBottom.printBottomCenterText("타자 연습");
screenBottom.printBottomCenterText("메뉴 > 타자 연습");
screenBottom.printBottomRightText(sessionStorageManager.playerName);
@@ -49,8 +49,6 @@ class MenuTypingPractice {
let koreanTypingPracticeAppCount = Object.keys(replyJSON.Korean).length;
let englishTypingPracticeAppCount = Object.keys(replyJSON.English).length;
// let startX = game.world.width / 2 - (buttonWidthGap * koreanTypingPracticeAppCount / 2) - (buttonWidthGap / 2);
// let koreanTypingPracticeAppIndex = 0;
for(let i = 0; i < koreanTypingPracticeAppCount; i++) {
let activeApp = replyJSON.Korean[i];
@@ -66,12 +64,12 @@ class MenuTypingPractice {
() => {
sessionStorageManager.playingAppID = activeApp.AppID;
sessionStorageManager.playingAppName = activeApp.AppName;
sessionStorageManager.playingAppKoreanName = activeApp.KoreanName;
location.href = '../../web/client/start.html';
}
);
}
// startX = game.world.width / 2 - (buttonWidthGap * englishTypingPracticeAppCount / 2) - (buttonWidthGap / 2);
for(let i = 0; i < englishTypingPracticeAppCount; i++) {
let activeApp = replyJSON.English[i];
@@ -87,6 +85,7 @@ class MenuTypingPractice {
() => {
sessionStorageManager.playingAppID = activeApp.AppID;
sessionStorageManager.playingAppName = activeApp.AppName;
sessionStorageManager.playingAppKoreanName = activeApp.KoreanName;
location.href = '../../web/client/start.html';
}
);
+140
View File
@@ -0,0 +1,140 @@
/////////////////////////////
// MenuTypingTest
class MenuTypingTest {
preload() {
game.load.image('icon_fullscreen', '../../../resources/image/icon/fullscreen_white.png');
game.load.image('space_invaders', '../../../resources/image/icon/space_invaders.png');
}
create() {
self = this;
this.game.stage.backgroundColor = '#4d4d4d';
// top
let backButton = new BackButton( () => {
location.href = '../../web/client/menu_app.html';
});
let fullscreenButton = new FullscreenButton(this.game);
// bottom
let screenBottom = new ScreenBottom();
screenBottom.makeBottomLine();
// screenBottom.printBottomLeftText("게임 진행 정보");
screenBottom.printBottomCenterText("메뉴 > 타자 시험");
screenBottom.printBottomRightText(sessionStorageManager.playerName);
this.makeActiveTypingTestAppButtons();
}
makeActiveTypingTestAppButtons() {
let dbConnectManager = new DBConnectManager();
dbConnectManager.requestTypingTestAppList(
sessionStorageManager.maestroID,
self.loginSucceeded,
self.loginFailed
);
}
loginSucceeded(replyJSON) {
// console.log(replyJSON);
let buttonWidthGap = TypingPracticeButton.BUTTON_WIDTH + MenuTypingTest.BUTTON_GAP;
let koreanTypingTestAppCount = Object.keys(replyJSON.Korean).length;
let englishTypingTestAppCount = Object.keys(replyJSON.English).length;
// let startX = game.world.width / 2 - (buttonWidthGap * koreanTypingTestAppCount / 2) - (buttonWidthGap / 2);
// let koreanTypingTestAppIndex = 0;
for(let i = 0; i < koreanTypingTestAppCount; i++) {
let activeApp = replyJSON.Korean[i];
let posX = self.getButtonPosX(i, koreanTypingTestAppCount);
let posY = self.getButtonPosY(i, koreanTypingTestAppCount,
TypingPracticeButton.BUTTON_UPPER_POS_Y
);
new TypingPracticeButton(
posX, posY, LANGUAGE_KOREAN,
TypingPracticeButton.NONE_ICON,
activeApp.KoreanName,
() => {
sessionStorageManager.playingAppID = activeApp.AppID;
sessionStorageManager.playingAppName = activeApp.AppName;
sessionStorageManager.playingAppKoreanName = activeApp.KoreanName;
location.href = '../../web/client/start.html';
}
);
}
// startX = game.world.width / 2 - (buttonWidthGap * englishTypingTestAppCount / 2) - (buttonWidthGap / 2);
for(let i = 0; i < englishTypingTestAppCount; i++) {
let activeApp = replyJSON.English[i];
let posX = self.getButtonPosX(i, englishTypingTestAppCount);
let posY = self.getButtonPosY(i, englishTypingTestAppCount,
TypingPracticeButton.BUTTON_LOWER_POS_Y
);
new TypingPracticeButton(
posX, posY, LANGUAGE_ENGLISH,
TypingPracticeButton.NONE_ICON,
activeApp.KoreanName,
() => {
sessionStorageManager.playingAppID = activeApp.AppID;
sessionStorageManager.playingAppName = activeApp.AppName;
sessionStorageManager.playingAppKoreanName = activeApp.KoreanName;
location.href = '../../web/client/start.html';
}
);
}
}
getButtonPosX(index, buttonCount) {
let gap = TypingPracticeButton.BUTTON_WIDTH + TypingPracticeButton.BUTTON_GAP;
let maxColumnNum = Math.floor( (game.world.width - TypingPracticeButton.MARGIN_VERTICAL) / gap );
// console.log("maxColumnNum : " + maxColumnNum);
let rowCount = Math.ceil(buttonCount / maxColumnNum);
// console.log("rowCount : " + rowCount);
let columnIndex = index % maxColumnNum;
// console.log("columnIndex : " + columnIndex);
let rowIndex = Math.floor(index / maxColumnNum);
// console.log("rowIndex : " + rowIndex);
let columnCountForThisRow = 0;
if(rowIndex < rowCount - 1)
columnCountForThisRow = maxColumnNum;
else
columnCountForThisRow = buttonCount - (maxColumnNum * rowIndex);
// console.log("columnCountForThisRow : " + columnCountForThisRow);
let startX = game.world.width / 2 - ( (gap / 2) * (columnCountForThisRow - 1) );
return startX + gap * columnIndex;
}
getButtonPosY(index, buttonCount, startPosY) {
let gap = TypingPracticeButton.BUTTON_HEIGHT + TypingPracticeButton.BUTTON_GAP;
let maxColumnNum = Math.floor( (game.world.width - TypingPracticeButton.MARGIN_VERTICAL) / gap );
// console.log("maxColumnNum : " + maxColumnNum);
let rowCount = Math.ceil(buttonCount / maxColumnNum);
// console.log("rowCount : " + rowCount);
let rowIndex = Math.floor(index / maxColumnNum);
// console.log("rowIndex : " + rowIndex);
let startY = startPosY - ( (gap / 2) * (rowCount - 1) );
return startY + gap * rowIndex;
}
loginFailed(replyJSON) {
console.log('login failed, jsonData : ' + JSON.stringify(replyJSON));
}
}
+7 -1
View File
@@ -16,8 +16,14 @@ class Result {
// top
let backButton = new BackButton( () => {
if(isTypingPracticeStage())
location.href = '../../web/client/menu_typing_practice.html';
else if(isTypingTestStage())
location.href = '../../web/client/menu_typing_test.html';
else
location.href = '../../web/client/menu_app.html';
sessionStorageManager.resetPlayingAppData();
location.href = '../../web/client/menu_app.html';
});
let fullscreenButton = new FullscreenButton(this.game);
+7 -5
View File
@@ -16,12 +16,14 @@ class Start {
// top
let backButton = new BackButton( () => {
sessionStorageManager.playingAppName = null;
sessionStorageManager.playingAppKoreanName = null;
sessionStorageManager.record = null;
sessionStorageManager.bestRecord = null;
if(isTypingPracticeStage())
location.href = '../../web/client/menu_typing_practice.html';
else if(isTypingTestStage())
location.href = '../../web/client/menu_typing_test.html';
else
location.href = '../../web/client/menu_app.html';
location.href = '../../web/client/menu_app.html';
sessionStorageManager.resetPlayingAppData();
});
let fullscreenButton = new FullscreenButton(this.game);
+35 -34
View File
@@ -1,7 +1,7 @@
/////////////////////////////
// Typing Test
// TypingTest
class Test {
class TypingTest {
create() {
self = this;
@@ -14,7 +14,8 @@ class Test {
// top
let backButton = new BackButton( () => {
sessionStorageManager.resetPlayingAppData();
location.href = '../../web/client/menu_app.html';
location.href = '../../web/client/menu_typing_test.html';
});
this.averageTypingSpeedText = new AverageTypingSpeed();
@@ -29,7 +30,7 @@ class Test {
bar.beginFill(0x000000, 0.2);
bar.drawRect(0, typingAreaPositionY, GAME_SCREEN_SIZE.x, 120);
if(this.isWordStage())
if(isTypingWordStage())
textStyleBasic.font = "bold 84px Arial";
else // Sentence stage
textStyleBasic.font = "bold 48px Arial";
@@ -37,21 +38,21 @@ class Test {
this.textTypingContent = game.add.text(0, 2, "test", textStyleBasic)
.setTextBounds(0, typingAreaPositionY, GAME_SCREEN_SIZE.x, 120)
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2)
.addColor(Test.COLOR_CONTENT_WRONG, 0);
.addColor(TypingTest.COLOR_CONTENT_WRONG, 0);
textStyleBasic.font = "32px Arial";
var textDoneColor = [ '#99994d', '#77774d', '#66664d' ];
this.textTypingContentsDone = [];
this.textTypingRecordsDone = [];
for(var i = 0; i < Test.TYPING_CONTENT_DONE_COUNT; i++) {
for(var i = 0; i < TypingTest.TYPING_CONTENT_DONE_COUNT; i++) {
this.textTypingContentsDone[i] = game.add.text(0, 2, "test", textStyleBasic)
.setTextBounds(0, typingAreaPositionY - 50 - i * 50, GAME_SCREEN_SIZE.x, 40)
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2)
.addColor(textDoneColor[i], 0);
var scorePositionX = 780;
if(this.isWordStage())
if(isTypingWordStage())
scorePositionX = 600;
this.textTypingRecordsDone[i] = game.add.text(0, 2, "", textStyleBasic)
@@ -63,7 +64,7 @@ class Test {
var textPreviewColor = [ '#999999', '#888888', '#777777' ];
this.textTypingContentPreview = [];
for(var i = 0; i < Test.TYPING_CONTENT_PREVIEW_COUNT; i++) {
for(var i = 0; i < TypingTest.TYPING_CONTENT_PREVIEW_COUNT; i++) {
this.textTypingContentPreview[i] = game.add.text(0, 2, "test", textStyleBasic)
.setTextBounds(0, typingAreaPositionY + 130 + i * 50, GAME_SCREEN_SIZE.x, 40)
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2)
@@ -148,13 +149,13 @@ class Test {
}
initTypingData() {
this.typingTestContents = this.getTypingTestContents();
var randomContents = Phaser.ArrayUtils.shuffle(this.typingTestContents);
this.wordCountForStage = Test.WORD_COUNT_FOR_STAGE;
this.typingContents = this.getTypingTestContents();
var randomContents = Phaser.ArrayUtils.shuffle(this.typingContents);
this.wordCountForStage = TypingTest.WORD_COUNT_FOR_STAGE;
if(isDebugMode())
this.wordCountForStage = 3;
this.typingRandomContents = randomContents.slice(1, this.wordCountForStage + 1); // start Num, end Num (not index)
this.typingContentLength = this.typingTestContents.length;
this.typingContentLength = this.typingContents.length;
this.typingIndex = 0;
this.isTyping = false;
@@ -185,16 +186,20 @@ class Test {
loadTestContent() {
var testContent = [];
switch(sessionStorageManager.playingAppName) {
case "korean_word":
case "test_korean_word":
case "practice_korean_word":
testContent = koreanWordList;
break;
case "korean_sentence":
case "test_korean_sentence":
case "practice_korean_sentence":
testContent = koreanSentenceList;
break;
case "english_word":
case "test_english_word":
case "practice_english_word":
testContent = englishWordList;
break;
case "english_sentence":
case "test_english_sentence":
case "practice_english_sentence":
testContent = englishSentenceList;
break;
}
@@ -202,12 +207,8 @@ class Test {
return testContent;
}
isWordStage() {
return ( (sessionStorageManager.playingAppID % 10) === 0 );
}
showTypingTestContents() {
for(var i = 0; i < Test.TYPING_CONTENT_DONE_COUNT; i++) {
for(var i = 0; i < TypingTest.TYPING_CONTENT_DONE_COUNT; i++) {
var doneIndex = this.typingIndex - i - 1;
if(doneIndex < 0) {
this.textTypingContentsDone[i].text = "";
@@ -225,7 +226,7 @@ class Test {
this.textTypingContent.text = this.typingRandomContents[this.typingIndex];
for(var i = 0; i < Test.TYPING_CONTENT_PREVIEW_COUNT; i++) {
for(var i = 0; i < TypingTest.TYPING_CONTENT_PREVIEW_COUNT; i++) {
var previewIndex = this.typingIndex + i + 1;
if(previewIndex < this.typingRandomContents.length)
this.textTypingContentPreview[i].text = this.typingRandomContents[previewIndex];
@@ -236,7 +237,7 @@ class Test {
resetTypingContent() {
this.textTypingContent.clearColors();
this.textTypingContent.addColor(Test.COLOR_CONTENT_WRONG, 0);
this.textTypingContent.addColor(TypingTest.COLOR_CONTENT_WRONG, 0);
this.inputTextContent.canvasInput.value('');
}
@@ -271,7 +272,7 @@ class Test {
var inputContent = this.inputTextContent.canvasInput.value();
this.textTypingContent.clearColors();
this.textTypingContent.addColor(Test.COLOR_CONTENT_RIGHT, 0);
this.textTypingContent.addColor(TypingTest.COLOR_CONTENT_RIGHT, 0);
if(typingContent == null)
return;
@@ -282,7 +283,7 @@ class Test {
// console.log("inputContent.charAt(i) : " + inputContent.charAt(i));
if(typingContent.charAt(i) != inputContent.charAt(i)) {
this.textTypingContent.addColor(Test.COLOR_CONTENT_WRONG, i);
this.textTypingContent.addColor(TypingTest.COLOR_CONTENT_WRONG, i);
return;
}
}
@@ -300,9 +301,9 @@ class Test {
var typingContentLength = StringUtil.getUnicodeAlphabetCount(typingContent);
// console.log('typingContentLength : ' + typingContentLength);
var typingContentPlusEnterCount = typingContentLength + Test.TYPING_COUNT_PLUS_ENTER;
var typingContentPlusEnterCount = typingContentLength + TypingTest.TYPING_COUNT_PLUS_ENTER;
var typingRecord = (typingContentPlusEnterCount + Test.TYPING_COUNT_PLUS_ENTER) * 60000 / elapsedTimeMS;
var typingRecord = (typingContentPlusEnterCount + TypingTest.TYPING_COUNT_PLUS_ENTER) * 60000 / elapsedTimeMS;
this.typingElapsedTime[this.typingIndex] = elapsedTimeMS;
this.typingLetterCountTotal += typingContentPlusEnterCount;
@@ -356,17 +357,17 @@ class Test {
}
Test.TYPING_CONTENT_PREVIEW_COUNT = 3;
Test.TYPING_CONTENT_DONE_COUNT = 3;
Test.TYPING_COUNT_PLUS_ENTER = 1;
TypingTest.TYPING_CONTENT_PREVIEW_COUNT = 3;
TypingTest.TYPING_CONTENT_DONE_COUNT = 3;
TypingTest.TYPING_COUNT_PLUS_ENTER = 1;
Test.OFFSET_RIGHT_ALIGN = 10;
TypingTest.OFFSET_RIGHT_ALIGN = 10;
Test.WORD_COUNT_FOR_STAGE = 10;
TypingTest.WORD_COUNT_FOR_STAGE = 10;
// if(isDebugMode())
// WORD_COUNT_FOR_STAGE = 3;
Test.COLOR_CONTENT_WRONG = "#aaaaaa";
Test.COLOR_CONTENT_RIGHT = "#ffff4d";
TypingTest.COLOR_CONTENT_WRONG = "#aaaaaa";
TypingTest.COLOR_CONTENT_RIGHT = "#ffff4d";
+2 -2
View File
@@ -81,11 +81,11 @@ class Loading {
// this.preloadBar.alpha = 1;
if(isDebugMode()) {
this.state.start('Test');
this.state.start('TypingTest');
return;
}
this.state.start('Test');
this.state.start('TypingTest');
// this.startMenu();
// this.startTypingTestStage();
// this.startTypingTestResult();
+1 -1
View File
@@ -12,5 +12,5 @@ let game = new Phaser.Game(
game.state.add('Loading', Loading);
game.state.start('Loading');
game.state.add('Test', Test);
game.state.add('TypingTest', TypingTest);
// game.state.add('Menu', Menu);