This commit is contained in:
ckcz123 2018-01-17 16:40:37 +08:00
parent 1a3735f52e
commit aa77e2aa57
6 changed files with 168 additions and 45 deletions

View File

@ -32,7 +32,7 @@
<div id='startButtons'> <div id='startButtons'>
<span class='startButton' id='playGame'>开始游戏</span> <span class='startButton' id='playGame'>开始游戏</span>
<span class='startButton' id='loadGame'>载入游戏</span> <span class='startButton' id='loadGame'>载入游戏</span>
<span class='startButton' id='aboutGame'>关于本塔</span> <span class='startButton' id='replayGame'>录像回放</span>
</div> </div>
<div id='levelChooseButtons'> <div id='levelChooseButtons'>
<span class='startButton' id='easyLevel'>简单</span> <span class='startButton' id='easyLevel'>简单</span>

View File

@ -53,12 +53,12 @@ function core() {
'isChrome': false, // 是否是Chrome 'isChrome': false, // 是否是Chrome
'supportCopy': false, // 是否支持复制到剪切板 'supportCopy': false, // 是否支持复制到剪切板
'inputButton': null, // FileInput 'fileInput': null, // FileInput
'file': null, // 读取的文件 'file': null, // 读取的文件
'fileReader': null, // 是否支持FileReader 'fileReader': null, // 是否支持FileReader
'successCallback': null, // 读取成功 'successCallback': null, // 读取成功
'errorCallback': null, // 读取失败 'errorCallback': null, // 读取失败
}, }
// 样式 // 样式
this.domStyle = { this.domStyle = {
styles: [], styles: [],
@ -199,8 +199,21 @@ core.prototype.init = function (dom, statusBar, canvas, images, pngs, bgms, soun
if (window.FileReader) { if (window.FileReader) {
core.platform.fileReader = new FileReader(); core.platform.fileReader = new FileReader();
core.platform.fileReader.onload = function () { core.platform.fileReader.onload = function () {
if (core.isset(core.platform.successCallback)) var content=core.platform.fileReader.result;
core.platform.successCallback(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 () { core.platform.fileReader.onerror = function () {
if (core.isset(core.platform.errorCallback)) 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 (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 - 10);
if (direct==-1) core.ui.drawSLPanel(core.status.event.data + 6); if (direct==-1) core.ui.drawSLPanel(core.status.event.data + 10);
return; return;
} }
} }
@ -3400,6 +3413,13 @@ core.prototype.formatDate = function(date) {
+core.setTwoDigits(date.getHours())+":"+core.setTwoDigits(date.getMinutes())+":"+core.setTwoDigits(date.getSeconds()); +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) { core.prototype.setTwoDigits = function (x) {
return parseInt(x)<10?"0"+x:x; return parseInt(x)<10?"0"+x:x;
@ -3456,9 +3476,18 @@ core.prototype.replay = function (list) {
else if (action.indexOf("item:")==0) { else if (action.indexOf("item:")==0) {
var itemId = action.substring(5); var itemId = action.substring(5);
if (core.canUseItem(itemId)) { if (core.canUseItem(itemId)) {
core.useItem(itemId, function () { var tools = Object.keys(core.status.hero.items.tools).sort();
core.replay(); 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; return;
} }
} }
@ -3467,11 +3496,15 @@ core.prototype.replay = function (list) {
var toIndex=core.status.hero.flyRange.indexOf(floorId); var toIndex=core.status.hero.flyRange.indexOf(floorId);
var nowIndex=core.status.hero.flyRange.indexOf(core.status.floorId); var nowIndex=core.status.hero.flyRange.indexOf(core.status.floorId);
if (core.hasItem('fly') && toIndex>=0 && nowIndex>=0) { if (core.hasItem('fly') && toIndex>=0 && nowIndex>=0) {
var stair=toIndex<nowIndex?"upFloor":"downFloor"; core.ui.drawFly(toIndex);
core.status.route.push("fly:"+core.floorIds.indexOf(floorId)); setTimeout(function () {
core.changeFloor(floorId, stair, null, null, function () { core.ui.closePanel();
core.replay(); var stair=toIndex<nowIndex?"upFloor":"downFloor";
}); core.status.route.push("fly:"+core.floorIds.indexOf(floorId));
core.changeFloor(floorId, stair, null, null, function () {
core.replay();
});
}, 500);
return; return;
} }
} }
@ -3690,7 +3723,7 @@ core.prototype.syncSave = function(type) {
formData.append('type', 'save'); formData.append('type', 'save');
formData.append('name', core.firstData.name); formData.append('name', core.firstData.name);
var saves = []; var saves = [];
for (var i=1;i<=180;i++) { for (var i=1;i<=150;i++) {
var data = core.getLocalStorage("save"+i, null); var data = core.getLocalStorage("save"+i, null);
if (core.isset(data)) { if (core.isset(data)) {
saves.push(data); saves.push(data);
@ -3760,7 +3793,7 @@ core.prototype.syncSave = function(type) {
// 成功 // 成功
var data=JSON.parse(response.msg); var data=JSON.parse(response.msg);
// console.log(data); // console.log(data);
for (var i=1;i<=180;i++) { for (var i=1;i<=150;i++) {
if (i<=data.length) { if (i<=data.length) {
core.setLocalStorage("save"+i, data[i-1]); core.setLocalStorage("save"+i, data[i-1]);
} }
@ -4017,13 +4050,11 @@ core.prototype.readFile = function (success, error) {
core.platform.fileInput.onchange = function () { core.platform.fileInput.onchange = function () {
var files = core.platform.fileInput.files; var files = core.platform.fileInput.files;
if (files.length==0) { if (files.length==0) {
core.platform.file = null;
if (core.isset(core.platform.errorCallback)) if (core.isset(core.platform.errorCallback))
core.platform.errorCallback(); core.platform.errorCallback();
return; return;
} }
core.platform.file = core.platform.fileInput.files[0]; core.platform.fileReader.readAsText(core.platform.fileInput.files[0]);
core.platform.fileReader.readAsText(core.platform.file);
} }
} }

View File

@ -113,52 +113,70 @@ events.prototype.setInitData = function (hard) {
////// 游戏获胜事件 ////// ////// 游戏获胜事件 //////
events.prototype.win = function(reason) { events.prototype.win = function(reason) {
core.ui.closePanel();
var replaying = core.status.replay.replaying;
core.status.replay.replaying=false;
core.waitHeroToStop(function() { core.waitHeroToStop(function() {
core.removeGlobalAnimate(0,0,true); core.removeGlobalAnimate(0,0,true);
core.clearMap('all'); // 清空全地图 core.clearMap('all'); // 清空全地图
core.drawText([ core.drawText([
"\t[结局2]恭喜通关!你的分数是${status:hp}。" "\t[恭喜通关]你的分数是${status:hp}。"
], function () { ], function () {
core.events.gameOver(); core.events.gameOver(replaying);
}) })
}); });
} }
////// 游戏失败事件 ////// ////// 游戏失败事件 //////
events.prototype.lose = function(reason) { events.prototype.lose = function(reason) {
core.ui.closePanel();
var replaying = core.status.replay.replaying;
core.status.replay.replaying=false;
core.waitHeroToStop(function() { core.waitHeroToStop(function() {
core.status.replay.replaying=false;
core.drawText([ core.drawText([
"\t[结局1]你死了。\n如题。" "\t[结局1]你死了。\n如题。"
], function () { ], function () {
core.events.gameOver(); core.events.gameOver(replaying);
}); });
}) })
} }
////// 游戏结束 ////// ////// 游戏结束 //////
events.prototype.gameOver = function () { events.prototype.gameOver = function (fromReplay) {
// 上传成绩 // 上传成绩
var confirmUpload = function () { var confirmUpload = function () {
core.restart();
} }
// 下载录像 // 下载录像
var confirmDownload = function () { var confirmDownload = function () {
core.drawConfirmBox("你想下载录像吗?", function () { core.ui.closePanel();
core.ui.drawConfirmBox("你想下载录像吗?", function () {
// 检测是否微信浏览器 var obj = {
// if () 'name': core.firstData.name,
'version': core.firstData.version,
'hard': core.status.hard,
'route': core.encodeRoute(core.status.route)
}
core.download(core.firstData.name+"_"+core.formatDate2(new Date())+".h5route", JSON.stringify(obj));
confirmUpload();
}, function () { }, function () {
confirmUpload(); confirmUpload();
}) })
} }
confirmDownload(); if (fromReplay) {
core.drawText("录像回放完毕!", function () {
core.restart();
});
}
else {
confirmDownload();
}
} }
@ -433,10 +451,14 @@ events.prototype.doAction = function() {
core.ui.drawChoices(data.text, data.choices); core.ui.drawChoices(data.text, data.choices);
break; break;
case "win": case "win":
core.events.win(data.reason); core.events.win(data.reason, function () {
core.events.doAction();
});
break; break;
case "lose": case "lose":
core.events.lose(data.reason); core.events.lose(data.reason, function () {
core.events.doAction();
});
break; break;
case "function": case "function":
var func = data["function"]; var func = data["function"];
@ -1317,11 +1339,11 @@ events.prototype.keyDownSL = function(keycode) {
return; return;
} }
if (keycode==33) { // PAGEUP if (keycode==33) { // PAGEUP
core.ui.drawSLPanel(10*(page+1) + offset); core.ui.drawSLPanel(10*(page-1) + offset);
return; return;
} }
if (keycode==34) { // PAGEDOWN if (keycode==34) { // PAGEDOWN
core.ui.drawSLPanel(10*(page-1) + offset); core.ui.drawSLPanel(10*(page+1) + offset);
return; return;
} }
} }
@ -1511,7 +1533,7 @@ events.prototype.keyUpSettings = function (keycode) {
events.prototype.clickSyncSave = function (x,y) { events.prototype.clickSyncSave = function (x,y) {
if (x<5 || x>7) return; if (x<5 || x>7) return;
var choices = [ var choices = [
"同步存档到服务器", "从服务器加载存档", "清空本地存档", "返回主菜单" "同步存档到服务器", "从服务器加载存档", "存档至本地文件", "从本地文件读档", "清空所有存档", "返回主菜单"
]; ];
var topIndex = 6 - parseInt((choices.length - 1) / 2); var topIndex = 6 - parseInt((choices.length - 1) / 2);
if (y>=topIndex && y<topIndex+choices.length) { if (y>=topIndex && y<topIndex+choices.length) {
@ -1524,16 +1546,59 @@ events.prototype.clickSyncSave = function (x,y) {
core.syncSave("load"); core.syncSave("load");
break; break;
case 2: case 2:
var saves = [];
for (var i=1;i<=150;i++) {
var data = core.getLocalStorage("save"+i, null);
if (core.isset(data)) {
saves.push(data);
}
}
var content = {
"name": core.firstData.name,
"version": core.firstData.version,
"data": saves
}
core.download(core.firstData.name+"_"+core.formatDate2(new Date())+".h5save", JSON.stringify(content));
break;
case 3:
core.readFile(function (obj) {
if (obj.name!=core.firstData.name) {
alert("存档和游戏不一致!");
return;
}
if (obj.version!=core.firstData.version) {
alert("游戏版本不一致!");
return;
}
if (!core.isset(obj.data)) {
alert("无效的存档!");
return;
}
var data=obj.data;
for (var i=1;i<=150;i++) {
if (i<=data.length) {
core.setLocalStorage("save"+i, data[i-1]);
}
else {
core.removeLocalStorage("save"+i);
}
}
core.drawText("读取成功!\n你的本地所有存档均已被覆盖。");
}, function () {
});
break;
case 4:
core.status.event.selection=1; core.status.event.selection=1;
core.ui.drawConfirmBox("你确定要清空所有本地存档吗?", function() { core.ui.drawConfirmBox("你确定要清空所有存档吗?", function() {
localStorage.clear(); localStorage.clear();
core.drawText("\t[操作成功]你的本地所有存档已被清空。"); core.drawText("\t[操作成功]你的所有存档已被清空。");
}, function() { }, function() {
core.status.event.selection=2; core.status.event.selection=2;
core.ui.drawSyncSave(false); core.ui.drawSyncSave(false);
}) })
break; break;
case 3: case 5:
core.status.event.selection=2; core.status.event.selection=2;
core.ui.drawSettings(); core.ui.drawSettings();
break; break;

View File

@ -668,7 +668,7 @@ ui.prototype.drawSyncSave = function () {
core.status.event.id = 'syncSave'; core.status.event.id = 'syncSave';
this.drawChoices(null, [ this.drawChoices(null, [
"同步存档到服务器", "从服务器加载存档", "清空本地存档", "返回主菜单" "同步存档到服务器", "从服务器加载存档", "存档至本地文件", "从本地文件读档", "清空所有存档", "返回主菜单"
]); ]);
} }
@ -1022,7 +1022,7 @@ ui.prototype.drawSLPanel = function(index) {
if (index<0) index=0; if (index<0) index=0;
var page = parseInt(index/10), offset=index%10; var page = parseInt(index/10), offset=index%10;
if (page>=30) page=30; if (page>=30) page=29;
if (offset>5) offset=5; if (offset>5) offset=5;
index=10*page+offset; index=10*page+offset;
@ -1192,6 +1192,7 @@ ui.prototype.drawHelp = function () {
"[T] 打开/关闭工具栏\n" + "[T] 打开/关闭工具栏\n" +
"[ESC] 打开/关闭系统菜单\n" + "[ESC] 打开/关闭系统菜单\n" +
"[H] 打开帮助页面\n"+ "[H] 打开帮助页面\n"+
"[R] 回放\n"+
"[SPACE] 轻按(仅在轻按开关打开时有效)\n" + "[SPACE] 轻按(仅在轻按开关打开时有效)\n" +
"[1] 快捷使用破墙镐\n" + "[1] 快捷使用破墙镐\n" +
"[2] 快捷使用炸弹/圣锤\n" + "[2] 快捷使用炸弹/圣锤\n" +

31
main.js
View File

@ -53,7 +53,7 @@ function main() {
'startButtons': document.getElementById('startButtons'), 'startButtons': document.getElementById('startButtons'),
'playGame': document.getElementById('playGame'), 'playGame': document.getElementById('playGame'),
'loadGame': document.getElementById('loadGame'), 'loadGame': document.getElementById('loadGame'),
'aboutGame': document.getElementById('aboutGame'), 'replayGame': document.getElementById('replayGame'),
'levelChooseButtons': document.getElementById('levelChooseButtons'), 'levelChooseButtons': document.getElementById('levelChooseButtons'),
'easyLevel': document.getElementById('easyLevel'), 'easyLevel': document.getElementById('easyLevel'),
'normalLevel': document.getElementById('normalLevel'), 'normalLevel': document.getElementById('normalLevel'),
@ -377,8 +377,33 @@ main.dom.loadGame.onclick = function() {
} }
////// 点击“关于本塔”时 ////// ////// 点击“关于本塔”时 //////
main.dom.aboutGame.onclick = function () { main.dom.replayGame.onclick = function () {
main.core.ui.drawAbout(); // 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 () {
})
} }
////// 点击“简单难度”时 ////// ////// 点击“简单难度”时 //////

View File

@ -13,6 +13,7 @@
[T] 打开/关闭工具栏 [T] 打开/关闭工具栏
[ESC] 打开/关闭系统菜单 [ESC] 打开/关闭系统菜单
[H] 打开帮助页面 [H] 打开帮助页面
[R] 回放
[SPACE] 轻按(仅在轻按开关打开时有效) [SPACE] 轻按(仅在轻按开关打开时有效)
[1] 快捷使用破墙镐 [1] 快捷使用破墙镐
[2] 快捷使用炸弹/圣锤(先检测有没有炸弹,没有再检测圣锤) [2] 快捷使用炸弹/圣锤(先检测有没有炸弹,没有再检测圣锤)