投篮游戏
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
6.5 KiB

(()=>{"use strict";var e={frame:{width:1068,height:600},count:5,game:60,level:1,totalScore:100,totalTimes:20,mode:0,scores:[{direction:0,score:5}],directions:function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=[],n=0;n<20;n++)t.push(e);return t}(0)},t=0,n=0,a=function(){t=0,n=0;var a=Date.now()+1e3*e.count,o=a+1e3*e.game;return{event:"start",data:{count:{finishTime:a,duration:e.count},game:{finishTime:o,duration:e.game,totalScore:e.totalScore,totalTimes:e.totalTimes,level:e.level,mode:e.mode,config:{scores:e.scores,directions:e.directions}},status:1,param:{}}}},o=function(e){return{event:0===e?"pause":"continue",data:{status:0===e?3:1}}},c=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:t,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:n;return{event:"finish",data:{score:e,times:a,status:2,param:{}}}},i=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=null;return d(e,n)?t={event:"play",data:{status:1,param:{direction:e}}}:alert("错误: 动作执行错误"),t},s=function(e){var t=null;switch(e){case"start":t=a();break;case"pause":t=o(0);break;case"continue":t=o(1);break;case"finish":t=c();break;case"play":t=i(+(arguments.length<=1?void 0:arguments[1]));break;case"again":t={event:"again",data:{}}}return t};function d(t,n){return t===e.directions[n]}var l=document.getElementById("iframe"),r=l.contentWindow;function u(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),a=1;a<t;a++)n[a-1]=arguments[a];var o=s.apply(void 0,[e].concat(n));if("again"!==o.event)return o?void r.postMessage(o,l.src):console.error("错误: 发送消息数据为空")}var m=0;function v(){var t,n,a=document.querySelectorAll("div.level button"),o=document.querySelectorAll("div.mode button");a.forEach((function(t){t.dataset.code-0===e.level?t.classList.add("btn-primary"):t.classList.remove("btn-primary")})),o.forEach((function(t){t.dataset.code-0===e.mode?t.classList.add("btn-primary"):t.classList.remove("btn-primary")})),t=document.getElementsByName("gameMode"),n=document.getElementsByName("difficulty"),t.forEach((function(t){t.value-0===e.mode?t.checked=!0:t.checked=!1})),n.forEach((function(t){t.value-0===e.level?t.checked=!0:t.checked=!1}))}function f(e){var t=g("pause");0===e?(t.dataset.status="1",t.dataset.event="continue",t.textContent="继续",t.classList.remove("btn-warning"),t.classList.add("btn-success")):(t.dataset.status="0",t.dataset.event="pause",t.textContent="暂停",t.classList.remove("btn-success"),t.classList.add("btn-warning"))}function y(t){var n=g("start"),a=g("pause"),o=g("again-box"),c=g("score"),i=g("action-container");if("start"===t){if(1===e.mode)return;m=1,n.classList.add("d-none"),a.classList.remove("d-none"),o.classList.add("d-none"),i.classList.remove("d-none")}else"finish"===t?(m=2,o.classList.remove("d-none"),a.classList.add("d-none"),c.textContent=e.totalScore+"分",i.classList.add("d-none")):"pause"===t?(m=3,i.classList.add("d-none")):"continue"===t&&(m=1,i.classList.remove("d-none"))}function g(e){return document.getElementById(e)}window.addEventListener("load",(function(){var a,o;window.addEventListener("message",(function(a){console.log("父-接受:",a.data);var o,c=a.data.event;"pause"!==c&&"continue"!==c&&"finish"!==c||("finish"===c&&(e.totalScore=a.data.data.score),u(c),y(c)),"pause"!==c&&"continue"!==c||f("pause"===c?0:1),"play"===c&&(o=a.data.data,n=o.currentTimes,t=o.currentScore),"again"===c&&location.reload()}),!1),v(),function(){var e=document.getElementById("myModal"),t=document.getElementById("myInput");e.addEventListener("click",(function(){t.style.display="block"}))}(),document.querySelectorAll("div.level button").forEach((function(t){t.addEventListener("click",(function(){if(0===m){var n=t.dataset.code;e.level=n-0,v()}else alert("错误: 动作执行错误")}))})),document.querySelectorAll("div.mode button").forEach((function(t){t.addEventListener("click",(function(){if(0===m){var n=t.dataset.code;e.mode=n-0,v()}else alert("错误: 动作执行错误")}))})),document.querySelectorAll("div.events button").forEa