From 6f27e55b11a6487beb8895b1ff6afc33dd686e45 Mon Sep 17 00:00:00 2001 From: Maxim Date: Fri, 2 Jun 2023 16:24:05 +0300 Subject: [PATCH] Minor changes --- .gitignore | 4 +-- dist/42e40244edcf332efc9a.js | 1 - dist/bundle.a1a836c153ee5bb09b0f.js | 1 - dist/index.html | 2 +- jest.config.js | 1 + package.json | 3 +- src/__tests__/Domino/Domino.test.js | 2 +- .../DominoGrid/boardPositioning.test.js | 4 +-- .../DominoGrid/checkValidity.test.js | 6 ++-- src/__tests__/DominoGrid/findAdjSum.test.js | 6 ++-- .../DominoGrid/findAvailablePosition.test.js | 6 ++-- .../DominoGrid/findDirections.test.js | 4 +-- .../DominoGrid/findEmptyCells.test.js | 4 +-- .../DominoGrid/generateDominoes.test.js | 2 +- src/__tests__/DominoGrid/isSolved.test.js | 6 ++-- src/__tests__/DominoGrid/placeDomino.test.js | 4 +-- .../DominoGrid/shuffleDominoes.test.js | 2 +- .../DominoGrid/unPlaceInitialDomino.test.js | 4 +-- src/__tests__/DominoGrid/validatePos.test.js | 6 ++-- src/assets/domino-icon.ico | Bin 0 -> 2086 bytes src/data/LocalStorageManager.js | 9 +++++- src/electron/main.js | 26 +++++++++++++++--- src/eventHandlers/BoardEventHandler.js | 24 ++++++++++------ src/eventHandlers/SolveBoardEventHandler.js | 6 +--- src/gameLogic/DominoGrid.js | 17 +++++++++++- src/helperClasses/BoardManager.js | 3 -- src/helpers/copyFunc.js | 7 ++--- src/index.js | 7 ++++- 28 files changed, 104 insertions(+), 63 deletions(-) delete mode 100644 dist/42e40244edcf332efc9a.js delete mode 100644 dist/bundle.a1a836c153ee5bb09b0f.js create mode 100644 src/assets/domino-icon.ico diff --git a/.gitignore b/.gitignore index 45b657e..917d04a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ node_modules dist -release-builds -savedSolutions \ No newline at end of file +release-builds* +savedSolutions diff --git a/dist/42e40244edcf332efc9a.js b/dist/42e40244edcf332efc9a.js deleted file mode 100644 index ddbd0ff..0000000 --- a/dist/42e40244edcf332efc9a.js +++ /dev/null @@ -1 +0,0 @@ -import"./template.html";import"./styles.css";import initialBoards from"./initialBoards/initialBoards";import UI from"./view/UI";import Section from"./components/Section";import copyDominoGrid from"./helpers/copyFunc";import Message from"./components/Message";import BoardSelect from"./components/BoardSelect";import Modal from"./components/Modal";import ThemeManager from"./view/ThemeManager";import LocalStorageManager from"./data/LocalStorageManager";import BoardEventHandler from"./eventHandlers/BoardEventHandler";import ModalEventHandlers from"./eventHandlers/ModalEventHandler";import SolveBoardEventHandler from"./eventHandlers/SolveBoardEventHandler";let boards,currentBoard,solveYourselfBoard;const STORE_KEY="SAVED_BOARDS",localStorageManager=new LocalStorageManager(STORE_KEY);localStorageManager.existBoards()?(boards=localStorageManager.getBoards(),[currentBoard]=boards):(localStorageManager.saveBoards(initialBoards),[currentBoard]=initialBoards);const themeManager=new ThemeManager;themeManager.init();const menuSection=new Section(document.querySelector(".menu-section")),addBoardSection=new Section(document.querySelector(".add-board")),solveBoardSection=new Section(document.querySelector(".solve-board")),messageElement=new Message(document.querySelector(".message")),boardSelect=new BoardSelect(document.getElementById("standard-select")),modalError=new Modal(document.querySelector(".modal"),document.querySelector(".overlay")),modalInfo=new Modal(document.querySelector(".modal__info"),document.querySelector(".overlay")),ui=new UI(menuSection,addBoardSection,solveBoardSection,messageElement,boardSelect,modalError,modalInfo);ui.displayBoard(currentBoard);const boardEventHandler=new BoardEventHandler(ui,currentBoard,boards,localStorageManager);boardEventHandler.init();const modalEventHandler=new ModalEventHandlers(ui);modalEventHandler.init();const solveBoardEventHandler=new SolveBoardEventHandler(ui,solveYourselfBoard,currentBoard,boardEventHandler);solveBoardEventHandler.init(),ui.boardSelect.element.addEventListener("change",(e=>{currentBoard=boards[e.target.value];const o=copyDominoGrid(currentBoard);boardEventHandler.setCurrentBoard(o),solveBoardEventHandler.setCurrentBoard(o),ui.clearBoard(o),ui.displayBoard(o),ui.hideButtons("clearBoard")})); \ No newline at end of file diff --git a/dist/bundle.a1a836c153ee5bb09b0f.js b/dist/bundle.a1a836c153ee5bb09b0f.js deleted file mode 100644 index 12d00b7..0000000 --- a/dist/bundle.a1a836c153ee5bb09b0f.js +++ /dev/null @@ -1 +0,0 @@ -(()=>{"use strict";var e={91:e=>{e.exports=function(e,t){return t||(t={}),e?(e=String(e.__esModule?e.default:e),t.hash&&(e+=t.hash),t.maybeNeedQuotes&&/[\t\n\f\r "'=<>`]/.test(e)?'"'.concat(e,'"'):e):e}},962:(e,t,o)=>{e.exports=o.p+"42e40244edcf332efc9a.js"},548:(e,t,o)=>{e.exports=o.p+"b88d04fba731603756b1.css"},637:(e,t,o)=>{e.exports=o.p+"images/delete-icon.svg"}},t={};function o(i){var n=t[i];if(void 0!==n)return n.exports;var s=t[i]={exports:{}};return e[i](s,s.exports,o),s.exports}o.m=e,o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},o.d=(e,t)=>{for(var i in t)o.o(t,i)&&!o.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e;o.g.importScripts&&(e=o.g.location+"");var t=o.g.document;if(!e&&t&&(t.currentScript&&(e=t.currentScript.src),!e)){var i=t.getElementsByTagName("script");i.length&&(e=i[i.length-1].src)}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),o.p=e})(),o.b=document.baseURI||self.location.href,(()=>{var e=o(91),t=o.n(e),i=new URL(o(548),o.b),n=new URL(o(962),o.b),s=new URL(o(637),o.b);t()(i),t()(n),t()(s);class a{constructor(e,t,o){this.value=e,this.row=t,this.col=o,this.done=!1}}class r{constructor(e,t){this.a=e,this.b=t,this.direction=Math.round(3*Math.random()),this.tipRow=null,this.tipCol=null,this.rotated=!1}getValue(e,t){return e===this.tipRow&&t===this.tipCol?this.a:this.b}static setupDomino(e,t,o){const[i,n]=t;e.direction=o,e.tipRow=i,e.tipCol=n}static areTheSame(e,t){return e.a===t.a&&e.b===t.b||e.a===t.b&&e.b===t.a}static rotateDomino(e){e.rotated=!e.rotated,[e.a,e.b]=[e.b,e.a]}}function l(e){const t=new c(e.size,[]),o=Array(e.size).fill(0).map((()=>Array(e.size).fill(0)));for(let i=0;i{i.push(d(e))}));const n=[];return e.cellValues.forEach((e=>{n.push(h(e,t))})),t.board=o,t.availableDominos=i,t.cellValues=n,t}function d(e){const t=structuredClone(e);return Object.setPrototypeOf(t,r.prototype),t}function h(e,t){const o=structuredClone(e);return Object.setPrototypeOf(o,a.prototype),o.dominoGrid=t,o}class c{constructor(e,t=null){this.size=e,this.cellValues=[],t?(this.board=t,this.board.forEach((e=>{e.forEach((e=>{e instanceof a&&this.cellValues.push(e)}))}))):this.generateBoard(),this.availableDominos=c.generateDominoes(),this.shuffleDominoes()}generateBoard(){const e=80+Math.floor(11*Math.random());this.board=Array(this.size).fill(0).map((()=>Array(this.size).fill(0)));let t=new c(this.size,Array(this.size).fill(0).map((()=>Array(this.size).fill(0))));[t]=t.findSolution();const o=t.board;for(let i=0;i0){const t=new a(e,i,n);this.cellValues.push(t),this.board[i][n]=t}}}static generateDominoes(){const e=[];for(let t=1;t<6;t+=1)for(let o=t+1;o<=6;o+=1)e.push(new r(t,o));return e}static offsets=[[-1,0],[0,1],[1,0],[0,-1]];shuffleDominoes(){for(let e=this.availableDominos.length-1;e>0;e-=1){const t=Math.floor(Math.random()*(e+1));[this.availableDominos[e],this.availableDominos[t]]=[this.availableDominos[t],this.availableDominos[e]]}}placeDomino(e){const t=e.tipRow,o=e.tipCol,[i,n]=c.offsets[e.direction],s=t+i,a=o+n;this.board[t][o]=e,this.board[s][a]=e}unPlaceDomino(e){const t=e.tipRow,o=e.tipCol,[i,n]=c.offsets[e.direction],s=t+i,a=o+n;this.board[t][o]=0,this.board[s][a]=0}isSameInRow(e,t,o){for(let i=0;i=0&&e=0&&t!e.done));if(0!==this.cellValues.length&&e){const t=e,o=this.findEmptyAdjCells(t);for(const[e,t]of o){const o=this.findDirections(e,t);if(0!==o.length)return[[e,t],o]}return null}for(let e=0;e!r.areTheSame(t,e)))}returnInitialDomino(e,t){this.availableDominos.splice(t,0,e)}markFinishedCells(){const e=[];return this.cellValues.forEach((t=>{t.done||this.isSolved(t)&&(t.done=!0,e.push(t))})),e}static unMarkFinishedCells(e){e.forEach((e=>{e.done=!1}))}findUnFinishedCells(){const e=[];return this.cellValues.forEach((t=>{t.done||e.push(t)})),e}findEmptyAdjCells(e){const t=e.row-1,o=e.col-1,i=[];for(let e=t;e{const[t,o]=e;return this.findDirections(t,o).length>0}));return t===e.value||t0}isSolved(e){return this.findAdjSum(e)===e.value}validate(e,t,o){const[i,n]=e,[s,a]=c.offsets[t],r=i+s,l=n+a;return!(!this.isOnBoard(r,l)||this.isSameInRow(o.a,i)||this.isSameInCol(o.a,n)||this.isSameInRow(o.b,r)||this.isSameInCol(o.b,l)||this.isAdjDomino([i,n],t))}validateSolution(){let e=!0;if(e=this.cellValues.every((e=>this.checkValidity(e))),!e)return!1;console.log("cells are valid");for(let e=0;e{const s=Date.now();if(console.log("Time passed: "+(s-o)),s-o>6e4)throw t+=1,console.error(`Timeout #${t+1}`),new Error("Timeout");const a=i.findAvailablePosition();let h,u;if(!a)return!1;for([h,u]=a;h;){console.log(`Current position: ${h}, Current Directions: ${u}`);for(let t=0;t0){u=i.markFinishedCells();const n=i.cellValues.find((e=>!e.done));if(0===i.availableDominos.length&&!n)return console.log("finished"),e.push(i),console.log(i),!0;if(n&&!i.checkValidity(n)){u&&u.length>0&&c.unMarkFinishedCells(u),i.returnInitialDomino(o,t),i.unPlaceDomino(s),console.log("continue");continue}}else if(0===i.availableDominos.length)return e.push(i),console.log("finished"),console.log(i),!0;if(console.log("recursive call"),n(l(i)))return!0;u&&u.length>0&&c.unMarkFinishedCells(u),i.returnInitialDomino(o,t),i.unPlaceDomino(s)}r.rotateDomino(s);for(const a of u)if(i.validate(h,a,s)){r.setupDomino(s,h,a),i.placeDomino(s),i.removeDomino(s);const d=i.findUnFinishedCells();let u;if(d&&d.length>0){u=i.markFinishedCells();const n=i.cellValues.find((e=>!e.done));if(0===i.availableDominos.length&&!n)return console.log("finished"),e.push(i),console.log(i),!0;if(n&&!i.checkValidity(n)){u&&u.length>0&&c.unMarkFinishedCells(u),i.returnInitialDomino(o,t),i.unPlaceDomino(s),console.log("continue");continue}}else if(0===i.availableDominos.length)return e.push(i),console.log("finished"),console.log(i),!0;if(console.log("recursive call"),n(l(i)))return!0;u&&u.length>0&&c.unMarkFinishedCells(u),i.returnInitialDomino(o,t),i.unPlaceDomino(s)}}const[t,o]=h;i.board[t][o]=!1;const s=i.findAvailablePosition();s?[h,u]=s:h=null}return!1};for(;0===e.length;)try{if(console.warn(this.availableDominos),!n(l(this)))return[]}catch(e){const n=l(i);if(this.board=n.board,this.cellValues=n.cellValues,this.availableDominos=n.availableDominos,this.shuffleDominoes(),o=Date.now(),3===t)return[]}return e}}const u=[new c(9,[[0,new a(14,0,1),0,0,new a(14,0,4),0,new a(11,0,6),0,0],[0,0,new a(10,1,2),new a(10,1,3),0,0,new a(14,1,6),new a(8,1,7),new a(8,1,8)],[new a(6,2,0),new a(13,2,1),0,new a(12,2,3),0,new a(12,2,5),0,0,0],[0,new a(14,3,1),0,0,0,0,new a(5,3,6),new a(10,3,7),new a(10,3,8)],[0,0,new a(6,4,2),0,new a(17,4,4),new a(17,4,5),0,0,0],[new a(12,5,0),0,new a(4,5,2),new a(6,5,3),0,0,0,new a(10,5,7),new a(10,5,8)],[0,0,new a(6,6,2),0,new a(13,6,4),new a(15,6,5),0,0,0],[0,new a(11,7,1),0,0,0,0,0,0,0],[0,0,new a(11,8,2),0,new a(8,8,4),new a(6,8,5),0,new a(9,8,7),new a(3,8,8)]]),new c(9,[[0,0,new a(11,0,2),0,0,0,new a(9,0,6),new a(10,0,7),new a(10,0,8)],[new a(9,1,0),0,new a(13,1,2),0,0,0,0,0,0],[new a(8,2,0),0,new a(12,2,2),new a(7,2,3),new a(8,2,4),new a(9,2,5),0,new a(17,2,7),0],[new a(8,3,0),0,new a(9,3,2),0,0,new a(12,3,5),0,new a(14,3,7),0],[new a(17,4,0),0,new a(16,4,2),new a(9,4,3),0,new a(13,4,5),0,0,0],[0,0,0,0,0,new a(5,5,5),new a(5,5,6),new a(14,5,7),new a(10,5,8)],[0,new a(20,6,1),0,new a(11,6,3),0,new a(7,6,5),new a(7,6,6),0,0],[0,0,0,0,new a(11,7,4),0,0,0,new a(14,7,8)],[0,new a(10,8,1),new a(6,8,2),new a(6,8,3),new a(11,8,4),0,new a(11,8,6),0,0]]),new c(9,[[0,0,0,new a(12,0,3),0,0,0,0,new a(2,0,8)],[0,0,0,new a(12,1,3),0,0,new a(8,1,6),new a(11,1,7),new a(5,1,8)],[new a(14,2,0),new a(16,2,1),new a(6,2,2),new a(7,2,3),new a(7,2,4),new a(10,2,5),new a(6,2,6),new a(13,2,7),0],[0,0,0,0,new a(5,3,4),0,0,0,0],[0,0,new a(6,4,2),0,new a(11,4,4),new a(12,4,5),new a(13,4,6),0,0],[0,new a(6,5,1),new a(6,5,2),0,new a(16,5,4),0,new a(12,5,6),0,0],[0,new a(6,6,1),0,0,new a(14,6,4),0,new a(16,6,6),new a(10,6,7),new a(10,6,8)],[new a(7,7,0),new a(12,7,1),0,0,new a(15,7,4),0,0,0,new a(7,7,8)],[new a(5,8,0),0,0,0,0,0,0,0,new a(7,8,8)]]),new c(9,[[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0]]),new c(9,[[0,0,0,0,0,0,0,0,0],[0,new a(20,1,1),0,0,0,0,0,0,0],[0,0,0,0,0,0,0,new a(8,2,7),0],[0,0,0,0,0,0,0,0,0],[0,0,0,new a(8,4,3),0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,new a(9,7,1),0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0]])];class m{constructor(){this.isStartedPlacingDomino=!1,this.activeInputs=[]}static handleNumberInput(e){const t=e.value.trim();t.length>0&&+t>0&&+t<23?e.classList.add("number"):(e.value="",e.classList="")}handleDominoInput(e,t,o,i,n,s,a){if(e.classList.contains("domino"))return;const l=e.value.trim();if(l.length>0&&+l>0&&+l<7)if(e.classList.add("domino"),this.isStartedPlacingDomino){if(this.isStartedPlacingDomino){const[l,d]=this.activeInputs[this.activeInputs.length-1],h=+e.value,u=+o[l][d].children[0].value,w=s-l,f=a-d;let g=-1;c.offsets.some(((e,t)=>{const[o,i]=e;return w===o&&f===i&&(g=t,!0)}));const B=new r(u,h);r.setupDomino(B,[+l,+d],g);let b=!1,v=-1;if(t.availableDominos.forEach(((e,t)=>{r.areTheSame(B,e)&&(b=!0,v=t)})),this.isStartedPlacingDomino=!1,this.activeInputs=[],m.enableInputs(t,o),!b)return o[l][d].children[0].value="",o[l][d].children[0].classList="",o[l][d].children[0].disabled=!1,e.value="",void(e.classList="");t.availableDominos.splice(v,1),t.placeDomino(B),e.disabled=!0,0===t.availableDominos.length&&(i.show("All dominos are placed!"),n.disabled=!0,this.disableInputs(t,o),n.classList.remove("btn--disabled"),n.disabled=!1)}}else{this.isStartedPlacingDomino=!0;const i=t.findDirections(s,a);if(0===i.length)return this.isStartedPlacingDomino=!1,e.classList.remove("domino"),void(e.value="");i.forEach((e=>{const[t,o]=c.offsets[e],i=[s+t,a+o];this.activeInputs.push(i)})),this.activeInputs.push([s,a]),this.disableInputs(t,o)}else e.value="",e.classList=""}disableInputs(e,t){for(let o=0;o{const[t,n]=e;return t===o&&n===i}))||(t[o][i].children[0].disabled=!0,t[o][i].children[0].classList.add("muted"))),t[o][i].children[0]&&t[o][i].children[0].classList.contains("domino")&&(t[o][i].children[0].disabled=!0)}static enableInputs(e,t){for(let o=0;o',this.domGrid[t][o].querySelector("input").addEventListener("blur",(e=>m.handleNumberInput(e.target)))}solveYourself(e,t,o){for(let i=0;ithis.inputHandler.handleDominoInput(s.target,e,this.domGrid,t,o,i,n))))}getNewBoard(e){const t=[[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0]];for(let o=0;o{e.disabled=!0}))}static enableAllButtons(){[...document.querySelectorAll("button")].forEach((e=>{e.disabled=!1}))}}class B{constructor(e){this.element=e}show(){this.element.classList.remove("hide")}hide(){this.element.classList.add("hide")}}class b extends B{}class v extends B{constructor(e,t){super(e),this.overlay=t}show(){this.overlay.classList.remove("hide"),super.show()}hide(){this.overlay.classList.add("hide"),super.hide()}}class p{constructor(){this.themeSwitcher=document.getElementById("themeSwitcher")}init(){this.themeSwitcher.addEventListener("click",p.toggleTheme),this.setInitialTheme()}static setTheme(e){localStorage.setItem("theme",e),document.documentElement.className=e}static toggleTheme(){"theme-dark"===localStorage.getItem("theme")?p.setTheme("theme-light"):p.setTheme("theme-dark")}setInitialTheme(){"theme-dark"===localStorage.getItem("theme")?(p.setTheme("theme-dark"),this.themeSwitcher.checked=!1):(p.setTheme("theme-light"),this.themeSwitcher.checked=!0)}}const S=e=>{if(0===e.length)return[];const t=[];return e.forEach((e=>{const o=e.board;for(let t=0;t{setTimeout((()=>{y.start()}),500)},E=()=>{setTimeout((()=>{y.stop()}),3e3)};let D,M;!function(){y.start=m,y.stop=w,y.toggle=function(){o?w():m()},y.pause=h,y.resume=c,y.togglePause=function(){n?c():h()},y.isPaused=function(){return n},y.remove=function(){stop(),n=!1,a=[]},y.isRunning=function(){return o};const e=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame,t=["rgba(30,144,255,","rgba(107,142,35,","rgba(255,215,0,","rgba(255,192,203,","rgba(106,90,205,","rgba(173,216,230,","rgba(238,130,238,","rgba(152,251,152,","rgba(70,130,180,","rgba(244,164,96,","rgba(210,105,30,","rgba(220,20,60,"];let o=!1,i=null,n=!1,s=Date.now(),a=[],r=0,l=null;function d(e,o,i){return e.color=`${t[Math.random()*t.length|0]}${y.alpha})`,e.color2=`${t[Math.random()*t.length|0]}${y.alpha})`,e.x=Math.random()*o,e.y=Math.random()*i-i,e.diameter=10*Math.random()+5,e.tilt=10*Math.random()-10,e.tiltAngleIncrement=.07*Math.random()+.05,e.tiltAngle=Math.random()*Math.PI,e}function h(){n=!0}function c(){n=!1,u()}function u(){if(!n)if(0===a.length)l.clearRect(0,0,window.innerWidth,window.innerHeight),i=null;else{const t=Date.now(),n=t-s;(!e||n>y.frameInterval)&&(l.clearRect(0,0,window.innerWidth,window.innerHeight),function(){const e=window.innerWidth,t=window.innerHeight;let i;r+=.01;for(let n=0;ne+20||i.x<-20||i.y>t)&&(o&&a.length<=y.maxCount?d(i,e,t):(a.splice(n,1),n--))}(),function(e){let t,o,i,n;for(let s=0;s{h.width=window.innerWidth,h.height=window.innerHeight}),!0),l=h.getContext("2d")):null===l&&(l=h.getContext("2d"));let c=y.maxCount;if(t)if(i)if(t==i)c=a.length+i;else{if(t>i){const e=t;t=i,i=e}c=a.length+(Math.random()*(i-t)+t|0)}else c=a.length+t;else i&&(c=a.length+i);for(;a.length{if(0===e.length)return[];const t=[];return e.forEach((e=>{const o=e;for(let t=0;te.remove())),e.forEach(((e,t)=>this.addOption(t)))}changeValue(e){this.element.value=e}}(document.getElementById("standard-select")),z=new v(document.querySelector(".modal"),document.querySelector(".overlay")),P=new v(document.querySelector(".modal__info"),document.querySelector(".overlay")),F=new g(C,x,k,L,T,z,P);F.displayBoard(M);const R=new class{constructor(e,t,o,i){this.ui=e,this.currentBoard=t,this.generatedBoard=null,this.boards=o,this.localStorageManager=i,this.clearBoardBtn=document.getElementById("clear-board"),this.generateBtn=document.getElementById("generate"),this.addBoardExitBtn=document.getElementById("add-board-exit"),this.removeBoardBtn=document.getElementById("remove-current-board"),this.addBoardBtn=document.getElementById("add-board"),this.enterNewBoardBtn=document.getElementById("enter-new-board")}init(){this.handleClearBoard=this.handleClearBoard.bind(this),this.handleGenerateBoard=this.handleGenerateBoard.bind(this),this.handleAddBoardExit=this.handleAddBoardExit.bind(this),this.handleRemoveBoard=this.handleRemoveBoard.bind(this),this.handleAddBoard=this.handleAddBoard.bind(this),this.handleEnterNewBoard=this.handleEnterNewBoard.bind(this),this.clearBoardBtn.addEventListener("click",this.handleClearBoard),this.generateBtn.addEventListener("click",this.handleGenerateBoard),this.addBoardExitBtn.addEventListener("click",this.handleAddBoardExit),this.removeBoardBtn.addEventListener("click",this.handleRemoveBoard),this.addBoardBtn.addEventListener("click",this.handleAddBoard),this.enterNewBoardBtn.addEventListener("click",this.handleEnterNewBoard),this.boards.forEach(((e,t)=>this.ui.addSelectOption(t)))}handleClearBoard(){const e=l(this.currentBoard);this.ui.clearBoard(e),this.ui.displayBoard(e),this.clearBoardBtn.classList.add("hide")}handleGenerateBoard(){this.ui.showMessage("Generating a board..."),setTimeout((()=>{this.generatedBoard=new c(9),this.ui.hideButtons("main"),this.ui.showButtons("addBoard");const e=l(this.generatedBoard);this.setCurrentBoard(e),this.ui.clearBoard(e),this.ui.displayBoard(e),this.ui.hideMessage()}),100)}handleAddBoardExit(){if(this.ui.hideButtons("addBoard"),this.ui.showButtons("main"),this.getGeneratedBoard()){this.setGeneratedBoard(null);const e=l(this.boards[0]);return this.ui.clearBoard(e),void this.ui.displayBoard(e)}const e=l(this.currentBoard);this.ui.clearBoard(e),this.ui.displayBoard(e)}handleRemoveBoard(){const e=this.boards.findIndex((e=>e===this.currentBoard));this.boards.splice(e,1),this.ui.removeBoardOption(this.boards),this.localStorageManager.saveBoards(this.boards),this.boards.splice(0,this.boards.length,...this.localStorageManager.getBoards()),this.currentBoard=this.boards[this.boards.length-1],this.ui.switchSelectedBoard(this.boards.length-1);const t=l(this.currentBoard);this.setCurrentBoard(t),this.ui.clearBoard(t),this.ui.displayBoard(t)}handleAddBoard(){let e;console.log(this.boards),this.getGeneratedBoard()?(console.log("generated board"),e=this.getGeneratedBoard(),this.setGeneratedBoard(null)):e=this.ui.getNewBoard(this.currentBoard),this.boards.push(e),this.localStorageManager.saveBoards(this.boards),this.boards.splice(0,this.boards.length,...this.localStorageManager.getBoards()),this.ui.hideButtons("addBoard"),this.ui.showButtons("main"),this.ui.addSelectOption(this.boards.length-1),console.log(this.boards),this.currentBoard=this.boards[this.boards.length-1];const t=l(this.currentBoard);this.setCurrentBoard(t),this.ui.clearBoard(t),this.ui.displayBoard(t),this.ui.switchSelectedBoard(""+(this.boards.length-1))}handleEnterNewBoard(){this.ui.hideButtons("main"),this.ui.addNewBoard(this.currentBoard),this.ui.showButtons("addBoard")}getCurrentBoard(){return this.currentBoard}setCurrentBoard(e){this.currentBoard=e}getGeneratedBoard(){return this.generatedBoard}setGeneratedBoard(e){this.generatedBoard=e}}(F,M,D,A);R.init();const G=new class{constructor(e){this.ui=e,this.closeModalBtn=document.querySelector(".modal__header svg"),this.closeModalInfoBtn=document.querySelector(".modal__info svg")}init(){this.handleModalClose=this.handleModalClose.bind(this),this.handleModalInfoClose=this.handleModalInfoClose.bind(this),this.closeModalBtn.addEventListener("click",this.handleModalClose),this.closeModalInfoBtn.addEventListener("click",this.handleModalInfoClose)}handleModalClose(){this.ui.hideModal("error")}handleModalInfoClose(){this.ui.hideModal("info")}}(F);G.init();const V=new class{constructor(e,t,o,i){this.ui=e,this.solveYourselfBoard=t,this.currentBoard=o,this.boardEventHandler=i,this.finishSolvingBtn=document.getElementById("finish-solving"),this.solveBoardExitBtn=document.getElementById("solve-board-exit"),this.solveAIBtn=document.getElementById("solve-ai"),this.solveYourselfBtn=document.getElementById("solve-yourself")}init(){this.handleFinishSolving=this.handleFinishSolving.bind(this),this.handleSolveBoardExit=this.handleSolveBoardExit.bind(this),this.handleSolveAI=this.handleSolveAI.bind(this),this.handleSolveYourself=this.handleSolveYourself.bind(this),this.finishSolvingBtn.addEventListener("click",this.handleFinishSolving),this.solveBoardExitBtn.addEventListener("click",this.handleSolveBoardExit),this.solveAIBtn.addEventListener("click",this.handleSolveAI),this.solveYourselfBtn.addEventListener("click",this.handleSolveYourself)}handleFinishSolving(){this.ui.hideButtons("solveBoard"),this.ui.showButtons("main"),this.ui.hideMessage(),this.solveYourselfBoard.validateSolution()?(this.ui.showModal("info"),g.disableAllButtons(),I(),E(),setTimeout((()=>g.enableAllButtons()),7e3),setTimeout((()=>this.ui.showButtons("clearBoard")),1e3),window.dominoAPI&&window.dominoAPI.saveSolution(...S([l(this.solveYourselfBoard)]))):(this.ui.showMessage("Your solution is incorrect"),this.ui.showButtons("clearBoard"),setTimeout((()=>{this.ui.hideMessage()}),3500));const e=l(this.solveYourselfBoard);this.ui.clearBoard(e),this.ui.displayBoard(e)}handleSolveBoardExit(){this.ui.hideButtons("solveBoard"),this.ui.showButtons("main"),console.log(this.currentBoard);const e=l(this.currentBoard);console.log(this.ui.dominoGrid),this.ui.clearBoard(e),this.ui.displayBoard(e)}handleSolveAI(){this.ui.showMessage("AI is currently working on the problem..."),setTimeout((()=>{console.log("current",this.boardEventHandler.getCurrentBoard());const e=l(this.boardEventHandler.getCurrentBoard()).findSolution();console.log(e);try{const t=l(e[0]);this.ui.clearBoard(t),this.ui.displayBoard(t),0!==e.length&&(g.disableAllButtons(),I(),E(),setTimeout((()=>g.enableAllButtons()),7e3),setTimeout((()=>this.ui.showButtons("clearBoard")),1e3),window.dominoAPI&&window.dominoAPI.saveSolution(...S(e)))}catch(e){console.log(e),this.ui.showModal("error")}this.ui.hideMessage()}),300)}handleSolveYourself(){this.ui.hideButtons("main"),this.solveYourselfBoard=l(this.currentBoard),this.ui.solveYourself(this.solveYourselfBoard),this.ui.showButtons("solveBoard")}getSolveYourselfBoard(){return this.solveYourselfBoard}setSolveYourselfBoard(e){this.solveYourselfBoard=e}getCurrentBoard(){return this.currentBoard}setCurrentBoard(e){this.currentBoard=e}}(F,void 0,M,R);V.init(),F.boardSelect.element.addEventListener("change",(e=>{M=D[e.target.value];const t=l(M);R.setCurrentBoard(t),V.setCurrentBoard(t),F.clearBoard(t),F.displayBoard(t),F.hideButtons("clearBoard")}))})()})(); \ No newline at end of file diff --git a/dist/index.html b/dist/index.html index 518665e..5dbea8c 100644 --- a/dist/index.html +++ b/dist/index.html @@ -1 +1 @@ -Domino Game

Domino Game

Solving...

\ No newline at end of file +Domino Game

Domino Game

Solving...

\ No newline at end of file diff --git a/jest.config.js b/jest.config.js index 942998a..677e148 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,4 +4,5 @@ module.exports = { '/__mocks__/fileMock.js', '\\.(css|less)$': '/__mocks__/styleMock.js', }, + testPathIgnorePatterns: ['release-builds/'], }; diff --git a/package.json b/package.json index afd79a7..b5dbcb4 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "test": "jest", "test:watch": "jest --watchAll", "electron": "npm run build && nodemon --exec electron ./src/electron/main.js", - "package": "electron-packager . --overwrite --platform=darwin --arch=x64 --icon=src/assets/domino-svgrepo-com.icns --prune=true --out=release-builds" + "package-mac": "electron-packager . --overwrite --platform=darwin --arch=x64 --icon=src/assets/domino-svgrepo-com.icns --prune=true --out=release-builds-mac", + "package-win": "electron-packager . domino_game --overwrite --asar=true --platform=win32 --arch=ia32 --icon=src/assets/domino-icon.ico --prune=true --out=release-builds-win --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName=\"Domino Game\"" }, "keywords": [], "author": "", diff --git a/src/__tests__/Domino/Domino.test.js b/src/__tests__/Domino/Domino.test.js index 999dd2f..d14aa39 100644 --- a/src/__tests__/Domino/Domino.test.js +++ b/src/__tests__/Domino/Domino.test.js @@ -1,4 +1,4 @@ -import Domino from '../../Domino'; +import Domino from '../../../src/gameLogic/Domino'; describe('Domino', () => { test('should have a and b properties', () => { diff --git a/src/__tests__/DominoGrid/boardPositioning.test.js b/src/__tests__/DominoGrid/boardPositioning.test.js index 2e613ec..32e4993 100644 --- a/src/__tests__/DominoGrid/boardPositioning.test.js +++ b/src/__tests__/DominoGrid/boardPositioning.test.js @@ -1,5 +1,5 @@ -import DominoGrid from '../../DominoGrid'; -import Domino from '../../Domino'; +import DominoGrid from '../../../src/gameLogic/DominoGrid'; +import Domino from '../../../src/gameLogic/Domino'; describe('DominoGrid', () => { describe('isOnBoard', () => { diff --git a/src/__tests__/DominoGrid/checkValidity.test.js b/src/__tests__/DominoGrid/checkValidity.test.js index 04a2e67..bcc35c9 100644 --- a/src/__tests__/DominoGrid/checkValidity.test.js +++ b/src/__tests__/DominoGrid/checkValidity.test.js @@ -1,6 +1,6 @@ -import CellValue from '../../CellValue'; -import Domino from '../../Domino'; -import DominoGrid from '../../DominoGrid'; +import CellValue from '../../../src/gameLogic/CellValue'; +import Domino from '../../../src/gameLogic/Domino'; +import DominoGrid from '../../../src/gameLogic/DominoGrid'; describe('CellValue', () => { describe('checkValidity', () => { diff --git a/src/__tests__/DominoGrid/findAdjSum.test.js b/src/__tests__/DominoGrid/findAdjSum.test.js index 2aea8ba..5cb22ef 100644 --- a/src/__tests__/DominoGrid/findAdjSum.test.js +++ b/src/__tests__/DominoGrid/findAdjSum.test.js @@ -1,6 +1,6 @@ -import CellValue from '../../CellValue'; -import DominoGrid from '../../DominoGrid'; -import Domino from '../../Domino'; +import CellValue from '../../../src/gameLogic/CellValue'; +import DominoGrid from '../../../src/gameLogic/DominoGrid'; +import Domino from '../../../src/gameLogic/Domino'; describe('CellValue', () => { describe('findAdjSum', () => { diff --git a/src/__tests__/DominoGrid/findAvailablePosition.test.js b/src/__tests__/DominoGrid/findAvailablePosition.test.js index 7b12dc1..28a6eb8 100644 --- a/src/__tests__/DominoGrid/findAvailablePosition.test.js +++ b/src/__tests__/DominoGrid/findAvailablePosition.test.js @@ -1,6 +1,6 @@ -import DominoGrid from '../../DominoGrid'; -import Domino from '../../Domino'; -import CellValue from '../../CellValue'; +import DominoGrid from '../../../src/gameLogic/DominoGrid'; +import Domino from '../../../src/gameLogic/Domino'; +import CellValue from '../../../src/gameLogic/CellValue'; describe('DominoGrid', () => { describe('findAvailablePosition', () => { diff --git a/src/__tests__/DominoGrid/findDirections.test.js b/src/__tests__/DominoGrid/findDirections.test.js index 2cf7910..22650b3 100644 --- a/src/__tests__/DominoGrid/findDirections.test.js +++ b/src/__tests__/DominoGrid/findDirections.test.js @@ -1,5 +1,5 @@ -import CellValue from '../../CellValue'; -import DominoGrid from '../../DominoGrid'; +import CellValue from '../../../src/gameLogic/CellValue'; +import DominoGrid from '../../../src/gameLogic/DominoGrid'; describe('DominoGrid', () => { describe('findDirections', () => { diff --git a/src/__tests__/DominoGrid/findEmptyCells.test.js b/src/__tests__/DominoGrid/findEmptyCells.test.js index d0490b0..836a52f 100644 --- a/src/__tests__/DominoGrid/findEmptyCells.test.js +++ b/src/__tests__/DominoGrid/findEmptyCells.test.js @@ -1,5 +1,5 @@ -import CellValue from '../../CellValue'; -import DominoGrid from '../../DominoGrid'; +import CellValue from '../../../src/gameLogic/CellValue'; +import DominoGrid from '../../../src/gameLogic/DominoGrid'; describe('CellValue', () => { describe('findEmptyAdjCells', () => { diff --git a/src/__tests__/DominoGrid/generateDominoes.test.js b/src/__tests__/DominoGrid/generateDominoes.test.js index 9e1888a..bf36c02 100644 --- a/src/__tests__/DominoGrid/generateDominoes.test.js +++ b/src/__tests__/DominoGrid/generateDominoes.test.js @@ -1,4 +1,4 @@ -import DominoGrid from '../../DominoGrid'; +import DominoGrid from '../../../src/gameLogic/DominoGrid'; describe('DominoGrid', () => { describe('generateDominoes', () => { diff --git a/src/__tests__/DominoGrid/isSolved.test.js b/src/__tests__/DominoGrid/isSolved.test.js index e212d59..7e3b1eb 100644 --- a/src/__tests__/DominoGrid/isSolved.test.js +++ b/src/__tests__/DominoGrid/isSolved.test.js @@ -1,6 +1,6 @@ -import CellValue from '../../CellValue'; -import Domino from '../../Domino'; -import DominoGrid from '../../DominoGrid'; +import CellValue from '../../../src/gameLogic/CellValue'; +import Domino from '../../../src/gameLogic/Domino'; +import DominoGrid from '../../../src/gameLogic/DominoGrid'; describe('CellValue', () => { describe('isSolved', () => { diff --git a/src/__tests__/DominoGrid/placeDomino.test.js b/src/__tests__/DominoGrid/placeDomino.test.js index 64f8d96..4fa173b 100644 --- a/src/__tests__/DominoGrid/placeDomino.test.js +++ b/src/__tests__/DominoGrid/placeDomino.test.js @@ -1,5 +1,5 @@ -import DominoGrid from '../../DominoGrid'; -import Domino from '../../Domino'; +import DominoGrid from '../../../src/gameLogic/DominoGrid'; +import Domino from '../../../src/gameLogic/Domino'; describe('DominoGrid', () => { describe('placeDomino', () => { diff --git a/src/__tests__/DominoGrid/shuffleDominoes.test.js b/src/__tests__/DominoGrid/shuffleDominoes.test.js index 130e72a..b94ec09 100644 --- a/src/__tests__/DominoGrid/shuffleDominoes.test.js +++ b/src/__tests__/DominoGrid/shuffleDominoes.test.js @@ -1,4 +1,4 @@ -import DominoGrid from '../../DominoGrid'; +import DominoGrid from '../../../src/gameLogic/DominoGrid'; describe('DominoGrid', () => { describe('shuffleDominoes', () => { diff --git a/src/__tests__/DominoGrid/unPlaceInitialDomino.test.js b/src/__tests__/DominoGrid/unPlaceInitialDomino.test.js index 5efd83c..93b05c8 100644 --- a/src/__tests__/DominoGrid/unPlaceInitialDomino.test.js +++ b/src/__tests__/DominoGrid/unPlaceInitialDomino.test.js @@ -1,5 +1,5 @@ -import DominoGrid from '../../DominoGrid'; -import Domino from '../../Domino'; +import DominoGrid from '../../../src/gameLogic/DominoGrid'; +import Domino from '../../../src/gameLogic/Domino'; describe('DominoGrid', () => { describe('unPlaceInitialDomino', () => { diff --git a/src/__tests__/DominoGrid/validatePos.test.js b/src/__tests__/DominoGrid/validatePos.test.js index f43957b..6ac2eae 100644 --- a/src/__tests__/DominoGrid/validatePos.test.js +++ b/src/__tests__/DominoGrid/validatePos.test.js @@ -1,6 +1,6 @@ -import CellValue from '../../CellValue'; -import Domino from '../../Domino'; -import DominoGrid from '../../DominoGrid'; +import CellValue from '../../../src/gameLogic/CellValue'; +import Domino from '../../../src/gameLogic/Domino'; +import DominoGrid from '../../../src/gameLogic/DominoGrid'; describe('DominoGrid', () => { describe('isSameInRow', () => { diff --git a/src/assets/domino-icon.ico b/src/assets/domino-icon.ico new file mode 100644 index 0000000000000000000000000000000000000000..a6f2e336bf2fcfafba2eec5b7828f0167044a56f GIT binary patch literal 2086 zcma)-$!ior6o)H|F;P*88n-Ax+}DT*3Qb(_qF_*o;MoPloV4PV#mH?Ln;y;t2GLKDBPuE4P;ENu?~Gi(LN zouFUcnqM7?4ow6+hB8d#OfsfK|9ku|U@mGQ=q?<9dC&pOwmPPE8@@g85w5^Sa88Y6 z-aD`x_T}~p#;8t=QSiQ-VH_^O1Go+gp`OybUi%bQC4tMaty3Rt0oSIS`zu)FNgc(! zz5Hh#)$=Qw z7Sft6;CukqgWK*lWMEHRUn8Y?t!qD+E6Tlb61u@UnC}LhgV_}GT89%b1w9aDzAtbF zHot;XT~H^6rofg)MUw{R2A=h*9%=pVxW8;(Gc4ifMSN^k+v ze9?}1t?N5j0!1nj@B{2gBgHzzeb(A2F!!%yd0}X)%t%Z%IlsTgZ=p>&dv9)d+r&e?@3PoX)bw(i8hDx9tWQ{-|ODPPg*?{ z<@FlZYur`%3eMgAWB=QeQCr%;THS}DeMU%C_OA>RIg^aF_@Cd+=MZ~ { @@ -76,8 +78,9 @@ export default class BoardEventHandler { } handleRemoveBoard() { - const index = this.boards.findIndex((val) => val === this.currentBoard); - this.boards.splice(index, 1); + this.ui.hideButtons('clearBoard'); + if (this.boards.length <= 1) return; + this.boards.splice(this.currentBoardIndex, 1); this.ui.removeBoardOption(this.boards); this.localStorageManager.saveBoards(this.boards); this.boards.splice( @@ -85,9 +88,9 @@ export default class BoardEventHandler { this.boards.length, ...this.localStorageManager.getBoards() ); - // this.boards = this.localStorageManager.getBoards(); - this.currentBoard = this.boards[this.boards.length - 1]; - this.ui.switchSelectedBoard(this.boards.length - 1); + this.currentBoardIndex = this.boards.length - 1; + this.currentBoard = this.boards[this.currentBoardIndex]; + this.ui.switchSelectedBoard(this.currentBoardIndex); const dominoGrid = copyDominoGrid(this.currentBoard); this.setCurrentBoard(dominoGrid); this.ui.clearBoard(dominoGrid); @@ -95,11 +98,9 @@ export default class BoardEventHandler { } handleAddBoard() { - console.log(this.boards); let newBoard; if (this.getGeneratedBoard()) { - console.log('generated board'); newBoard = this.getGeneratedBoard(); this.setGeneratedBoard(null); } else { @@ -118,8 +119,8 @@ export default class BoardEventHandler { this.ui.addSelectOption(this.boards.length - 1); - console.log(this.boards); - this.currentBoard = this.boards[this.boards.length - 1]; + this.currentBoardIndex = this.boards.length - 1; + this.currentBoard = this.boards[this.currentBoardIndex]; const dominoGrid = copyDominoGrid(this.currentBoard); this.setCurrentBoard(dominoGrid); this.ui.clearBoard(dominoGrid); @@ -128,6 +129,7 @@ export default class BoardEventHandler { } handleEnterNewBoard() { + this.ui.hideButtons('clearBoard'); this.ui.hideButtons('main'); this.ui.addNewBoard(this.currentBoard); this.ui.showButtons('addBoard'); @@ -148,4 +150,8 @@ export default class BoardEventHandler { setGeneratedBoard(board) { this.generatedBoard = board; } + + setCurrentBoardIndex(index) { + this.currentBoardIndex = index; + } } diff --git a/src/eventHandlers/SolveBoardEventHandler.js b/src/eventHandlers/SolveBoardEventHandler.js index 914f05a..c47a4ea 100644 --- a/src/eventHandlers/SolveBoardEventHandler.js +++ b/src/eventHandlers/SolveBoardEventHandler.js @@ -59,9 +59,7 @@ export default class SolveBoardEventHandler { handleSolveBoardExit() { this.ui.hideButtons('solveBoard'); this.ui.showButtons('main'); - console.log(this.currentBoard); const dominoGrid = copyDominoGrid(this.currentBoard); - console.log(this.ui.dominoGrid); this.ui.clearBoard(dominoGrid); this.ui.displayBoard(dominoGrid); } @@ -69,11 +67,9 @@ export default class SolveBoardEventHandler { handleSolveAI() { this.ui.showMessage('AI is currently working on the problem...'); setTimeout(() => { - console.log('current', this.boardEventHandler.getCurrentBoard()); const solutions = copyDominoGrid( this.boardEventHandler.getCurrentBoard() ).findSolution(); - console.log(solutions); try { const dominoGrid = copyDominoGrid(solutions[0]); @@ -91,7 +87,6 @@ export default class SolveBoardEventHandler { } } } catch (err) { - console.log(err); this.ui.showModal('error'); } this.ui.hideMessage(); @@ -100,6 +95,7 @@ export default class SolveBoardEventHandler { handleSolveYourself() { this.ui.hideButtons('main'); + this.ui.hideButtons('clearBoard'); this.solveYourselfBoard = copyDominoGrid(this.currentBoard); this.ui.solveYourself(this.solveYourselfBoard); this.ui.showButtons('solveBoard'); diff --git a/src/gameLogic/DominoGrid.js b/src/gameLogic/DominoGrid.js index 10ebaf6..60a22d2 100644 --- a/src/gameLogic/DominoGrid.js +++ b/src/gameLogic/DominoGrid.js @@ -142,7 +142,21 @@ export default class DominoGrid { if (!this.isOnBoard(row, col)) { return false; } - return this.board[row][col] === 0; + if (this.board[row][col] === 0) { + for (let r = row - 1; r <= row + 1; r += 1) { + for (let c = col - 1; c <= col + 1; c += 1) { + if (this.isOnBoard(r, c)) { + if (this.board[r][c] instanceof CellValue) { + if (this.board[r][c].done) { + return false; + } + } + } + } + } + return true; + } + return false; } findDirections(row, col) { @@ -410,6 +424,7 @@ export default class DominoGrid { console.log( `Current position: ${currPos}, Current Directions: ${directions}` ); + console.log(copyDominoGrid(dominoGrid)); for (let i = 0; i < dominoGrid.availableDominos.length; i += 1) { const currInitialDomino = copyDomino(dominoGrid.availableDominos[i]); const currDomino = dominoGrid.availableDominos[i]; diff --git a/src/helperClasses/BoardManager.js b/src/helperClasses/BoardManager.js index dcd09d0..ef2cd96 100644 --- a/src/helperClasses/BoardManager.js +++ b/src/helperClasses/BoardManager.js @@ -60,9 +60,6 @@ export default class BoardManager { for (let i = 0; i < dominoGrid.size; i += 1) { for (let j = 0; j < dominoGrid.size; j += 1) { - console.log(this.domGrid); - console.log(i, j); - console.log(this.domGrid[i][j]); const { value } = this.domGrid[i][j].querySelector('input'); if (value.length !== 0) { board[i][j] = new CellValue(+value, i, j); diff --git a/src/helpers/copyFunc.js b/src/helpers/copyFunc.js index 747ebf0..ead0c28 100644 --- a/src/helpers/copyFunc.js +++ b/src/helpers/copyFunc.js @@ -8,12 +8,14 @@ export default function copyDominoGrid(dominoGrid) { .fill(0) .map(() => Array(dominoGrid.size).fill(0)); + const newCellValues = []; for (let r = 0; r < dominoGrid.size; r += 1) { for (let c = 0; c < dominoGrid.size; c += 1) { if (dominoGrid.board[r][c] instanceof Domino) { newBoard[r][c] = copyDomino(dominoGrid.board[r][c]); } else if (dominoGrid.board[r][c] instanceof CellValue) { newBoard[r][c] = copyCellValue(dominoGrid.board[r][c], newDominoGrid); + newCellValues.push(newBoard[r][c]); } else { newBoard[r][c] = dominoGrid.board[r][c]; } @@ -25,11 +27,6 @@ export default function copyDominoGrid(dominoGrid) { newAvailableDominos.push(copyDomino(domino)); }); - const newCellValues = []; - dominoGrid.cellValues.forEach((value) => { - newCellValues.push(copyCellValue(value, newDominoGrid)); - }); - newDominoGrid.board = newBoard; newDominoGrid.availableDominos = newAvailableDominos; newDominoGrid.cellValues = newCellValues; diff --git a/src/index.js b/src/index.js index 60ccd34..c1dce63 100644 --- a/src/index.js +++ b/src/index.js @@ -26,7 +26,8 @@ if (localStorageManager.existBoards()) { [currentBoard] = boards; } else { localStorageManager.saveBoards(initialBoards); - [currentBoard] = initialBoards; + boards = localStorageManager.getBoards(initialBoards); + [currentBoard] = boards; } const themeManager = new ThemeManager(); @@ -54,6 +55,9 @@ const ui = new UI( modalError, modalInfo ); +console.log(initialBoards); +console.log(boards); +console.log(currentBoard); ui.displayBoard(currentBoard); const boardEventHandler = new BoardEventHandler( @@ -75,6 +79,7 @@ solveBoardEventHandler.init(); ui.boardSelect.element.addEventListener('change', (e) => { currentBoard = boards[e.target.value]; + boardEventHandler.setCurrentBoardIndex(e.target.value); const dominoGrid = copyDominoGrid(currentBoard); boardEventHandler.setCurrentBoard(dominoGrid); solveBoardEventHandler.setCurrentBoard(dominoGrid);