Add: test and practice
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user