{"size": 8911, "ext": "js", "max_stars_repo_path": "build/js/app.min.js", "max_stars_repo_name": "my-repositories/Hangman", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "build/js/app.min.js", "max_issues_repo_name": "my-repositories/Hangman", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "build/js/app.min.js", "max_forks_repo_name": "my-repositories/Hangman", "max_forks_repo_forks_event_min_datetime": "2018-03-25T03:31:19.000Z", "max_forks_repo_forks_event_max_datetime": "2018-03-25T03:31:19.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 8911.0, "max_line_length": 8911, "alphanum_fraction": 0.7412187184}
"use strict";function _toConsumableArray(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _toConsumableArray(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var a=e[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}return function(e,n,a){return n&&t(e.prototype,n),a&&t(e,a),e}}();!function(){var t={winGame:'\n\t\t\t<h2>Игра пройдена!</h2>\n\t\t\t<p>Желаете начать сначала?</p>\n\t\t\t<footer>\n\t\t\t<input type="button" value="Нет" class="btn cancel">\n\t\t\t<input type="button" value="Да" class="btn confirm">\n\t\t\t</footer>\n\t\t',nextLevel:'\n\t\t\t<h2>Уровень ##LEVEL## пройден!</h2>\n\t\t\t<p>Перейти на следующий уровень?</p>\n\t\t\t<footer>\n\t\t\t<input type="button" value="Отмена" class="btn cancel">\n\t\t\t<input type="button" value="Продолжить" class="btn confirm">\n\t\t\t</footer>\n\t\t',gameOver:'\n\t\t\t<h2>Игра окончена!</h2>\n\t\t\t<p>Попробовать еще?</p>\n\t\t\t<footer>\n\t\t\t<input type="button" value="Нет" class="btn cancel">\n\t\t\t<input type="button" value="Да" class="btn confirm">\n\t\t\t</footer>\n\t\t'},e=function(){function e(){_classCallCheck(this,e),this.game=document.querySelector(".game"),this.title=this.game.querySelector(".game-title"),this.question=this.game.querySelector(".game-question"),this.answer=this.game.querySelector(".game-answer"),this.keyboard=this.game.querySelector(".game-keyboard"),this.keyboardButtons=[],this.hangman=new Hangman,this.canvas=new Canvas,this.CreateKeyBoard(),this.AddEvents()}return _createClass(e,[{key:"Init",value:function(){this.hangman.Run(),this.LoadNextLevel()}},{key:"CreateKeyBoard",value:function(){for(var t=["йцукенгшщзхъ","фывапролджэ","ячсмитьбю"],e=0,n=t.length;e<n;++e){var a=document.createElement("div");a.className="row";for(var s=0,i=t[e].length;s<i;++s){var r=this.keyboardButtons.length;this.keyboardButtons[r]=document.createElement("span"),this.keyboardButtons[r].className="game-keyboard-button",this.keyboardButtons[r].innerText=t[e][s],a.append(this.keyboardButtons[r])}this.keyboard.append(a)}}},{key:"LoadNextLevel",value:function(){this.ResetGameArea(),this.hangman.ChangeLevel(),this.title.innerText="Вопрос №"+this.hangman.level+" из "+this.hangman.taskCount,this.question.innerText=this.hangman.currentTask.question;for(var t=0,e=this.hangman.currentTask.answer.length;t<e;t++){var n=document.createElement("span");n.className="game-answer-letter",n.innerText="_",this.answer.append(n)}this.answerLetters=this.answer.querySelectorAll(".game-answer-letter")}},{key:"ResetGameArea",value:function(){this.canvas.Clear();for(var t=this.keyboard.querySelectorAll(".game-keyboard-button"),e=0,n=t.length;e<n;e++)t[e].classList.remove("disabled");for(;this.answer.firstChild;)this.answer.removeChild(this.answer.firstChild)}},{key:"CheckGame",value:function(){var e=this.hangman.GetGameState();return!!e.status||(ShowPopup("gameover"==e.message?{body:t.gameOver,onconfirm:this.Init.bind(this)}:"wingame"==e.message?{body:t.winGame,onconfirm:this.Init.bind(this)}:{body:t.nextLevel.replace("##LEVEL##",this.hangman.level),onconfirm:this.LoadNextLevel.bind(this)}),!1)}},{key:"AddEvents",value:function(){var t=this;this.keyboard.addEventListener("click",function(e){var n=e.target;n.classList.contains("game-keyboard-button")&&t.CheckGame()&&-1!=t.FindKeyByCode(n.innerText)&&(n.classList.add("disabled"),t.HandleStep(n.innerText),t.CheckGame())}),document.body.addEventListener("keyup",function(e){var n=t.FindKeyByCode(e.key);-1!=n&&(n.classList.remove("active"),n.click())}),document.body.addEventListener("keydown",function(e){var n=t.FindKeyByCode(e.key);-1!=n&&n.classList.add("active")})}},{key:"HandleStep",value:function(t){this.HasOccurrences(t)||(--this.hangman.life,this.canvas.Draw())}},{key:"HasOccurrences",value:function(t){for(var e=!1,n=0,a=this.hangman.currentTask.answer.length;n<a;n++)this.hangman.currentTask.answer[n].toLowerCase()===t&&(this.answerLetters[n].innerText=t,--this.hangman.remainingLetters,e=!0);return e}},{key:"FindKeyByCode",value:function(t){t=this.ParseKey(t);var e=this.keyboard.querySelectorAll(".game-keyboard-button");return 0==(e=[].concat(_toConsumableArray(e)).filter(function(e){return e.innerText==t})).length||e[0].classList.contains("disabled")?-1:e.shift()}},{key:"ParseKey",value:function(t){var e="f,dult`;pbqrkvyjghcnea[wxio]sm'.z".indexOf(t.toLowerCase());return-1===e?t:"абвгдеёжзийклмнопрстуфхцчшщъыьэюя"[e]}}]),e}();window.Application=e}();var _createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var a=e[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}return function(e,n,a){return n&&t(e.prototype,n),a&&t(e,a),e}}();!function(){var t=[{x:150,y:30,r:20},{x1:150,y1:50,x2:150,y2:100},{x1:150,y1:55,x2:120,y2:80},{x1:150,y1:55,x2:180,y2:80},{x1:150,y1:100,x2:180,y2:125},{x1:150,y1:100,x2:120,y2:125}],e=function(){function e(){_classCallCheck(this,e),this.counter=0,this.c=document.querySelector(".game-canvas"),this.ctx=this.c.getContext("2d")}return _createClass(e,[{key:"Clear",value:function(){this.ctx.clearRect(0,0,350,170),this.counter=0}},{key:"Draw",value:function(){this.ctx.beginPath(),1==++this.counter?this.ctx.arc(t[0].x,t[0].y,t[0].r,0,2*Math.PI,!1):5===this.counter&&this.Kill(),this.ctx.moveTo(t[this.counter].x1,t[this.counter].y1),this.ctx.lineTo(t[this.counter].x2,t[this.counter].y2),this.ctx.stroke()}},{key:"Kill",value:function(){this.ctx.moveTo(155,22),this.ctx.lineTo(162,28),this.ctx.moveTo(162,22),this.ctx.lineTo(155,28),this.ctx.moveTo(137,22),this.ctx.lineTo(145,28),this.ctx.moveTo(145,22),this.ctx.lineTo(137,28)}}]),e}();window.Canvas=e}();var _createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var a=e[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}return function(e,n,a){return n&&t(e.prototype,n),a&&t(e,a),e}}();!function(){var t=[{question:"Полосатая лошадка?",answer:"Зебра"},{question:"Столица Казахстана?",answer:"Астана"},{question:"Один из друзей Винни-Пуха?",answer:"Ослик"},{question:"Единица мощности?",answer:"Ватт"},{question:"Континентальный «кенгурятник»?",answer:"Австралия"}],e=function(){function e(){_classCallCheck(this,e),this.taskCount=t.length,this.life=5}return _createClass(e,[{key:"Run",value:function(){this.level=0,this.tasks=[].concat(_toConsumableArray(Array(this.taskCount).keys()))}},{key:"ChangeLevel",value:function(){++this.level,this.life=5,this.currentTask=this.GetRandomTask(),this.remainingLetters=this.currentTask.answer.length}},{key:"GetGameState",value:function(){return 0==this.life?{status:!1,message:"gameover"}:this.remainingLetters>0?{status:!0}:this.level==this.taskCount?{status:!1,message:"wingame"}:{status:!1,message:"nextlevel"}}},{key:"GetRandomTask",value:function(){if(this.tasks.length>0){var e=Math.floor(Math.random()*this.tasks.length),n=this.tasks.splice(e,1).shift();return t[n]}}}]),e}();window.Hangman=e}(),document.addEventListener("DOMContentLoaded",function(){(new Application).Init()});var ShowPopup=function(){function t(t){var n=this;e=this,this.params=t,this.overlay=document.createElement("div"),this.overlay.className="overlay",document.body.append(this.overlay),this.popup=document.createElement("div"),this.popup.className="popup",this.popup.innerHTML=this.params.body,this.closeButton=document.createElement("span"),this.closeButton.title="Close the popup",this.closeButton.className="popup-close",this.popup.prepend(this.closeButton),document.body.append(this.popup),setTimeout(function(){return n.overlay.classList.add("animated")},100),this.popup.addEventListener("click",this.OnPopupClick.bind(this))}var e=void 0;return t.prototype.OnPopupClick=function(t){t.target.classList.contains("popup-close")||t.target.classList.contains("cancel")?("function"==typeof this.params.oncancel&&this.params.oncancel(),this.Close()):t.target.classList.contains("confirm")&&("function"==typeof this.params.onconfirm&&this.params.onconfirm(),this.Close())},t.prototype.Close=function(){this.popup.removeEventListener("click",this.OnPopupClick),this.overlay.classList.remove("animated"),this.popup.removeChild(this.closeButton),this.popup.innerHTML="",document.body.removeChild(this.popup),document.body.removeChild(this.overlay),e=void 0},function(n){return e&&e.Close(),new t(n)}}();