From aa77e2aa57b905df9b979d4c205dd4b64461d473 Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Wed, 17 Jan 2018 16:40:37 +0800 Subject: [PATCH] Replay --- index.html | 2 +- libs/core.js | 69 +++++++++++++++++++++++--------- libs/events.js | 105 +++++++++++++++++++++++++++++++++++++++---------- libs/ui.js | 5 ++- main.js | 31 +++++++++++++-- 快捷键说明.txt | 1 + 6 files changed, 168 insertions(+), 45 deletions(-) diff --git a/index.html b/index.html index ae063d97..60b85214 100644 --- a/index.html +++ b/index.html @@ -32,7 +32,7 @@
开始游戏 载入游戏 - 关于本塔 + 录像回放
简单 diff --git a/libs/core.js b/libs/core.js index 85ae52c7..db74ac41 100644 --- a/libs/core.js +++ b/libs/core.js @@ -53,12 +53,12 @@ function core() { 'isChrome': false, // 是否是Chrome 'supportCopy': false, // 是否支持复制到剪切板 - 'inputButton': null, // FileInput + 'fileInput': null, // FileInput 'file': null, // 读取的文件 'fileReader': null, // 是否支持FileReader 'successCallback': null, // 读取成功 'errorCallback': null, // 读取失败 - }, + } // 样式 this.domStyle = { styles: [], @@ -199,8 +199,21 @@ core.prototype.init = function (dom, statusBar, canvas, images, pngs, bgms, soun if (window.FileReader) { core.platform.fileReader = new FileReader(); core.platform.fileReader.onload = function () { - if (core.isset(core.platform.successCallback)) - core.platform.successCallback(core.platform.fileReader.result); + var content=core.platform.fileReader.result; + var obj=null; + try { + obj=JSON.parse(content); + if (core.isset(obj) && core.isset(core.platform.successCallback)) { + core.platform.successCallback(obj); + return; + } + } + catch (e) {} + alert("不是有效的JSON文件!"); + + if (core.isset(core.platform.errorCallback)) + core.platform.errorCallback(); + }; core.platform.fileReader.onerror = function () { if (core.isset(core.platform.errorCallback)) @@ -1107,8 +1120,8 @@ core.prototype.onmousewheel = function (direct) { // 存读档 if (core.status.lockControl && (core.status.event.id == 'save' || core.status.event.id == 'load')) { - if (direct==1) core.ui.drawSLPanel(core.status.event.data - 6); - if (direct==-1) core.ui.drawSLPanel(core.status.event.data + 6); + if (direct==1) core.ui.drawSLPanel(core.status.event.data - 10); + if (direct==-1) core.ui.drawSLPanel(core.status.event.data + 10); return; } } @@ -3400,6 +3413,13 @@ core.prototype.formatDate = function(date) { +core.setTwoDigits(date.getHours())+":"+core.setTwoDigits(date.getMinutes())+":"+core.setTwoDigits(date.getSeconds()); } +////// 格式化时间为最简字符串 ////// +core.prototype.formatDate2 = function (date) { + if (!core.isset(date)) return ""; + return date.getFullYear()+core.setTwoDigits(date.getMonth()+1)+core.setTwoDigits(date.getDate()) + +core.setTwoDigits(date.getHours())+core.setTwoDigits(date.getMinutes())+core.setTwoDigits(date.getSeconds()); +} + ////// 两位数显示 ////// core.prototype.setTwoDigits = function (x) { return parseInt(x)<10?"0"+x:x; @@ -3456,9 +3476,18 @@ core.prototype.replay = function (list) { else if (action.indexOf("item:")==0) { var itemId = action.substring(5); if (core.canUseItem(itemId)) { - core.useItem(itemId, function () { - core.replay(); - }); + var tools = Object.keys(core.status.hero.items.tools).sort(); + var constants = Object.keys(core.status.hero.items.constants).sort(); + var index; + if ((index=tools.indexOf(itemId))>=0 || (index=constants.indexOf(itemId)+100)>=100) { + core.ui.drawToolbox(index); + setTimeout(function () { + core.ui.closePanel(); + core.useItem(itemId, function () { + core.replay(); + }); + }, 500); + } return; } } @@ -3467,11 +3496,15 @@ core.prototype.replay = function (list) { var toIndex=core.status.hero.flyRange.indexOf(floorId); var nowIndex=core.status.hero.flyRange.indexOf(core.status.floorId); if (core.hasItem('fly') && toIndex>=0 && nowIndex>=0) { - var stair=toIndex7) return; var choices = [ - "同步存档到服务器", "从服务器加载存档", "清空本地存档", "返回主菜单" + "同步存档到服务器", "从服务器加载存档", "存档至本地文件", "从本地文件读档", "清空所有存档", "返回主菜单" ]; var topIndex = 6 - parseInt((choices.length - 1) / 2); if (y>=topIndex && y=30) page=30; + if (page>=30) page=29; if (offset>5) offset=5; index=10*page+offset; @@ -1192,6 +1192,7 @@ ui.prototype.drawHelp = function () { "[T] 打开/关闭工具栏\n" + "[ESC] 打开/关闭系统菜单\n" + "[H] 打开帮助页面\n"+ + "[R] 回放\n"+ "[SPACE] 轻按(仅在轻按开关打开时有效)\n" + "[1] 快捷使用破墙镐\n" + "[2] 快捷使用炸弹/圣锤\n" + diff --git a/main.js b/main.js index 4215a7cc..8a381330 100644 --- a/main.js +++ b/main.js @@ -53,7 +53,7 @@ function main() { 'startButtons': document.getElementById('startButtons'), 'playGame': document.getElementById('playGame'), 'loadGame': document.getElementById('loadGame'), - 'aboutGame': document.getElementById('aboutGame'), + 'replayGame': document.getElementById('replayGame'), 'levelChooseButtons': document.getElementById('levelChooseButtons'), 'easyLevel': document.getElementById('easyLevel'), 'normalLevel': document.getElementById('normalLevel'), @@ -377,8 +377,33 @@ main.dom.loadGame.onclick = function() { } ////// 点击“关于本塔”时 ////// -main.dom.aboutGame.onclick = function () { - main.core.ui.drawAbout(); +main.dom.replayGame.onclick = function () { + // main.core.ui.drawAbout(); + + core.readFile(function (obj) { + if (obj.name!=core.firstData.name) { + alert("存档和游戏不一致!"); + return; + } + if (obj.version!=core.firstData.version) { + alert("游戏版本不一致!"); + return; + } + if (!core.isset(obj.route) || !core.isset(obj.hard)) { + alert("无效的录像!"); + return; + } + + core.dom.startPanel.style.display = 'none'; + core.resetStatus(core.firstData.hero, obj.hard, core.firstData.floorId, null, core.initStatus.maps); + core.events.setInitData(obj.hard); + core.changeFloor(core.status.floorId, null, core.firstData.hero.loc, null, function() { + core.setHeroMoveTriggerInterval(); + core.replay(core.decodeRoute(obj.route)); + }); + }, function () { + + }) } ////// 点击“简单难度”时 ////// diff --git a/快捷键说明.txt b/快捷键说明.txt index 01a24314..525b10d5 100644 --- a/快捷键说明.txt +++ b/快捷键说明.txt @@ -13,6 +13,7 @@ [T] 打开/关闭工具栏 [ESC] 打开/关闭系统菜单 [H] 打开帮助页面 +[R] 回放 [SPACE] 轻按(仅在轻按开关打开时有效) [1] 快捷使用破墙镐 [2] 快捷使用炸弹/圣锤(先检测有没有炸弹,没有再检测圣锤)