Files
chocomae/src/game/mouse/one_to_fifty/game.js
T
2019-05-10 08:40:38 +09:00

159 lines
4.0 KiB
JavaScript

var Game = {
create: function() {
this.dbConnectManager = new DBConnectManager();
sessionStorageManager.setRecord(0);
sessionStorageManager.setIsNewAppHighestRecord(false);
var experienceAppTimer = new ExperienceAppTimer();
experienceAppTimer.setTimeOverListener(
(function() { this.timeOver(); }).bind(this)
);
// keyboard shortcut
this.keyboardShortcut = new KeyboardShortcut();
this.keyboardShortcut.addCallback(
Phaser.KeyCode.ESC, // keyCode
null, // keyDownHandler
(function() { this.back(); }).bind(this), // keyUpHandler
"1 to 50" // callerClassName
);
// game stage
game.stage.backgroundColor = '#4d4d4d';
// top ui
var screenTopUI = new ScreenTopUI();
screenTopUI.makeBackButton( (function() { this.back(); }).bind(this) );
screenTopUI.makeFullScreenButton();
this.stopWatch = new StopWatch(game);
// init game elements
this.initVariables();
// bottom ui
var screenBottomUI = new ScreenBottomUI();
screenBottomUI.printLeftTextWithAppHighestRecord(sessionStorageManager.getAppHighestRecord());
screenBottomUI.printCenterText(sessionStorageManager.getPlayingAppKoreanName());
screenBottomUI.printRightText(sessionStorageManager.getPlayerName());
this.startGame();
// // this.countDown();
},
initVariables: function() {
this.firstChocoballArray = this.makeChocoballArray(1, 25);
this.secondChocoballArray = this.makeChocoballArray(26, 50);
this.chocoballs = new Array();
for(var i = 0; i < 25; i++) {
var chocoball = new Chocoball(
i,
(function(chocoball) { this.onClickChocoball(chocoball); }).bind(this)
);
chocoball.setNumber(this.firstChocoballArray[i]);
this.chocoballs.push(chocoball);
}
this.god = new God(game.world.width - 120, Game.GOD_POSITION_Y + 100, this);
this.nextNumber = 1;
},
makeChocoballArray(firstNumber, lastNumber) {
var numberArray = new Array();
for(var i = firstNumber; i < lastNumber + 1; i++) {
numberArray.push(i);
}
var randomArray = Phaser.ArrayUtils.shuffle(numberArray);
return randomArray;
},
back: function() {
sessionStorageManager.resetPlayingAppData();
location.href = '../../web/client/menu_app.html';
},
onClickChocoball: function(chocoball) {
// console.log(chocoball.index);
console.log(chocoball.number);
if(chocoball.number == 1)
this.stopWatch.start();
if(chocoball.number != this.nextNumber) {
console.log("wrong");
return;
} else {
this.nextNumber++;
}
if(chocoball.number < 25)
chocoball.setNumber(this.secondChocoballArray[chocoball.index]);
else
chocoball.setActive(false);
if(chocoball.number == 50) {
console.log("game clear");
this.gameClear();
}
},
startGame: function() {
},
gameClear: function() {
var recordTime = this.stopWatch.stop();
sessionStorageManager.setRecord(recordTime);
if(!isExperienceMaestroAccount())
this.updateResultRecord();
var missionClearText = new MissionClearText();
game.time.events.add(Game.GAME_OVER_WAIT_TIME_MS, this.goResult, this);
},
timeOver: function() {
var timeOverText = new TimeOverText();
if(!isExperienceMaestroAccount())
this.updateResultRecord();
var recordTime = this.stopWatch.stop();
sessionStorageManager.setRecord(recordTime);
if(!isExperienceMaestroAccount())
this.updateResultRecord();
var timeOverText = new TimeOverText();
game.time.events.add(Game.GAME_OVER_WAIT_TIME_MS, this.goResult, this);
},
updateResultRecord: function() {
console.log("update record : " + sessionStorageManager.getRecord());
return;
if(sessionStorageManager.getMaestroAccountType() < 100) { // experience account
this.dbConnectManager.updateResultRecord(
sessionStorageManager.getMaestroID(),
sessionStorageManager.getPlayerID(),
sessionStorageManager.getPlayingAppID(),
sessionStorageManager.getRecord()
);
}
},
goResult: function() {
location.href = '../../web/client/result.html';
},
}
Game.GAME_OVER_WAIT_TIME_MS = 3000;
// Game.GAME_TIME_SEC = 60;
// Game.NEXT_STAGE_DELAY_MS = 500;