text: (this.webpackJsonpminesweeper=this.webpackJsonpminesweeper||[]).push([[0],{13:function(e,t,a){e.exports=a(23)},18:function(e,t,a){},19:function(e,t,a){},22:function(e,t,a){},23:function(e,t,a){"use strict";a.r(t);var n=a(0),l=a.n(n),r=a(7),o=a.n(r),c=a(8),s=a(9),i=a(12),m=a(11),u=Object(n.createContext)(),g=function(){var e=Object(n.useContext)(u),t=e.getIsRevealMode();return l.a.createElement("button",{className:"btn btn-outline-success my-2 my-sm-0 ml-auto ".concat(t?"active":""),onClick:function(){e.setIsRevealMode(!t)}},l.a.createElement("i",{className:"fa fa-eye"})," Reveal All Cells")},d=function(){return l.a.createElement("nav",{className:"navbar navbar-expand-md navbar-dark bg-dark"},l.a.createElement("a",{className:"navbar-brand",onClick:function(e){return e.preventDefault()},href:"/#"},l.a.createElement("i",{className:"fa fa-bomb"})," ReactJS Minesweeper"),l.a.createElement("button",{className:"navbar-toggler collapsed",type:"button","data-toggle":"collapse","data-target":"#navbarCollapse","aria-controls":"navbarCollapse","aria-expanded":"false","aria-label":"Toggle navigation"},l.a.createElement("span",{className:"navbar-toggler-icon"})),l.a.createElement("div",{className:"navbar-collapse collapse",id:"navbarCollapse"},l.a.createElement(g,null)))},f=a(2),p=a(5),b=a(1),v=(a(18),{header:"Well Done!",content:l.a.createElement("span",null,"You did it!",l.a.createElement("i",{className:"fa fa-trophy ml-1"})),type:"success",timeout:null}),E={header:"Oy Vey!",content:l.a.createElement("span",null,"It's a mine",l.a.createElement("i",{className:"fa fa-bomb ml-1"})),type:"danger",timeout:null},N={header:"Out Of Flags!",content:l.a.createElement("span",null,"Try to remove a flag before adding a new one",l.a.createElement("i",{className:"fa fa-flag ml-1"})),type:"secondary",timeout:5e3},T=function(e){var t=e.cellRow,a=e.cellCol,r=e.isMine,o=e.mineNeighbours,c=e.isRevealed,s=e.isFlagged,i=e.isLostTrigger,m=e.missedMark,g=e.clickHandler,d=e.rightClickHandler,f=e.touchHandler,p=Object(n.useContext)(u).getIsRevealMode(),b=null;return l.a.createElement("div",{className:"game-cell alert alert-".concat(i?"danger":m?"secondary":"primary"),style:{width:30,height:30}},l.a.createElement("span",null,r?l.a.createElement("i",{className:"fa fa-bomb fa-md"}):s?l.a.createElement("i",{className:"fa fa-times",style:{color:"#ffb000"}}):o>0?l.a.createElement(n.Fragment,null,o):null),l.a.createElement("button",{className:"btn btn-warning game-btn d-block",onClick:function(e){return g(e,t,a)},onContextMenu:function(e){return d(e,t,a)},onTouchStart:function(){return function(e,t){b=setTimeout((function(){f(e,t)}),500)}(t,a)},onTouchEnd:function(){clearTimeout(b)},style:{opacity:c?0:p?.5:1,cursor:c?"auto":"pointer"}},s?l.a.createElement("i",{className:"fa fa-flag"}):null))},h=(a(19),function(e,t,a,n){for(var l=function(e){e.map((function(n,l){return n.map((function(n,r){return e[l][r].mineNeighbours=function(n,l){if(e[n][l].isMine)return-1;for(var r=0,o=-1;o<=1;o++){var c=n+o;if(!(c<0||c>=t))for(var s=-1;s<=1;s++){var i=l+s;i<0||i>=a||e[c][i].isMine&&r++}}return r}(l,r)}))}))},r=0;r<n;){var o=Math.floor(Math.random()*t),c=Math.floor(Math.random()*a);e[o][c].isMine||(e[o][c].isMine=!0,r++),l(e)}}),O=a(10),M=function(e){var t=e.remainingFlags;return l.a.createElement(n.Fragment,null,l.a.createElement("div",{className:"bs-component"},l.a.createElement("div",{className:"alert"},l.a.createElement("h3",{className:"mr-1"},l.a.createElement("strong",null,t),l.a.createElement("i",{className:"fa fa-flag ml-1"})))))};M.prototype={remainingFlags:a.n(O).a.number};var S=M,y=function(e){var t=e.alert;return null!==t&&l.a.createElement("div",{className:"bs-component"},l.a.createElement("div",{className:"alert alert-".concat(t.type)},l.a.createElement("strong",null,t.header)," ",t.content))},C=function(){var e=Object(n.useContext)(u),t=e.getTotalRows(),a=e.getTotalCols(),r=e.getTotalMines(),o=e.getBoardTimestamp(),c=function(){return JSON.parse(localStorage.getItem("board"))},s=Object(n.useState)(c),i=Object(b.a)(s,2),m=i[0],g=i[1],d=Object(n.useState)("true"===localStorage.getItem("gameFreeze")||!1),O=Object(b.a)(d,2),M=O[0],C=O[1],R=Object(n.useState)(parseInt(localStorage.getItem("remainingFlags"))||r),j=Object(b.a)(R,2),I=j[0],w=j[1],k=Object(n.useState)(parseInt(localStorage.getItem("numberOfCorrectFlags"))||0),F=Object(b.a)(k,2),x=F[0],_=F[1],L=function(e){!function(e){localStorage.setItem("gameFreeze",e)}(e),C(e)},A=function(e){!function(e){localStorage.setItem("remainingFlags",e)}(e),w(e)},D=function(e){!function(e){localStorage.setItem("numberOfCorrectFlags",e)}(e),_(e)},B=Object(n.useState)(null),H=Object(b.a)(B,2),P=H[0],J=H[1],V=Object(n.useCallback)((function(e){J(e),e&&e.timeout>0&&setTimeout((function(){return J(null)}),e.timeout)}),[]);Object(n.useEffect)((function(){c()||(g(function(e,t,a){var n=[];return function(e,t,a){for(var n=0;n<t;n++){e.push([]);for(var l=0;l<a;l++)e[n].push({cellRow:n,cellCol:l,isRevealed:!1,isMine:!1,isFlagged:!1,isLostTrigger:!1,missedMark:!1,mineNeighbours:0})}}(n,e,t),h(n,e,t,a),n}(t,a,r)),D(0),A(r),L(!1),J(null))}),[t,a,r,o]),Object(n.useEffect)((function(){localStorage.setItem("board",JSON.stringify(m))}),[m]);var W=Object(n.useCallback)((function(e,t){e===t?(V(v),L(!0)):(V(null),L(!1))}),[V]);Object(n.useEffect)((function(){return W(x,r)}),[x,r,V,W]);var z=function(e,t,a){Y(e.shiftKey,t,a)},G=function(e,t,a){return e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),Y(!0,t,a),!1},K=function(e,t){Y(!0,e,t)},Y=function(e,t,a){var n=m[t][a];if(!M&&!n.isRevealed)if(e)q(t,a);else if(!n.isFlagged)return n.isMine?(V(E),n.isLostTrigger=!0,g(Object(p.a)(m).map((function(e){return e.map((function(e){return e.isMine&&!e.isFlagged||e.isFlagged&&!e.isMine?Object(f.a)({},e,{isRevealed:!0,missedMark:!0}):e}))}))),void L(!0)):void(n.isFlagged||Q(t,a))},q=function(e,t){var a=Object(p.a)(m),n=a[e][t];if(n.isFlagged)!function(e,t,a){A(e+1),t&&D(a-1)}(I,n.isMine,x);else{if(!(I>0))return void V(N);!function(e,t,a){A(e-1),n.isMine&&D(a+1)}(I,n.isMine,x)}a[e][t].isFlagged=!a[e][t].isFlagged,g(a)},Q=function(e,t){var a=Object(p.a)(m);a=U(a,e,t),g(a)},U=function(e,t,a){var n=e[t][a];return n.isRevealed=!0,0===n.mineNeighbours&&(e=X(e,n)),e},X=function(e,n){for(var l=n.cellRow,r=n.cellCol,o=-1;o<=1;o++){var c=l+o;if(!(c<0||c>=t))for(var s=-1;s<=1;s++){var i=r+s;if(!(i<0||i>=a)){var m=e[c][i];m.isRevealed||m.isMine||m.isFlagged||U(e,m.cellRow,m.cellCol)}}}return e};return l.a.createElement(n.Fragment,null,l.a.createElement(y,{alert:P}),l.a.createElement("div",{className:"container"},l.a.createElement(S,{remainingFlags:I})),l.a.createElement("div",{className:"game-board",style:{gridTemplateColumns:"repeat(".concat(a,", ").concat(30,"px)")}},m&&m.map((function(e,t){return e.map((function(e,a){return l.a.createElement("div",{key:"".concat(t,",").concat(a)},l.a.createElement(T,{cellRow:t,cellCol:a,isMine:e.isMine,mineNeighbours:e.mineNeighbours,isRevealed:e.isRevealed,isFlagged:e.isFlagged,isLostTrigger:e.isLostTrigger,missedMark:e.missedMark,clickHandler:z,rightClickHandler:G,touchHandler:K}))}))}))))},R=function(e,t){switch(t.type){case"SET_TOTAL_ROWS":return Object(f.a)({},e,{totalRows:t.payload});case"SET_TOTAL_COLS":return Object(f.a)({},e,{totalCols:t.payload});case"SET_TOTAL_MINES":return Object(f.a)({},e,{totalMines:t.payload});case"SET_BOARD_TIMESTAMP":return Object(f.a)({},e,{boardTimestamp:t.payload});case"SET_IS_REVEAL_MODE":return Object(f.a)({},e,{isRevealMode:t.payload});default:return}},j=function(e){var t={totalRows:9,totalCols:9,totalMines:10,boardTimestamp:(new Date).getTime(),isRevealMode:!1},a=Object(n.useReducer)(R,t),r=Object(b.a)(a,2),o=r[0],c=r[1];return l.a.createElement(u.Provider,{value:{getTotalRows:function(){var e=parseInt(localStorage.getItem("totalRows"));return e||o.totalRows},getTotalCols:function(){var e=parseInt(localStorage.getItem("totalCols"));return e||o.totalCols},getTotalMines:function(){var e=parseInt(localStorage.getItem("totalMines"));return e||o.totalMines},getBoardTimestamp:function(){var e=localStorage.getItem("boardTimestamp");return e||o.boardTimestamp},getIsRevealMode:function(){var e="true"===localStorage.getItem("isRevealMode");return e||o.isRevealMode},setTotalRows:function(e){!function(e){localStorage.setItem("totalRows",e)}(e),c({type:"SET_TOTAL_ROWS",payload:e})},setTotalCols:function(e){!function(e){localStorage.setItem("totalCols",e)}(e),c({type:"SET_TOTAL_COLS",payload:e})},setTotalMines:function(e){!function(e){localStorage.setItem("totalMines",e)}(e),c({type:"SET_TOTAL_MINES",payload:e})},setBoardTimestamp:function(e){!function(e){localStorage.setItem("boardTimestamp",e)}(e),c({type:"SET_BOARD_TIMESTAMP",payload:e})},setIsRevealMode:function(e){!function(e){localStorage.setItem("isRevealMode",e)}(e),c({type:"SET_IS_REVEAL_MODE",payload:e})}}},e.children)},I=(a(22),function(){var e=Object(n.useContext)(u),t=Object(n.useState)(e.getTotalRows()),a=Object(b.a)(t,2),r=a[0],o=a[1],c=Object(n.useState)(e.getTotalCols()),s=Object(b.a)(c,2),i=s[0],m=s[1],g=Object(n.useState)(e.getTotalMines()),d=Object(b.a)(g,2),f=d[0],p=d[1];return l.a.createElement("form",{onSubmit:function(t){t.preventDefault(),e.setTotalRows(parseInt(r)),e.setTotalCols(parseInt(i)),e.setTotalMines(parseInt(f)),localStorage.removeItem("board"),e.setBoardTimestamp((new Date).getTime())}},l.a.createElement("div",{className:"row"},l.a.createElement("div",{className:"col-md-8 col-centered mx-auto"},l.a.createElement("div",{className:"row"},l.a.createElement("div",{className:"col-md-3"},l.a.createElement("div",{className:"input-group mb-1"},l.a.createElement("div",{className:"input-group-prepend"},l.a.createElement("span",{className:"input-group-text"},l.a.createElement("i",{className:"fa fa-align-justify","aria-hidden":"true"}))),l.a.createElement("input",{id:"totalRowsInput",className:"form-control",type:"number",min:"1",max:"50",value:r,onChange:function(e){return o(e.target.value)},"aria-label":"Rows"}))),l.a.createElement("div",{className:"col-md-3"},l.a.createElement("div",{className:"input-group mb-1"},l.a.createElement("div",{className:"input-group-prepend"},l.a.createElement("span",{className:"input-group-text"},l.a.createElement("i",{className:"fa fa-align-justify fa-rotate-90","aria-hidden":"true"}))),l.a.createElement("input",{id:"totalColsInput",className:"form-control",type:"number",min:"1",max:"50",value:i,onChange:function(e){return m(e.target.value)},"aria-label":"Cols"}))),l.a.createElement("div",{className:"col-md-3"},l.a.createElement("div",{className:"input-group mb-1"},l.a.createElement("div",{className:"input-group-prepend"},l.a.createElement("span",{className:"input-group-text"},l.a.createElement("i",{className:"fa fa-bomb","aria-hidden":"true"}))),l.a.createElement("input",{id:"totalMinesInput",className:"form-control",type:"number",min:"1",max:r*i,value:f,onChange:function(e){return p(e.target.value)},"aria-label":"Mines"}))),l.a.createElement("div",{className:"col-md-3 mb-1"},l.a.createElement("button",{className:"btn btn-success btn-block",type:"submit"},"New Game"))))))}),w=function(){return l.a.createElement("div",{className:"continer text-center mb-3"},l.a.createElement("h4",{className:"text-light"},"How To Play"),l.a.createElement("span",{className:"text-light mr-2 d-none d-sm-inline"},"Click to reveal a cell."),l.a.createElement("span",{className:"text-light mr-2 d-block d-sm-none"},"Touch to reveal a cell."),l.a.createElement("span",{className:"text-light mr-2 d-none d-sm-inline"},"Shift + Click or Right Click to set a flag."),l.a.createElement("span",{className:"text-light mr-2 d-block d-sm-none"},"Touch Longer to set a flag."),l.a.createElement("span",{className:"text-light"},"Flag all mines for the win!"))},k=function(e){Object(i.a)(a,e);var t=Object(m.a)(a);function a(e){var n;return Object(c.a)(this,a),(n=t.call(this,e)).state={hasError:!1},n}return Object(s.a)(a,[{key:"componentDidCatch",value:function(e,t){localStorage.clear()}},{key:"render",value:function(){return this.state.hasError?l.a.createElement("div",{className:"container"},l.a.createElement("h1",{className:"text-white"},"Something went wrong.")):this.props.children}}],[{key:"getDerivedStateFromError",value:function(e){return{hasError:!0}}}]),a}(l.a.Component),F=function(){return l.a.createElement(k,null,l.a.createElement(j,null,l.a.createElement("div",{className:"minesweeperApp"},l.a.createElement(d,null),l.a.createElement("div",{className:"container mt-3"},l.a.createElement(I,null)),l.a.createElement("div",{className:"container jumbotron text-center mt-3 py-4 dark-background"},l.a.createElement("div",{className:"container game-board-container"},l.a.createElement(C,null))),l.a.createElement(w,null))))};o.a.render(l.a.createElement(F,null),document.getElementById("root"))}},[[13,1,2]]]);
  //# sourceMappingURL=main.282b443a.chunk.js.map