Files
chocomae/src/game/mouse/one_to_fifty/game.js
T
2019-05-10 20:21:59 +09:00

216 lines
5.9 KiB
JavaScript

var Game = {
create: function() {
this.mode = "release"; // "test";
this.initVariables();
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.drawObjects();
// 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.nextNumber = 1;
this.difficulty = Chocoball.MODE_DIFFICULT;
// if previous record is over 60 sec, play easy mode
var prevRecord = sessionStorageManager.getRecord()
// console.log(prevRecord);
var secForEasyMode = this.mode == "test" ? 1 : 60;
if(prevRecord > secForEasyMode) {
this.difficulty = Chocoball.MODE_EASY;
}
this.firstChocoballArray = this.makeChocoballArray(1, 25);
this.secondChocoballArray = this.makeChocoballArray(26, 50);
},
drawObjects: function() {
var graphics = game.add.graphics(0, 0);
var outLineRadius = 97;
this.chocoballs = new Array();
for(var i = 0; i < 25; i++) {
graphics.lineStyle(0);
graphics.beginFill(0x202020);
graphics.drawCircle(Chocoball.getX(i), Chocoball.getY(i), outLineRadius);
graphics.endFill();
var chocoball = new Chocoball(
i,
this.difficulty,
(function(chocoball) { this.onClickChocoball(chocoball); }).bind(this)
);
chocoball.setNumber(this.firstChocoballArray[i]);
this.chocoballs.push(chocoball);
}
var triangleStartX = God.POSITION_X;
var triangleStartY = God.POSITION_Y - 245;
var triangleHalfWidth = 20;
var triangleHeight = 40;
graphics.beginFill(0xFFFFFF);
graphics.lineStyle(20, 0x000000);
graphics.moveTo(triangleStartX, triangleStartY);
graphics.lineTo(triangleStartX + triangleHalfWidth, triangleStartY - triangleHeight);
graphics.lineTo(triangleStartX - triangleHalfWidth, triangleStartY - triangleHeight);
graphics.lineTo(triangleStartX, triangleStartY);
graphics.endFill();
graphics.lineStyle(10, 0x000000);
graphics.beginFill(0xFFFFFF);
graphics.drawCircle(God.POSITION_X, God.POSITION_Y - 360, 200);
graphics.endFill();
graphics.beginFill(0xFFFFFF);
graphics.lineStyle(0);
graphics.moveTo(triangleStartX, triangleStartY);
graphics.lineTo(triangleStartX + triangleHalfWidth, triangleStartY - triangleHeight);
graphics.lineTo(triangleStartX - triangleHalfWidth, triangleStartY - triangleHeight);
graphics.lineTo(triangleStartX, triangleStartY);
graphics.endFill();
this.nextChocoball = new Chocoball(
100,
this.difficulty,
(function(chocoball) { console.log("no event") }).bind(this)
);
this.nextChocoball.setNumber(this.nextNumber);
this.god = new God(God.POSITION_X, God.POSITION_Y, this);
},
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 == 50) {
// console.log("game clear");
chocoball.setVisible(false);
this.gameClear();
return;
}
if(chocoball.number != this.nextNumber) {
console.log("wrong");
this.god.animateAngry();
return;
}
// clicked correct number
if(chocoball.number == 1)
this.stopWatch.start();
this.nextNumber++;
this.god.animateHappy();
if(chocoball.number <= 25)
chocoball.setNumber(this.secondChocoballArray[chocoball.index]);
else
chocoball.setVisible(false);
this.nextChocoball.setNumber(this.nextNumber);
if(this.mode == "test" && this.nextNumber == 3) {
console.log("time over");
this.timeOver();
}
},
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 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() {
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?update=1905101';
},
}
Game.GAME_OVER_WAIT_TIME_MS = 3000;
// Game.GAME_TIME_SEC = 60;
// Game.NEXT_STAGE_DELAY_MS = 500;