text: !function(e){function t(a){if(n[a])return n[a].exports;var o=n[a]={exports:{},id:a,loaded:!1};return e[a].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function a(){function e(e){e.preventDefault(),l.show(e.currentTarget.getAttribute("data-content-id"))}var t=document.getElementById("game-board"),n=document.getElementById("leader-board"),a=document.getElementById("rules-link"),l=new o,d=new s(t),m=new i(n);a.addEventListener("click",e),function c(){r("/game?"+Date.now()).get(function(e,t){if(200!=t)return setTimeout(c,2500);var n=e.result.games[0];n.players=e.players,d.load(n).play(function(){setTimeout(c,2500)})})}(),function p(){r("/leaderboard?"+Date.now()).get(function(e,t){return 200!=t?setTimeout(p,3e3):(m.load(e),void setTimeout(p,3e3))})}()}var o=n(1),s=n(2),i=n(3),r=n(4);document.addEventListener("DOMContentLoaded",a)},function(e,t){"use strict";function n(){var e=this.container=document.createElement("div"),t=this.wrapper=document.createElement("div"),n=this.closeButton=document.createElement("button"),a=this.contents=document.getElementsByClassName("dialog__content"),o=this.content={},s=this;e.className="dialog",t.className="dialog__wrapper",n.className="dialog__close-button",n.innerHTML="×";for(var i=a.length-1;i>=0;i--){var r=a[i];o[r.id]=r.innerHTML,r.parentElement.removeChild(r)}return n.addEventListener("click",function(t){t.preventDefault(),document.body.removeChild(e)}),e.appendChild(t),e.appendChild(n),{show:s.show.bind(s)}}n.prototype.show=function(e){this.wrapper.innerHTML=this.content[e],document.body.appendChild(this.container)},e.exports=n},function(e,t){"use strict";function n(e){var t=this.container=e,n=this.options={},a=this.board={},o=this.board.players={},s=this;t.className+=" game-board",n.rows=6,n.columns=7,n.interval=500,o.element=document.createElement("div"),o.element.className="game-board__players",o.guestElement=document.createElement("div"),o.guestName=document.createElement("span"),o.homeElement=document.createElement("div"),o.homeName=document.createElement("span"),o.guestElement.className="game-board__guest-player",o.homeElement.className="game-board__home-player",o.homeName.className="game-board__player-name",o.guestName.className="game-board__player-name",o.homeElement.appendChild(o.homeName),o.guestElement.appendChild(o.guestName),o.element.appendChild(o.homeElement),o.element.appendChild(o.guestElement),a.size=n.rows*n.columns,a.element=document.createElement("ul"),a.element.className="game-board__positions",a.positions=[];for(var i=0;i<a.size;i++)a.positions[i]=document.createElement("li"),a.positions[i].className="game-board__position",a.element.appendChild(a.positions[i]);return t.appendChild(o.element),t.appendChild(a.element),{board:s.board,options:s.options,load:s.load.bind(s),play:s.play.bind(s)}}n.prototype.load=function(e){var t=this.board.positions,n=this.container,a=this.board.players;this.options;this.result=e,this.homePlayer=e.players[0],this.guestPlayer=e.players[1],this.move=0,this.moves=e.moves,this.sequence=e.sequence,a.homeName.innerHTML=this.homePlayer.username,a.guestName.innerHTML=this.guestPlayer.username,n.className=n.className.replace("game-board--finished","");for(var o=t.length-1;o>=0;o--)t[o].className="game-board__position";return this},n.prototype.play=function(e,t){var n=this.moves[this.move],a=n.username===this.homePlayer.username?"home-play":"guest-play",o=n.move[0],s=n.move[1];return this.timer&&clearTimeout(this.timer),t&&(this.onMove=t),e&&(this.onFinish=e),this.applyPosition(a,o,s),this.move++,this.onMove&&this.onMove(n),this.moves[this.move]?this.timer=setTimeout(this.play.bind(this),this.options.interval):(this.highlightSequence(this.sequence||[]),this.container.className+=" game-board--finished",void(this.onFinish&&this.onFinish(this.result)))},n.prototype.highlightSequence=function(e){var t=this.board.positions;for(var n in e){for(var a=0,o=e[n],s=-1;s<o[1];s++)a+=this.options.columns;a-=this.options.columns-o[0],t[a].className+=" game-board__position--sequence"}},n.prototype.applyPosition=function(e,t,n){for(var a=this.board.positions,o=0,s=(a.length,"game-board__position "+e),i=-1;n>i;i++)o+=this.options.columns;o-=this.options.columns-t,a[o].className=s},e.exports=n},function(e,t){"use strict";function n(e){var t=this.container=e,n=this.tableHead=document.createElement("thead"),a=this.tableBody=document.createElement("tbody"),o=this,s=document.createElement("tr"),i=document.createElement("td"),r=document.createElement("td"),l=document.createElement("td"),d=document.createElement("td"),m=document.createElement("td");return t.className="leader-board",i.className="leader-board__position",r.className="leader-board__wins",l.className="leader-board__draws",d.className="leader-board__losses",m.className="leader-board__score",i.innerHTML="Melhores jogadores",r.innerHTML="V",l.innerHTML="E",d.innerHTML="D",r.title="Vitórias",l.title="Empates",d.title="Derrotas",t.innerHTML="",s.appendChild(i),s.appendChild(r),s.appendChild(l),s.appendChild(d),n.appendChild(s),t.appendChild(n),t.appendChild(a),{load:o.load.bind(o)}}n.prototype.load=function(e){var t=this.tableBody,n=e.length;t.innerHTML="";for(var a=0;n>a;a++){var o=e[a],s=document.createElement("tr"),i=document.createElement("td"),r=document.createElement("td"),l=document.createElement("td"),d=document.createElement("td");document.createElement("td");s.className="leader-board__player",i.className="leader-board__position",r.className="leader-board__wins",l.className="leader-board__draws",d.className="leader-board__losses",i.innerHTML=["<b>#"+(a+1)+"</b>",o.player+",",o.score,"pt's"].join(" "),r.innerHTML=o.win,l.innerHTML=o.draw,d.innerHTML=o.lost,r.title=o.win+" vitórias",l.title=o.draw+" empates",d.title=o.lost+" derrotas",s.appendChild(i),s.appendChild(r),s.appendChild(l),s.appendChild(d),t.appendChild(s)}},e.exports=n},function(e,t){function n(e){var t=new XMLHttpRequest;return{get:function(n){t.open("GET",a+e),t.setRequestHeader("Content-Type","application/json; charset=UTF-8"),t.addEventListener("load",function(){var e=null;t.response&&(e=JSON.parse(t.response).payload),n(e,t.status)}),t.send()},put:function(n,o){t.open("PUT",a+e),t.setRequestHeader("Content-Type","application/json; charset=UTF-8"),t.addEventListener("load",function(){var e=null;401==t.status&&document.location.reload(),t.response&&(e=JSON.parse(t.response).payload),o(e,t.status)}),t.send(JSON.stringify(n))}}}var a="//"+document.location.host+"/api";e.exports=n}]);