-
Notifications
You must be signed in to change notification settings - Fork 0
/
2378955e816095d76d90.js
1 lines (1 loc) · 4.07 KB
/
2378955e816095d76d90.js
1
!function(){"use strict";var t={};t.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),function(){var e;t.g.importScripts&&(e=t.g.location+"");var s=t.g.document;if(!e&&s&&(s.currentScript&&"SCRIPT"===s.currentScript.tagName.toUpperCase()&&(e=s.currentScript.src),!e)){var r=s.getElementsByTagName("script");if(r.length)for(var i=r.length-1;i>-1&&(!e||!/^http(s?):/.test(e));)e=r[i--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),t.p=e}();const e=document.querySelectorAll(".field__item"),s=["field__naught","field__cross","field__naught_win","field__cross_win"],r=t=>{e.forEach((e=>{e.classList[t]("field__naught_disabled")}))},i=document.querySelector(".res__circle"),o=document.querySelector(".res__cross"),a=(t,e)=>{i.classList[t]("res__circle_active"),o.classList[e]("res__cross_active")};let c=0;const n=t=>c=t,d={xWin:"X Wins",oWin:"0 Wins",draw:"Draw"},l=document.querySelector(".res__score-text"),u=t=>{l.textContent=d[t],h("add")},h=t=>l.classList[t]("res__score-text_show");let _;const m=t=>_=t;var b=t.p+"assets/sounds/dc4dade8c9e44d3b5a6a.mp3";const f=t=>{t.classList.add("field__naught"),(t=>{const e="http://www.w3.org/2000/svg",s=document.createElementNS(e,"svg");s.setAttribute("width","90"),s.setAttribute("height","90"),s.setAttribute("viewBox","0 0 200 200");const r=document.createElementNS(e,"circle");r.setAttribute("cx","100"),r.setAttribute("cy","100"),r.setAttribute("r","90"),r.setAttribute("stroke","rgb(228 10 41)"),r.setAttribute("stroke-width","10"),r.setAttribute("fill","none"),r.setAttribute("stroke-dasharray","565.48"),r.setAttribute("stroke-dashoffset","565.48"),r.classList.add("animated-circle"),s.appendChild(r),t.appendChild(s),requestAnimationFrame((()=>{r.style.strokeDashoffset="0"}))})(t),a("remove","add")},w=t=>{t.classList.add("field__cross"),(t=>{const e="http://www.w3.org/2000/svg",s=document.createElementNS(e,"svg");s.setAttribute("width","90"),s.setAttribute("height","90"),s.setAttribute("viewBox","0 0 200 200");const r=document.createElementNS(e,"line");r.setAttribute("x1","15"),r.setAttribute("y1","15"),r.setAttribute("x2","180"),r.setAttribute("y2","180"),r.setAttribute("stroke","rgb(15 18 198)"),r.setAttribute("stroke-width","8"),r.setAttribute("stroke-dasharray","232.38"),r.setAttribute("stroke-dashoffset","232.38"),r.classList.add("animated-cross");const i=document.createElementNS(e,"line");i.setAttribute("x1","180"),i.setAttribute("y1","15"),i.setAttribute("x2","15"),i.setAttribute("y2","180"),i.setAttribute("stroke","rgb(15 18 198)"),i.setAttribute("stroke-width","10"),i.setAttribute("stroke-dasharray","232.38"),i.setAttribute("stroke-dashoffset","232.38"),i.classList.add("animated-cross"),s.appendChild(r),s.appendChild(i),t.appendChild(s),requestAnimationFrame((()=>{r.style.strokeDashoffset="0",i.style.strokeDashoffset="0"}))})(t),a("add","remove")},A=t=>{t.classList.contains("field__item")&&0===t.children.length&&(c%2==0?f(t):w(t),new Audio(b).play(),++c)},g=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]];let p=0,v=0;const y=(t,s,i)=>{for(let o=0;o<g.length;o++)e[g[o][0]].classList.contains(t)&&e[g[o][1]].classList.contains(t)&&e[g[o][2]].classList.contains(t)&&(n(0),r("add"),a("remove","remove"),m(!0),setTimeout((()=>{e[g[o][0]].classList.add(`${t}_win`),e[g[o][1]].classList.add(`${t}_win`),e[g[o][2]].classList.add(`${t}_win`),s.textContent="xWin"===i?++v:++p,u(i)}),250))},L=document.querySelector(".res__score-naughts"),k=document.querySelector(".res__score-crosses"),S=()=>{y("field__cross",k,"xWin"),y("field__naught",L,"oWin"),9===c&&(r("add"),a("remove","remove"),setTimeout((()=>{u("draw")}),250))},x={".field":t=>{_||(A(t.target),S())},".newgame__button":()=>{n(0),e.forEach((t=>{t.classList.length>1&&(t.textContent="",s.forEach((e=>t.classList.remove(e))))})),r("remove"),a("add","remove"),h("remove"),m(!1)}};window.addEventListener("click",(t=>((t,e)=>{const s=t.target;for(const r in e)if(s.closest(r)){e[r](t);break}})(t,x)))}();