diff --git a/index.1f6979d2.js b/index.1f6979d2.js new file mode 100644 index 000000000..ba3dad959 --- /dev/null +++ b/index.1f6979d2.js @@ -0,0 +1,2 @@ +const t=new class{constructor(t=this.getNewBoard()){this.state=t,this.initialState=this.copyState(t),this.prevState=this.copyState(this.state),this.status="idle",this.score=0,this.isWin=!1,console.log(this.state[0],this.state[1],this.state[2],this.state[3])}moveLeft(){let t=this.getStatus();if("idle"!==t&&"lose"!==t){this.setPrevState();for(let t=0;t<4;t++){let e=this.state[t],s=this.moveLine(e);this.state[t]=s}this.addCellIfMoved(),this.updateStatus()}}moveRight(){let t=this.getStatus();if("idle"!==t&&"lose"!==t){this.setPrevState();for(let t=0;t<4;t++){let e=this.state[t].reverse(),s=this.moveLine(e);this.state[t]=s.reverse()}this.addCellIfMoved(),this.updateStatus()}}moveUp(){let t=this.getStatus();if("idle"!==t&&"lose"!==t){this.setPrevState();for(let t=0;t<4;t++){let e=this.getRow(t),s=this.moveLine(e);this.changeRow(s,t)}this.addCellIfMoved(),this.updateStatus()}}moveDown(){let t=this.getStatus();if("idle"!==t&&"lose"!==t){this.setPrevState();for(let t=0;t<4;t++){let e=this.getRow(t),s=this.moveLine(e.reverse());this.changeRow(s.reverse(),t)}this.addCellIfMoved(),this.updateStatus()}}getScore(){return this.score}updateScore(t){this.score+=t}getLineSum(t){return t.reduce((t,e)=>t+e,0)}getState(){return this.state}getPrevState(){return this.prevState}setPrevState(){this.prevState=this.copyState(this.state)}copyState(t){return t.map(t=>[...t])}getStatus(){return this.status}setStatus(t){this.status=t}start(){this.addRandomCell(),this.addRandomCell(),this.setStatus("playing")}restart(){this.state=this.copyState(this.initialState),this.score=0,this.setStatus("idle")}getNewBoard(){return[void 0,void 0,void 0,void 0].map(()=>[,,,,].fill(0))}addRandomCell(){let t=this.getEmptyCells();if(0!==t.length){let e=Math.floor(Math.random()*t.length),s=t[e];this.state[s.rowIndex][s.colIndex]=.9>Math.random()?2:4}}getEmptyCells(){let t=[];for(let e=0;e<4;e++)for(let s=0;s<4;s++)0===this.state[e][s]&&t.push({rowIndex:e,colIndex:s});return t}addCellIfMoved(){this.isMoved(this.getPrevState())&&this.addRandomCell()}moveLine(t){let e=t.filter(t=>0!==t);for(let t=0;t{e.forEach((e,i)=>{let a=t[4*s+i];0!==e?(a.textContent=e,a.classList=`field-cell field-cell--${e}`):(a.textContent=null,a.classList="field-cell")})})}},e=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],s=document.querySelector(".button"),i=document.querySelector(".game-score"),a=document.querySelector(".message-start"),r=document.querySelector(".message-lose"),o=document.querySelector(".message-win"),l=document.querySelectorAll(".field-cell");function h(){switch(t.getStatus()){case"win":o.classList.remove("hidden");break;case"lose":r.classList.remove("hidden");break;case"playing":o.classList.contains("hidden")||o.classList.add("hidden"),r.classList.contains("hidden")||r.classList.add("hidden")}}s.addEventListener("click",function(){"Start"===s.textContent?(t.start(),s.textContent="Restart",s.classList.toggle("restart"),a.classList.toggle("hidden")):(t.restart(),t.start(),h()),t.drawBoard(l)}),document.addEventListener("keydown",s=>{e.includes(s.key)&&"lose"!==t.getStatus()&&(function(e){switch(e){case"ArrowLeft":t.moveLeft();break;case"ArrowRight":t.moveRight();break;case"ArrowUp":t.moveUp();break;case"ArrowDown":t.moveDown()}}(s.key),i.textContent=t.getScore(),t.drawBoard(l),h())}); +//# sourceMappingURL=index.1f6979d2.js.map diff --git a/index.1f6979d2.js.map b/index.1f6979d2.js.map new file mode 100644 index 000000000..5f88816b4 --- /dev/null +++ b/index.1f6979d2.js.map @@ -0,0 +1 @@ +{"mappings":"ACGA,MAAM,EAAO,ICMb,MAeE,YAAY,EAAe,IAAI,CAAC,WAAW,EAAE,CAAE,CAC7C,IAAI,CAAC,KAAK,CAAG,EACb,IAAI,CAAC,YAAY,CAAG,IAAI,CAAC,SAAS,CAAC,GACnC,IAAI,CAAC,SAAS,CAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAC1C,IAAI,CAAC,MAAM,CAA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AS,CAAC,MAAM,CAAC,WACxB,EAAa,SAAS,CAAC,MAAM,CAAC,YAE9B,EAAK,OAAO,GACZ,EAAK,KAAK,GAEV,KAGF,EAAK,SAAS,CAAC,EACjB,GA3BA,SAAS,gBAAgB,CAAC,UAAW,AAAA,IAC9B,EAAS,QAAQ,CAAC,EAAS,GAAG,GAAK,AAAqB,SAArB,EAAK,SAAS,KAItD,AAwBF,SAAoB,CAAO,EACzB,OAAQ,GACN,IAAK,YACH,EAAK,QAAQ,GACb,KAEF,KAAK,aACH,EAAK,SAAS,GACd,KAEF,KAAK,UACH,EAAK,MAAM,GACX,KAEF,KAAK,YACH,EAAK,QAAQ,EAEjB,CACF,EA1Ca,EAAS,GAAG,EAEvB,EAAM,WAAW,CAAG,EAAK,QAAQ,GACjC,EAAK,SAAS,CAAC,GACf,IACF","sources":["","src/scripts/main.js","src/modules/Game.class.js"],"sourcesContent":["\"use strict\";\nvar $a5fd07fa01589658$exports = {};\n\"use strict\";\nconst $a5fd07fa01589658$var$BOARD_SIZE = 4;\n/**\n * This class represents the game.\n * Now it has a basic structure, that is needed for testing.\n * Feel free to add more props and methods if needed.\n */ class $a5fd07fa01589658$var$Game {\n /**\n * Creates a new game instance.\n *\n * @param {number[][]} initialState\n * The initial state of the board.\n * @default\n * [[0, 0, 0, 0],\n * [0, 0, 0, 0],\n * [0, 0, 0, 0],\n * [0, 0, 0, 0]]\n *\n * If passed, the board will be initialized with the provided\n * initial state.\n */ constructor(initialState = this.getNewBoard()){\n this.state = initialState;\n this.initialState = this.copyState(initialState);\n this.prevState = this.copyState(this.state);\n this.status = \"idle\";\n this.score = 0;\n this.isWin = false;\n // eslint-disable-next-line no-console\n console.log(this.state[0], this.state[1], this.state[2], this.state[3]);\n }\n moveLeft() {\n const gameStatus = this.getStatus();\n if (gameStatus === \"idle\" || gameStatus === \"lose\") return;\n this.setPrevState();\n for(let i = 0; i < $a5fd07fa01589658$var$BOARD_SIZE; i++){\n const col = this.state[i];\n const movedCol = this.moveLine(col);\n this.state[i] = movedCol;\n }\n this.addCellIfMoved();\n this.updateStatus();\n }\n moveRight() {\n const gameStatus = this.getStatus();\n if (gameStatus === \"idle\" || gameStatus === \"lose\") return;\n this.setPrevState();\n for(let i = 0; i < $a5fd07fa01589658$var$BOARD_SIZE; i++){\n const col = this.state[i].reverse();\n const movedCol = this.moveLine(col);\n this.state[i] = movedCol.reverse();\n }\n this.addCellIfMoved();\n this.updateStatus();\n }\n moveUp() {\n const gameStatus = this.getStatus();\n if (gameStatus === \"idle\" || gameStatus === \"lose\") return;\n this.setPrevState();\n for(let rowIndex = 0; rowIndex < $a5fd07fa01589658$var$BOARD_SIZE; rowIndex++){\n const row = this.getRow(rowIndex);\n const movedRow = this.moveLine(row);\n this.changeRow(movedRow, rowIndex);\n }\n this.addCellIfMoved();\n this.updateStatus();\n }\n moveDown() {\n const gameStatus = this.getStatus();\n if (gameStatus === \"idle\" || gameStatus === \"lose\") return;\n this.setPrevState();\n for(let rowIndex = 0; rowIndex < $a5fd07fa01589658$var$BOARD_SIZE; rowIndex++){\n const row = this.getRow(rowIndex);\n const movedRow = this.moveLine(row.reverse());\n this.changeRow(movedRow.reverse(), rowIndex);\n }\n this.addCellIfMoved();\n this.updateStatus();\n }\n /**\n * @returns {number}\n */ getScore() {\n return this.score;\n }\n updateScore(cellNumber) {\n this.score += cellNumber;\n }\n getLineSum(arr) {\n const sum = arr.reduce((a, b)=>a + b, 0);\n return sum;\n }\n /**\n * @returns {number[][]}\n */ getState() {\n return this.state;\n }\n getPrevState() {\n return this.prevState;\n }\n setPrevState() {\n this.prevState = this.copyState(this.state);\n }\n copyState(state) {\n return state.map((line)=>[\n ...line\n ]);\n }\n /**\n * Returns the current game status.\n *\n * @returns {string} One of: 'idle', 'playing', 'win', 'lose'\n *\n * `idle` - the game has not started yet (the initial state);\n * `playing` - the game is in progress;\n * `win` - the game is won;\n * `lose` - the game is lost\n */ getStatus() {\n return this.status;\n }\n setStatus(newStatus) {\n this.status = newStatus;\n }\n /**\n * Starts the game.\n */ start() {\n this.addRandomCell();\n this.addRandomCell();\n this.setStatus(\"playing\");\n }\n /**\n * Resets the game.\n */ restart() {\n this.state = this.copyState(this.initialState);\n this.score = 0;\n this.setStatus(\"idle\");\n }\n getNewBoard() {\n return [\n ...Array($a5fd07fa01589658$var$BOARD_SIZE)\n ].map(()=>Array($a5fd07fa01589658$var$BOARD_SIZE).fill(0));\n }\n addRandomCell() {\n const emptyCells = this.getEmptyCells();\n if (emptyCells.length !== 0) {\n const anyIndex = Math.floor(Math.random() * emptyCells.length);\n const anyPosition = emptyCells[anyIndex];\n const randomValue = Math.random() < 0.9 ? 2 : 4;\n this.state[anyPosition.rowIndex][anyPosition.colIndex] = randomValue;\n }\n }\n getEmptyCells() {\n const emptyCells = [];\n for(let rowIndex = 0; rowIndex < $a5fd07fa01589658$var$BOARD_SIZE; rowIndex++)for(let colIndex = 0; colIndex < $a5fd07fa01589658$var$BOARD_SIZE; colIndex++){\n const cell = this.state[rowIndex][colIndex];\n if (cell === 0) emptyCells.push({\n rowIndex: rowIndex,\n colIndex: colIndex\n });\n }\n return emptyCells;\n }\n addCellIfMoved() {\n if (this.isMoved(this.getPrevState())) this.addRandomCell();\n }\n moveLine(lineArr) {\n const getOutZeroes = lineArr.filter((elem)=>elem !== 0);\n const newLine = getOutZeroes;\n for(let i = 0; i < newLine.length; i++){\n const curr = newLine[i];\n const next = newLine[i + 1];\n if (curr === next) {\n const newCell = curr + next;\n newLine.splice(i, 1, newCell);\n newLine.splice(i + 1, 1);\n this.updateScore(curr + next);\n if (newCell === 2048) this.isWin = true;\n }\n }\n while(newLine.length !== $a5fd07fa01589658$var$BOARD_SIZE)newLine.push(0);\n return newLine;\n }\n getRow(rowIndex) {\n const row = [];\n for(let colIndex = 0; colIndex < $a5fd07fa01589658$var$BOARD_SIZE; colIndex++){\n const col = this.state[colIndex];\n const elem = col[rowIndex];\n row.push(elem);\n }\n return row;\n }\n changeRow(rowToPlace, rowIndex) {\n for(let colIndex = 0; colIndex < $a5fd07fa01589658$var$BOARD_SIZE; colIndex++)this.state[colIndex][rowIndex] = rowToPlace[colIndex];\n }\n isMoved(prevState) {\n for(let r = 0; r < $a5fd07fa01589658$var$BOARD_SIZE; r++)for(let c = 0; c < $a5fd07fa01589658$var$BOARD_SIZE; c++){\n const prevCell = prevState[r][c];\n const currCell = this.state[r][c];\n if (prevCell !== currCell) return true;\n }\n return false;\n }\n isLose() {\n for(let r = 0; r < $a5fd07fa01589658$var$BOARD_SIZE; r++)for(let c = 0; c < $a5fd07fa01589658$var$BOARD_SIZE; c++){\n const currCell = this.state[r][c];\n const nextCell = r + 1 < $a5fd07fa01589658$var$BOARD_SIZE ? this.state[r + 1][c] : -1;\n const bottomCell = c + 1 < $a5fd07fa01589658$var$BOARD_SIZE ? this.state[r][c + 1] : -1;\n const emptyCell = currCell === 0 || nextCell === 0 || bottomCell === 0;\n const areCellsEqual = currCell === nextCell | currCell === bottomCell;\n if (areCellsEqual || emptyCell) return false;\n }\n return true;\n }\n updateStatus() {\n if (this.isLose()) this.setStatus(\"lose\");\n if (this.isWin) this.setStatus(\"win\");\n }\n drawBoard(cells) {\n this.state.forEach((row, rowIndex)=>{\n row.forEach((colValue, colIndex)=>{\n const calculateCellIndex = rowIndex * $a5fd07fa01589658$var$BOARD_SIZE + colIndex;\n const cell = cells[calculateCellIndex];\n if (colValue !== 0) {\n cell.textContent = colValue;\n cell.classList = `field-cell field-cell--${colValue}`;\n } else {\n cell.textContent = null;\n cell.classList = `field-cell`;\n }\n });\n });\n }\n}\n$a5fd07fa01589658$exports = $a5fd07fa01589658$var$Game;\n\n\nconst $09e991522ca7e64e$var$game = new $a5fd07fa01589658$exports();\nconst $09e991522ca7e64e$var$gameKeys = [\n \"ArrowUp\",\n \"ArrowDown\",\n \"ArrowLeft\",\n \"ArrowRight\"\n];\nconst $09e991522ca7e64e$var$button = document.querySelector(\".button\");\nconst $09e991522ca7e64e$var$score = document.querySelector(\".game-score\");\nconst $09e991522ca7e64e$var$messageStart = document.querySelector(\".message-start\");\nconst $09e991522ca7e64e$var$messageLose = document.querySelector(\".message-lose\");\nconst $09e991522ca7e64e$var$messageWin = document.querySelector(\".message-win\");\nconst $09e991522ca7e64e$var$cells = document.querySelectorAll(\".field-cell\");\n$09e991522ca7e64e$var$button.addEventListener(\"click\", $09e991522ca7e64e$var$setupGame);\ndocument.addEventListener(\"keydown\", (keeydown)=>{\n if (!$09e991522ca7e64e$var$gameKeys.includes(keeydown.key) || $09e991522ca7e64e$var$game.getStatus() === \"lose\") return;\n $09e991522ca7e64e$var$defineMove(keeydown.key);\n $09e991522ca7e64e$var$score.textContent = $09e991522ca7e64e$var$game.getScore();\n $09e991522ca7e64e$var$game.drawBoard($09e991522ca7e64e$var$cells);\n $09e991522ca7e64e$var$defineMessage();\n});\nfunction $09e991522ca7e64e$var$setupGame() {\n if ($09e991522ca7e64e$var$button.textContent === \"Start\") {\n $09e991522ca7e64e$var$game.start();\n $09e991522ca7e64e$var$button.textContent = \"Restart\";\n $09e991522ca7e64e$var$button.classList.toggle(\"restart\");\n $09e991522ca7e64e$var$messageStart.classList.toggle(\"hidden\");\n } else {\n $09e991522ca7e64e$var$game.restart();\n $09e991522ca7e64e$var$game.start();\n $09e991522ca7e64e$var$defineMessage();\n }\n $09e991522ca7e64e$var$game.drawBoard($09e991522ca7e64e$var$cells);\n}\nfunction $09e991522ca7e64e$var$defineMove(keydown) {\n switch(keydown){\n case \"ArrowLeft\":\n $09e991522ca7e64e$var$game.moveLeft();\n break;\n case \"ArrowRight\":\n $09e991522ca7e64e$var$game.moveRight();\n break;\n case \"ArrowUp\":\n $09e991522ca7e64e$var$game.moveUp();\n break;\n case \"ArrowDown\":\n $09e991522ca7e64e$var$game.moveDown();\n break;\n }\n}\nfunction $09e991522ca7e64e$var$defineMessage() {\n switch($09e991522ca7e64e$var$game.getStatus()){\n case \"win\":\n $09e991522ca7e64e$var$messageWin.classList.remove(\"hidden\");\n break;\n case \"lose\":\n $09e991522ca7e64e$var$messageLose.classList.remove(\"hidden\");\n break;\n case \"playing\":\n if (!$09e991522ca7e64e$var$messageWin.classList.contains(\"hidden\")) $09e991522ca7e64e$var$messageWin.classList.add(\"hidden\");\n if (!$09e991522ca7e64e$var$messageLose.classList.contains(\"hidden\")) $09e991522ca7e64e$var$messageLose.classList.add(\"hidden\");\n }\n}\n\n\n//# sourceMappingURL=index.1f6979d2.js.map\n","'use strict';\n\nconst Game = require('../modules/Game.class');\nconst game = new Game();\nconst gameKeys = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'];\n\nconst button = document.querySelector('.button');\nconst score = document.querySelector('.game-score');\nconst messageStart = document.querySelector('.message-start');\nconst messageLose = document.querySelector('.message-lose');\nconst messageWin = document.querySelector('.message-win');\nconst cells = document.querySelectorAll('.field-cell');\n\nbutton.addEventListener('click', setupGame);\n\ndocument.addEventListener('keydown', keeydown => {\n if (!gameKeys.includes(keeydown.key) || game.getStatus() === 'lose') {\n return;\n }\n\n defineMove(keeydown.key);\n\n score.textContent = game.getScore();\n game.drawBoard(cells);\n defineMessage();\n});\n\nfunction setupGame() {\n if (button.textContent === 'Start') {\n game.start();\n\n button.textContent = 'Restart';\n button.classList.toggle('restart');\n messageStart.classList.toggle('hidden');\n } else {\n game.restart();\n game.start();\n\n defineMessage();\n }\n\n game.drawBoard(cells);\n}\n\nfunction defineMove(keydown) {\n switch (keydown) {\n case 'ArrowLeft':\n game.moveLeft();\n break;\n\n case 'ArrowRight':\n game.moveRight();\n break;\n\n case 'ArrowUp':\n game.moveUp();\n break;\n\n case 'ArrowDown':\n game.moveDown();\n break;\n }\n}\n\nfunction defineMessage() {\n switch (game.getStatus()) {\n case 'win':\n messageWin.classList.remove('hidden');\n break;\n\n case 'lose':\n messageLose.classList.remove('hidden');\n break;\n\n case 'playing':\n if (!messageWin.classList.contains('hidden')) {\n messageWin.classList.add('hidden');\n }\n\n if (!messageLose.classList.contains('hidden')) {\n messageLose.classList.add('hidden');\n }\n }\n}\n","'use strict';\n\nconst BOARD_SIZE = 4;\n\n/**\n * This class represents the game.\n * Now it has a basic structure, that is needed for testing.\n * Feel free to add more props and methods if needed.\n */\nclass Game {\n /**\n * Creates a new game instance.\n *\n * @param {number[][]} initialState\n * The initial state of the board.\n * @default\n * [[0, 0, 0, 0],\n * [0, 0, 0, 0],\n * [0, 0, 0, 0],\n * [0, 0, 0, 0]]\n *\n * If passed, the board will be initialized with the provided\n * initial state.\n */\n constructor(initialState = this.getNewBoard()) {\n this.state = initialState;\n this.initialState = this.copyState(initialState);\n this.prevState = this.copyState(this.state);\n this.status = 'idle';\n this.score = 0;\n this.isWin = false;\n\n // eslint-disable-next-line no-console\n console.log(this.state[0], this.state[1], this.state[2], this.state[3]);\n }\n\n moveLeft() {\n const gameStatus = this.getStatus();\n\n if (gameStatus === 'idle' || gameStatus === 'lose') {\n return;\n }\n\n this.setPrevState();\n\n for (let i = 0; i < BOARD_SIZE; i++) {\n const col = this.state[i];\n const movedCol = this.moveLine(col);\n\n this.state[i] = movedCol;\n }\n\n this.addCellIfMoved();\n this.updateStatus();\n }\n\n moveRight() {\n const gameStatus = this.getStatus();\n\n if (gameStatus === 'idle' || gameStatus === 'lose') {\n return;\n }\n\n this.setPrevState();\n\n for (let i = 0; i < BOARD_SIZE; i++) {\n const col = this.state[i].reverse();\n const movedCol = this.moveLine(col);\n\n this.state[i] = movedCol.reverse();\n }\n\n this.addCellIfMoved();\n this.updateStatus();\n }\n\n moveUp() {\n const gameStatus = this.getStatus();\n\n if (gameStatus === 'idle' || gameStatus === 'lose') {\n return;\n }\n\n this.setPrevState();\n\n for (let rowIndex = 0; rowIndex < BOARD_SIZE; rowIndex++) {\n const row = this.getRow(rowIndex);\n const movedRow = this.moveLine(row);\n\n this.changeRow(movedRow, rowIndex);\n }\n\n this.addCellIfMoved();\n this.updateStatus();\n }\n\n moveDown() {\n const gameStatus = this.getStatus();\n\n if (gameStatus === 'idle' || gameStatus === 'lose') {\n return;\n }\n\n this.setPrevState();\n\n for (let rowIndex = 0; rowIndex < BOARD_SIZE; rowIndex++) {\n const row = this.getRow(rowIndex);\n const movedRow = this.moveLine(row.reverse());\n\n this.changeRow(movedRow.reverse(), rowIndex);\n }\n\n this.addCellIfMoved();\n this.updateStatus();\n }\n\n /**\n * @returns {number}\n */\n getScore() {\n return this.score;\n }\n\n updateScore(cellNumber) {\n this.score += cellNumber;\n }\n\n getLineSum(arr) {\n const sum = arr.reduce((a, b) => a + b, 0);\n\n return sum;\n }\n\n /**\n * @returns {number[][]}\n */\n getState() {\n return this.state;\n }\n\n getPrevState() {\n return this.prevState;\n }\n\n setPrevState() {\n this.prevState = this.copyState(this.state);\n }\n\n copyState(state) {\n return state.map(line => [...line]);\n }\n\n /**\n * Returns the current game status.\n *\n * @returns {string} One of: 'idle', 'playing', 'win', 'lose'\n *\n * `idle` - the game has not started yet (the initial state);\n * `playing` - the game is in progress;\n * `win` - the game is won;\n * `lose` - the game is lost\n */\n getStatus() {\n return this.status;\n }\n\n setStatus(newStatus) {\n this.status = newStatus;\n }\n\n /**\n * Starts the game.\n */\n start() {\n this.addRandomCell();\n this.addRandomCell();\n this.setStatus('playing');\n }\n\n /**\n * Resets the game.\n */\n restart() {\n this.state = this.copyState(this.initialState);\n this.score = 0;\n this.setStatus('idle');\n }\n\n getNewBoard() {\n return [...Array(BOARD_SIZE)].map(() => Array(BOARD_SIZE).fill(0));\n }\n\n addRandomCell() {\n const emptyCells = this.getEmptyCells();\n\n if (emptyCells.length !== 0) {\n const anyIndex = Math.floor(Math.random() * emptyCells.length);\n const anyPosition = emptyCells[anyIndex];\n const randomValue = Math.random() < 0.9 ? 2 : 4;\n\n this.state[anyPosition.rowIndex][anyPosition.colIndex] = randomValue;\n }\n }\n\n getEmptyCells() {\n const emptyCells = [];\n\n for (let rowIndex = 0; rowIndex < BOARD_SIZE; rowIndex++) {\n for (let colIndex = 0; colIndex < BOARD_SIZE; colIndex++) {\n const cell = this.state[rowIndex][colIndex];\n\n if (cell === 0) {\n emptyCells.push({\n rowIndex, colIndex,\n });\n }\n }\n }\n\n return emptyCells;\n }\n\n addCellIfMoved() {\n if (this.isMoved(this.getPrevState())) {\n this.addRandomCell();\n }\n }\n\n moveLine(lineArr) {\n const getOutZeroes = lineArr.filter(elem => elem !== 0);\n const newLine = getOutZeroes;\n\n for (let i = 0; i < newLine.length; i++) {\n const curr = newLine[i];\n const next = newLine[i + 1];\n\n if (curr === next) {\n const newCell = curr + next;\n\n newLine.splice(i, 1, newCell);\n newLine.splice(i + 1, 1);\n this.updateScore(curr + next);\n\n if (newCell === 2048) {\n this.isWin = true;\n }\n }\n }\n\n while (newLine.length !== BOARD_SIZE) {\n newLine.push(0);\n }\n\n return newLine;\n }\n\n getRow(rowIndex) {\n const row = [];\n\n for (let colIndex = 0; colIndex < BOARD_SIZE; colIndex++) {\n const col = this.state[colIndex];\n const elem = col[rowIndex];\n\n row.push(elem);\n }\n\n return row;\n }\n\n changeRow(rowToPlace, rowIndex) {\n for (let colIndex = 0; colIndex < BOARD_SIZE; colIndex++) {\n this.state[colIndex][rowIndex] = rowToPlace[colIndex];\n }\n }\n\n isMoved(prevState) {\n for (let r = 0; r < BOARD_SIZE; r++) {\n for (let c = 0; c < BOARD_SIZE; c++) {\n const prevCell = prevState[r][c];\n const currCell = this.state[r][c];\n\n if (prevCell !== currCell) {\n return true;\n }\n }\n }\n\n return false;\n }\n\n isLose() {\n for (let r = 0; r < BOARD_SIZE; r++) {\n for (let c = 0; c < BOARD_SIZE; c++) {\n const currCell = this.state[r][c];\n const nextCell = r + 1 < BOARD_SIZE ? this.state[r + 1][c] : -1;\n const bottomCell = c + 1 < BOARD_SIZE ? this.state[r][c + 1] : -1;\n\n const emptyCell = currCell === 0 || nextCell === 0 || bottomCell === 0;\n const areCellsEqual = currCell === nextCell | currCell === bottomCell;\n\n if (areCellsEqual || emptyCell) {\n return false;\n }\n }\n }\n\n return true;\n }\n\n updateStatus() {\n if (this.isLose()) {\n this.setStatus('lose');\n }\n\n if (this.isWin) {\n this.setStatus('win');\n }\n }\n\n drawBoard(cells) {\n this.state.forEach((row, rowIndex) => {\n row.forEach((colValue, colIndex) => {\n const calculateCellIndex = rowIndex * BOARD_SIZE + colIndex;\n const cell = cells[calculateCellIndex];\n\n if (colValue !== 0) {\n cell.textContent = colValue;\n cell.classList = `field-cell field-cell--${colValue}`;\n } else {\n cell.textContent = null;\n cell.classList = `field-cell`;\n }\n });\n });\n }\n}\n\nmodule.exports = Game;\n"],"names":["$09e991522ca7e64e$var$game","constructor","initialState","getNewBoard","state","copyState","prevState","status","score","isWin","console","log","moveLeft","gameStatus","getStatus","setPrevState","i","col","movedCol","moveLine","addCellIfMoved","updateStatus","moveRight","reverse","moveUp","rowIndex","row","getRow","movedRow","changeRow","moveDown","getScore","updateScore","cellNumber","getLineSum","arr","reduce","a","b","getState","getPrevState","map","line","setStatus","newStatus","start","addRandomCell","restart","Array","fill","emptyCells","getEmptyCells","length","anyIndex","Math","floor","random","anyPosition","colIndex","push","isMoved","lineArr","getOutZeroes","filter","elem","newLine","curr","next","newCell","splice","rowToPlace","r","c","prevCell","isLose","currCell","nextCell","bottomCell","emptyCell","areCellsEqual","drawBoard","cells","forEach","colValue","cell","textContent","classList","$09e991522ca7e64e$var$gameKeys","$09e991522ca7e64e$var$button","document","querySelector","$09e991522ca7e64e$var$score","$09e991522ca7e64e$var$messageStart","$09e991522ca7e64e$var$messageLose","$09e991522ca7e64e$var$messageWin","$09e991522ca7e64e$var$cells","querySelectorAll","$09e991522ca7e64e$var$defineMessage","remove","contains","add","addEventListener","toggle","keeydown","includes","key","$09e991522ca7e64e$var$defineMove","keydown"],"version":3,"file":"index.1f6979d2.js.map"} \ No newline at end of file diff --git a/index.40606d0b.js b/index.40606d0b.js new file mode 100644 index 000000000..eb63ec067 --- /dev/null +++ b/index.40606d0b.js @@ -0,0 +1,2 @@ +!function(){function t(t,e){for(var r=0;rt.length)&&(e=t.length);for(var r=0,a=Array(e);r0&&void 0!==arguments[0]?arguments[0]:this.getNewBoard();!function(t,e){if(!(t instanceof e))throw TypeError("Cannot call a class as a function")}(this,s),this.state=t,this.initialState=this.copyState(t),this.prevState=this.copyState(this.state),this.status="idle",this.score=0,this.isWin=!1,console.log(this.state[0],this.state[1],this.state[2],this.state[3])}return e=[{key:"moveLeft",value:function(){var t=this.getStatus();if("idle"!==t&&"lose"!==t){this.setPrevState();for(var e=0;e<4;e++){var r=this.state[e],a=this.moveLine(r);this.state[e]=a}this.addCellIfMoved(),this.updateStatus()}}},{key:"moveRight",value:function(){var t=this.getStatus();if("idle"!==t&&"lose"!==t){this.setPrevState();for(var e=0;e<4;e++){var r=this.state[e].reverse(),a=this.moveLine(r);this.state[e]=a.reverse()}this.addCellIfMoved(),this.updateStatus()}}},{key:"moveUp",value:function(){var t=this.getStatus();if("idle"!==t&&"lose"!==t){this.setPrevState();for(var e=0;e<4;e++){var r=this.getRow(e),a=this.moveLine(r);this.changeRow(a,e)}this.addCellIfMoved(),this.updateStatus()}}},{key:"moveDown",value:function(){var t=this.getStatus();if("idle"!==t&&"lose"!==t){this.setPrevState();for(var e=0;e<4;e++){var r=this.getRow(e),a=this.moveLine(r.reverse());this.changeRow(a.reverse(),e)}this.addCellIfMoved(),this.updateStatus()}}},{key:"getScore",value:function(){return this.score}},{key:"updateScore",value:function(t){this.score+=t}},{key:"getLineSum",value:function(t){return t.reduce(function(t,e){return t+e},0)}},{key:"getState",value:function(){return this.state}},{key:"getPrevState",value:function(){return this.prevState}},{key:"setPrevState",value:function(){this.prevState=this.copyState(this.state)}},{key:"copyState",value:function(t){return t.map(function(t){return r(t)})}},{key:"getStatus",value:function(){return this.status}},{key:"setStatus",value:function(t){this.status=t}},{key:"start",value:function(){this.addRandomCell(),this.addRandomCell(),this.setStatus("playing")}},{key:"restart",value:function(){this.state=this.copyState(this.initialState),this.score=0,this.setStatus("idle")}},{key:"getNewBoard",value:function(){return r([,,,,]).map(function(){return[,,,,].fill(0)})}},{key:"addRandomCell",value:function(){var t=this.getEmptyCells();if(0!==t.length){var e=Math.floor(Math.random()*t.length),r=t[e];this.state[r.rowIndex][r.colIndex]=.9>Math.random()?2:4}}},{key:"getEmptyCells",value:function(){for(var t=[],e=0;e<4;e++)for(var r=0;r<4;r++)0===this.state[e][r]&&t.push({rowIndex:e,colIndex:r});return t}},{key:"addCellIfMoved",value:function(){this.isMoved(this.getPrevState())&&this.addRandomCell()}},{key:"moveLine",value:function(t){for(var e=t.filter(function(t){return 0!==t}),r=0;r","src/scripts/main.js","src/modules/Game.class.js","node_modules/@swc/helpers/esm/_class_call_check.js","node_modules/@swc/helpers/esm/_create_class.js","node_modules/@swc/helpers/esm/_to_consumable_array.js","node_modules/@swc/helpers/esm/_array_without_holes.js","node_modules/@swc/helpers/esm/_array_like_to_array.js","node_modules/@swc/helpers/esm/_iterable_to_array.js","node_modules/@swc/helpers/esm/_non_iterable_spread.js","node_modules/@swc/helpers/esm/_unsupported_iterable_to_array.js"],"sourcesContent":["(function () {\n\"use strict\";\nvar $3d28d7f1aac198f5$exports = {};\nfunction $8713978b2328d32b$export$2996f80ef42b8419(instance, Constructor) {\n if (!(instance instanceof Constructor)) throw new TypeError(\"Cannot call a class as a function\");\n}\n\n\nfunction $4fc75ccb937ab1df$var$_defineProperties(target, props) {\n for(var i = 0; i < props.length; i++){\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n Object.defineProperty(target, descriptor.key, descriptor);\n }\n}\nfunction $4fc75ccb937ab1df$export$d60067ff2358eee8(Constructor, protoProps, staticProps) {\n if (protoProps) $4fc75ccb937ab1df$var$_defineProperties(Constructor.prototype, protoProps);\n if (staticProps) $4fc75ccb937ab1df$var$_defineProperties(Constructor, staticProps);\n return Constructor;\n}\n\n\nfunction $c3b10a83b523f372$export$79e617b1955a2616(arr, len) {\n if (len == null || len > arr.length) len = arr.length;\n for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];\n return arr2;\n}\n\n\nfunction $c50969dc1df61e8b$export$7e0947b5ad3404e2(arr) {\n if (Array.isArray(arr)) return (0, $c3b10a83b523f372$export$79e617b1955a2616)(arr);\n}\n\n\nfunction $09c9f293d010c0e1$export$1eb58a6e75231000(iter) {\n if (typeof Symbol !== \"undefined\" && iter[Symbol.iterator] != null || iter[\"@@iterator\"] != null) return Array.from(iter);\n}\n\n\nfunction $38c2d4931cb7a7c4$export$e6f3c4780d19eb2b() {\n throw new TypeError(\"Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\");\n}\n\n\n\nfunction $d4f69c5c6c4654b1$export$a5be06335b3a083c(o, minLen) {\n if (!o) return;\n if (typeof o === \"string\") return (0, $c3b10a83b523f372$export$79e617b1955a2616)(o, minLen);\n var n = Object.prototype.toString.call(o).slice(8, -1);\n if (n === \"Object\" && o.constructor) n = o.constructor.name;\n if (n === \"Map\" || n === \"Set\") return Array.from(n);\n if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return (0, $c3b10a83b523f372$export$79e617b1955a2616)(o, minLen);\n}\n\n\nfunction $227c6742e0ff6f82$export$1b5e630bc3aea29f(arr) {\n return (0, $c50969dc1df61e8b$export$7e0947b5ad3404e2)(arr) || (0, $09c9f293d010c0e1$export$1eb58a6e75231000)(arr) || (0, $d4f69c5c6c4654b1$export$a5be06335b3a083c)(arr) || (0, $38c2d4931cb7a7c4$export$e6f3c4780d19eb2b)();\n}\n\n\n\"use strict\";\nvar $3d28d7f1aac198f5$var$BOARD_SIZE = 4;\n/**\n * This class represents the game.\n * Now it has a basic structure, that is needed for testing.\n * Feel free to add more props and methods if needed.\n */ var $3d28d7f1aac198f5$var$Game = /*#__PURE__*/ function() {\n function Game() {\n var initialState = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.getNewBoard();\n (0, $8713978b2328d32b$export$2996f80ef42b8419)(this, Game);\n this.state = initialState;\n this.initialState = this.copyState(initialState);\n this.prevState = this.copyState(this.state);\n this.status = \"idle\";\n this.score = 0;\n this.isWin = false;\n // eslint-disable-next-line no-console\n console.log(this.state[0], this.state[1], this.state[2], this.state[3]);\n }\n (0, $4fc75ccb937ab1df$export$d60067ff2358eee8)(Game, [\n {\n key: \"moveLeft\",\n value: function moveLeft() {\n var gameStatus = this.getStatus();\n if (gameStatus === \"idle\" || gameStatus === \"lose\") return;\n this.setPrevState();\n for(var i = 0; i < $3d28d7f1aac198f5$var$BOARD_SIZE; i++){\n var col = this.state[i];\n var movedCol = this.moveLine(col);\n this.state[i] = movedCol;\n }\n this.addCellIfMoved();\n this.updateStatus();\n }\n },\n {\n key: \"moveRight\",\n value: function moveRight() {\n var gameStatus = this.getStatus();\n if (gameStatus === \"idle\" || gameStatus === \"lose\") return;\n this.setPrevState();\n for(var i = 0; i < $3d28d7f1aac198f5$var$BOARD_SIZE; i++){\n var col = this.state[i].reverse();\n var movedCol = this.moveLine(col);\n this.state[i] = movedCol.reverse();\n }\n this.addCellIfMoved();\n this.updateStatus();\n }\n },\n {\n key: \"moveUp\",\n value: function moveUp() {\n var gameStatus = this.getStatus();\n if (gameStatus === \"idle\" || gameStatus === \"lose\") return;\n this.setPrevState();\n for(var rowIndex = 0; rowIndex < $3d28d7f1aac198f5$var$BOARD_SIZE; rowIndex++){\n var row = this.getRow(rowIndex);\n var movedRow = this.moveLine(row);\n this.changeRow(movedRow, rowIndex);\n }\n this.addCellIfMoved();\n this.updateStatus();\n }\n },\n {\n key: \"moveDown\",\n value: function moveDown() {\n var gameStatus = this.getStatus();\n if (gameStatus === \"idle\" || gameStatus === \"lose\") return;\n this.setPrevState();\n for(var rowIndex = 0; rowIndex < $3d28d7f1aac198f5$var$BOARD_SIZE; rowIndex++){\n var row = this.getRow(rowIndex);\n var movedRow = this.moveLine(row.reverse());\n this.changeRow(movedRow.reverse(), rowIndex);\n }\n this.addCellIfMoved();\n this.updateStatus();\n }\n },\n {\n /**\n * @returns {number}\n */ key: \"getScore\",\n value: function getScore() {\n return this.score;\n }\n },\n {\n key: \"updateScore\",\n value: function updateScore(cellNumber) {\n this.score += cellNumber;\n }\n },\n {\n key: \"getLineSum\",\n value: function getLineSum(arr) {\n var sum = arr.reduce(function(a, b) {\n return a + b;\n }, 0);\n return sum;\n }\n },\n {\n /**\n * @returns {number[][]}\n */ key: \"getState\",\n value: function getState() {\n return this.state;\n }\n },\n {\n key: \"getPrevState\",\n value: function getPrevState() {\n return this.prevState;\n }\n },\n {\n key: \"setPrevState\",\n value: function setPrevState() {\n this.prevState = this.copyState(this.state);\n }\n },\n {\n key: \"copyState\",\n value: function copyState(state) {\n return state.map(function(line) {\n return (0, $227c6742e0ff6f82$export$1b5e630bc3aea29f)(line);\n });\n }\n },\n {\n /**\n * Returns the current game status.\n *\n * @returns {string} One of: 'idle', 'playing', 'win', 'lose'\n *\n * `idle` - the game has not started yet (the initial state);\n * `playing` - the game is in progress;\n * `win` - the game is won;\n * `lose` - the game is lost\n */ key: \"getStatus\",\n value: function getStatus() {\n return this.status;\n }\n },\n {\n key: \"setStatus\",\n value: function setStatus(newStatus) {\n this.status = newStatus;\n }\n },\n {\n /**\n * Starts the game.\n */ key: \"start\",\n value: function start() {\n this.addRandomCell();\n this.addRandomCell();\n this.setStatus(\"playing\");\n }\n },\n {\n /**\n * Resets the game.\n */ key: \"restart\",\n value: function restart() {\n this.state = this.copyState(this.initialState);\n this.score = 0;\n this.setStatus(\"idle\");\n }\n },\n {\n key: \"getNewBoard\",\n value: function getNewBoard() {\n return (0, $227c6742e0ff6f82$export$1b5e630bc3aea29f)(Array($3d28d7f1aac198f5$var$BOARD_SIZE)).map(function() {\n return Array($3d28d7f1aac198f5$var$BOARD_SIZE).fill(0);\n });\n }\n },\n {\n key: \"addRandomCell\",\n value: function addRandomCell() {\n var emptyCells = this.getEmptyCells();\n if (emptyCells.length !== 0) {\n var anyIndex = Math.floor(Math.random() * emptyCells.length);\n var anyPosition = emptyCells[anyIndex];\n var randomValue = Math.random() < 0.9 ? 2 : 4;\n this.state[anyPosition.rowIndex][anyPosition.colIndex] = randomValue;\n }\n }\n },\n {\n key: \"getEmptyCells\",\n value: function getEmptyCells() {\n var emptyCells = [];\n for(var rowIndex = 0; rowIndex < $3d28d7f1aac198f5$var$BOARD_SIZE; rowIndex++)for(var colIndex = 0; colIndex < $3d28d7f1aac198f5$var$BOARD_SIZE; colIndex++){\n var cell = this.state[rowIndex][colIndex];\n if (cell === 0) emptyCells.push({\n rowIndex: rowIndex,\n colIndex: colIndex\n });\n }\n return emptyCells;\n }\n },\n {\n key: \"addCellIfMoved\",\n value: function addCellIfMoved() {\n if (this.isMoved(this.getPrevState())) this.addRandomCell();\n }\n },\n {\n key: \"moveLine\",\n value: function moveLine(lineArr) {\n var getOutZeroes = lineArr.filter(function(elem) {\n return elem !== 0;\n });\n var newLine = getOutZeroes;\n for(var i = 0; i < newLine.length; i++){\n var curr = newLine[i];\n var next = newLine[i + 1];\n if (curr === next) {\n var newCell = curr + next;\n newLine.splice(i, 1, newCell);\n newLine.splice(i + 1, 1);\n this.updateScore(curr + next);\n if (newCell === 2048) this.isWin = true;\n }\n }\n while(newLine.length !== $3d28d7f1aac198f5$var$BOARD_SIZE)newLine.push(0);\n return newLine;\n }\n },\n {\n key: \"getRow\",\n value: function getRow(rowIndex) {\n var row = [];\n for(var colIndex = 0; colIndex < $3d28d7f1aac198f5$var$BOARD_SIZE; colIndex++){\n var col = this.state[colIndex];\n var elem = col[rowIndex];\n row.push(elem);\n }\n return row;\n }\n },\n {\n key: \"changeRow\",\n value: function changeRow(rowToPlace, rowIndex) {\n for(var colIndex = 0; colIndex < $3d28d7f1aac198f5$var$BOARD_SIZE; colIndex++)this.state[colIndex][rowIndex] = rowToPlace[colIndex];\n }\n },\n {\n key: \"isMoved\",\n value: function isMoved(prevState) {\n for(var r = 0; r < $3d28d7f1aac198f5$var$BOARD_SIZE; r++)for(var c = 0; c < $3d28d7f1aac198f5$var$BOARD_SIZE; c++){\n var prevCell = prevState[r][c];\n var currCell = this.state[r][c];\n if (prevCell !== currCell) return true;\n }\n return false;\n }\n },\n {\n key: \"isLose\",\n value: function isLose() {\n for(var r = 0; r < $3d28d7f1aac198f5$var$BOARD_SIZE; r++)for(var c = 0; c < $3d28d7f1aac198f5$var$BOARD_SIZE; c++){\n var currCell = this.state[r][c];\n var nextCell = r + 1 < $3d28d7f1aac198f5$var$BOARD_SIZE ? this.state[r + 1][c] : -1;\n var bottomCell = c + 1 < $3d28d7f1aac198f5$var$BOARD_SIZE ? this.state[r][c + 1] : -1;\n var emptyCell = currCell === 0 || nextCell === 0 || bottomCell === 0;\n var areCellsEqual = currCell === nextCell | currCell === bottomCell;\n if (areCellsEqual || emptyCell) return false;\n }\n return true;\n }\n },\n {\n key: \"updateStatus\",\n value: function updateStatus() {\n if (this.isLose()) this.setStatus(\"lose\");\n if (this.isWin) this.setStatus(\"win\");\n }\n },\n {\n key: \"drawBoard\",\n value: function drawBoard(cells) {\n this.state.forEach(function(row, rowIndex) {\n row.forEach(function(colValue, colIndex) {\n var calculateCellIndex = rowIndex * $3d28d7f1aac198f5$var$BOARD_SIZE + colIndex;\n var cell = cells[calculateCellIndex];\n if (colValue !== 0) {\n cell.textContent = colValue;\n cell.classList = \"field-cell field-cell--\".concat(colValue);\n } else {\n cell.textContent = null;\n cell.classList = \"field-cell\";\n }\n });\n });\n }\n }\n ]);\n return Game;\n}();\n$3d28d7f1aac198f5$exports = $3d28d7f1aac198f5$var$Game;\n\n\nvar $197cd56b15c33885$var$game = new $3d28d7f1aac198f5$exports();\nvar $197cd56b15c33885$var$gameKeys = [\n \"ArrowUp\",\n \"ArrowDown\",\n \"ArrowLeft\",\n \"ArrowRight\"\n];\nvar $197cd56b15c33885$var$button = document.querySelector(\".button\");\nvar $197cd56b15c33885$var$score = document.querySelector(\".game-score\");\nvar $197cd56b15c33885$var$messageStart = document.querySelector(\".message-start\");\nvar $197cd56b15c33885$var$messageLose = document.querySelector(\".message-lose\");\nvar $197cd56b15c33885$var$messageWin = document.querySelector(\".message-win\");\nvar $197cd56b15c33885$var$cells = document.querySelectorAll(\".field-cell\");\n$197cd56b15c33885$var$button.addEventListener(\"click\", $197cd56b15c33885$var$setupGame);\ndocument.addEventListener(\"keydown\", function(keeydown) {\n if (!$197cd56b15c33885$var$gameKeys.includes(keeydown.key) || $197cd56b15c33885$var$game.getStatus() === \"lose\") return;\n $197cd56b15c33885$var$defineMove(keeydown.key);\n $197cd56b15c33885$var$score.textContent = $197cd56b15c33885$var$game.getScore();\n $197cd56b15c33885$var$game.drawBoard($197cd56b15c33885$var$cells);\n $197cd56b15c33885$var$defineMessage();\n});\nfunction $197cd56b15c33885$var$setupGame() {\n if ($197cd56b15c33885$var$button.textContent === \"Start\") {\n $197cd56b15c33885$var$game.start();\n $197cd56b15c33885$var$button.textContent = \"Restart\";\n $197cd56b15c33885$var$button.classList.toggle(\"restart\");\n $197cd56b15c33885$var$messageStart.classList.toggle(\"hidden\");\n } else {\n $197cd56b15c33885$var$game.restart();\n $197cd56b15c33885$var$game.start();\n $197cd56b15c33885$var$defineMessage();\n }\n $197cd56b15c33885$var$game.drawBoard($197cd56b15c33885$var$cells);\n}\nfunction $197cd56b15c33885$var$defineMove(keydown) {\n switch(keydown){\n case \"ArrowLeft\":\n $197cd56b15c33885$var$game.moveLeft();\n break;\n case \"ArrowRight\":\n $197cd56b15c33885$var$game.moveRight();\n break;\n case \"ArrowUp\":\n $197cd56b15c33885$var$game.moveUp();\n break;\n case \"ArrowDown\":\n $197cd56b15c33885$var$game.moveDown();\n break;\n }\n}\nfunction $197cd56b15c33885$var$defineMessage() {\n switch($197cd56b15c33885$var$game.getStatus()){\n case \"win\":\n $197cd56b15c33885$var$messageWin.classList.remove(\"hidden\");\n break;\n case \"lose\":\n $197cd56b15c33885$var$messageLose.classList.remove(\"hidden\");\n break;\n case \"playing\":\n if (!$197cd56b15c33885$var$messageWin.classList.contains(\"hidden\")) $197cd56b15c33885$var$messageWin.classList.add(\"hidden\");\n if (!$197cd56b15c33885$var$messageLose.classList.contains(\"hidden\")) $197cd56b15c33885$var$messageLose.classList.add(\"hidden\");\n }\n}\n\n})();\n//# sourceMappingURL=index.40606d0b.js.map\n","'use strict';\n\nconst Game = require('../modules/Game.class');\nconst game = new Game();\nconst gameKeys = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'];\n\nconst button = document.querySelector('.button');\nconst score = document.querySelector('.game-score');\nconst messageStart = document.querySelector('.message-start');\nconst messageLose = document.querySelector('.message-lose');\nconst messageWin = document.querySelector('.message-win');\nconst cells = document.querySelectorAll('.field-cell');\n\nbutton.addEventListener('click', setupGame);\n\ndocument.addEventListener('keydown', keeydown => {\n if (!gameKeys.includes(keeydown.key) || game.getStatus() === 'lose') {\n return;\n }\n\n defineMove(keeydown.key);\n\n score.textContent = game.getScore();\n game.drawBoard(cells);\n defineMessage();\n});\n\nfunction setupGame() {\n if (button.textContent === 'Start') {\n game.start();\n\n button.textContent = 'Restart';\n button.classList.toggle('restart');\n messageStart.classList.toggle('hidden');\n } else {\n game.restart();\n game.start();\n\n defineMessage();\n }\n\n game.drawBoard(cells);\n}\n\nfunction defineMove(keydown) {\n switch (keydown) {\n case 'ArrowLeft':\n game.moveLeft();\n break;\n\n case 'ArrowRight':\n game.moveRight();\n break;\n\n case 'ArrowUp':\n game.moveUp();\n break;\n\n case 'ArrowDown':\n game.moveDown();\n break;\n }\n}\n\nfunction defineMessage() {\n switch (game.getStatus()) {\n case 'win':\n messageWin.classList.remove('hidden');\n break;\n\n case 'lose':\n messageLose.classList.remove('hidden');\n break;\n\n case 'playing':\n if (!messageWin.classList.contains('hidden')) {\n messageWin.classList.add('hidden');\n }\n\n if (!messageLose.classList.contains('hidden')) {\n messageLose.classList.add('hidden');\n }\n }\n}\n","'use strict';\n\nconst BOARD_SIZE = 4;\n\n/**\n * This class represents the game.\n * Now it has a basic structure, that is needed for testing.\n * Feel free to add more props and methods if needed.\n */\nclass Game {\n /**\n * Creates a new game instance.\n *\n * @param {number[][]} initialState\n * The initial state of the board.\n * @default\n * [[0, 0, 0, 0],\n * [0, 0, 0, 0],\n * [0, 0, 0, 0],\n * [0, 0, 0, 0]]\n *\n * If passed, the board will be initialized with the provided\n * initial state.\n */\n constructor(initialState = this.getNewBoard()) {\n this.state = initialState;\n this.initialState = this.copyState(initialState);\n this.prevState = this.copyState(this.state);\n this.status = 'idle';\n this.score = 0;\n this.isWin = false;\n\n // eslint-disable-next-line no-console\n console.log(this.state[0], this.state[1], this.state[2], this.state[3]);\n }\n\n moveLeft() {\n const gameStatus = this.getStatus();\n\n if (gameStatus === 'idle' || gameStatus === 'lose') {\n return;\n }\n\n this.setPrevState();\n\n for (let i = 0; i < BOARD_SIZE; i++) {\n const col = this.state[i];\n const movedCol = this.moveLine(col);\n\n this.state[i] = movedCol;\n }\n\n this.addCellIfMoved();\n this.updateStatus();\n }\n\n moveRight() {\n const gameStatus = this.getStatus();\n\n if (gameStatus === 'idle' || gameStatus === 'lose') {\n return;\n }\n\n this.setPrevState();\n\n for (let i = 0; i < BOARD_SIZE; i++) {\n const col = this.state[i].reverse();\n const movedCol = this.moveLine(col);\n\n this.state[i] = movedCol.reverse();\n }\n\n this.addCellIfMoved();\n this.updateStatus();\n }\n\n moveUp() {\n const gameStatus = this.getStatus();\n\n if (gameStatus === 'idle' || gameStatus === 'lose') {\n return;\n }\n\n this.setPrevState();\n\n for (let rowIndex = 0; rowIndex < BOARD_SIZE; rowIndex++) {\n const row = this.getRow(rowIndex);\n const movedRow = this.moveLine(row);\n\n this.changeRow(movedRow, rowIndex);\n }\n\n this.addCellIfMoved();\n this.updateStatus();\n }\n\n moveDown() {\n const gameStatus = this.getStatus();\n\n if (gameStatus === 'idle' || gameStatus === 'lose') {\n return;\n }\n\n this.setPrevState();\n\n for (let rowIndex = 0; rowIndex < BOARD_SIZE; rowIndex++) {\n const row = this.getRow(rowIndex);\n const movedRow = this.moveLine(row.reverse());\n\n this.changeRow(movedRow.reverse(), rowIndex);\n }\n\n this.addCellIfMoved();\n this.updateStatus();\n }\n\n /**\n * @returns {number}\n */\n getScore() {\n return this.score;\n }\n\n updateScore(cellNumber) {\n this.score += cellNumber;\n }\n\n getLineSum(arr) {\n const sum = arr.reduce((a, b) => a + b, 0);\n\n return sum;\n }\n\n /**\n * @returns {number[][]}\n */\n getState() {\n return this.state;\n }\n\n getPrevState() {\n return this.prevState;\n }\n\n setPrevState() {\n this.prevState = this.copyState(this.state);\n }\n\n copyState(state) {\n return state.map(line => [...line]);\n }\n\n /**\n * Returns the current game status.\n *\n * @returns {string} One of: 'idle', 'playing', 'win', 'lose'\n *\n * `idle` - the game has not started yet (the initial state);\n * `playing` - the game is in progress;\n * `win` - the game is won;\n * `lose` - the game is lost\n */\n getStatus() {\n return this.status;\n }\n\n setStatus(newStatus) {\n this.status = newStatus;\n }\n\n /**\n * Starts the game.\n */\n start() {\n this.addRandomCell();\n this.addRandomCell();\n this.setStatus('playing');\n }\n\n /**\n * Resets the game.\n */\n restart() {\n this.state = this.copyState(this.initialState);\n this.score = 0;\n this.setStatus('idle');\n }\n\n getNewBoard() {\n return [...Array(BOARD_SIZE)].map(() => Array(BOARD_SIZE).fill(0));\n }\n\n addRandomCell() {\n const emptyCells = this.getEmptyCells();\n\n if (emptyCells.length !== 0) {\n const anyIndex = Math.floor(Math.random() * emptyCells.length);\n const anyPosition = emptyCells[anyIndex];\n const randomValue = Math.random() < 0.9 ? 2 : 4;\n\n this.state[anyPosition.rowIndex][anyPosition.colIndex] = randomValue;\n }\n }\n\n getEmptyCells() {\n const emptyCells = [];\n\n for (let rowIndex = 0; rowIndex < BOARD_SIZE; rowIndex++) {\n for (let colIndex = 0; colIndex < BOARD_SIZE; colIndex++) {\n const cell = this.state[rowIndex][colIndex];\n\n if (cell === 0) {\n emptyCells.push({\n rowIndex, colIndex,\n });\n }\n }\n }\n\n return emptyCells;\n }\n\n addCellIfMoved() {\n if (this.isMoved(this.getPrevState())) {\n this.addRandomCell();\n }\n }\n\n moveLine(lineArr) {\n const getOutZeroes = lineArr.filter(elem => elem !== 0);\n const newLine = getOutZeroes;\n\n for (let i = 0; i < newLine.length; i++) {\n const curr = newLine[i];\n const next = newLine[i + 1];\n\n if (curr === next) {\n const newCell = curr + next;\n\n newLine.splice(i, 1, newCell);\n newLine.splice(i + 1, 1);\n this.updateScore(curr + next);\n\n if (newCell === 2048) {\n this.isWin = true;\n }\n }\n }\n\n while (newLine.length !== BOARD_SIZE) {\n newLine.push(0);\n }\n\n return newLine;\n }\n\n getRow(rowIndex) {\n const row = [];\n\n for (let colIndex = 0; colIndex < BOARD_SIZE; colIndex++) {\n const col = this.state[colIndex];\n const elem = col[rowIndex];\n\n row.push(elem);\n }\n\n return row;\n }\n\n changeRow(rowToPlace, rowIndex) {\n for (let colIndex = 0; colIndex < BOARD_SIZE; colIndex++) {\n this.state[colIndex][rowIndex] = rowToPlace[colIndex];\n }\n }\n\n isMoved(prevState) {\n for (let r = 0; r < BOARD_SIZE; r++) {\n for (let c = 0; c < BOARD_SIZE; c++) {\n const prevCell = prevState[r][c];\n const currCell = this.state[r][c];\n\n if (prevCell !== currCell) {\n return true;\n }\n }\n }\n\n return false;\n }\n\n isLose() {\n for (let r = 0; r < BOARD_SIZE; r++) {\n for (let c = 0; c < BOARD_SIZE; c++) {\n const currCell = this.state[r][c];\n const nextCell = r + 1 < BOARD_SIZE ? this.state[r + 1][c] : -1;\n const bottomCell = c + 1 < BOARD_SIZE ? this.state[r][c + 1] : -1;\n\n const emptyCell = currCell === 0 || nextCell === 0 || bottomCell === 0;\n const areCellsEqual = currCell === nextCell | currCell === bottomCell;\n\n if (areCellsEqual || emptyCell) {\n return false;\n }\n }\n }\n\n return true;\n }\n\n updateStatus() {\n if (this.isLose()) {\n this.setStatus('lose');\n }\n\n if (this.isWin) {\n this.setStatus('win');\n }\n }\n\n drawBoard(cells) {\n this.state.forEach((row, rowIndex) => {\n row.forEach((colValue, colIndex) => {\n const calculateCellIndex = rowIndex * BOARD_SIZE + colIndex;\n const cell = cells[calculateCellIndex];\n\n if (colValue !== 0) {\n cell.textContent = colValue;\n cell.classList = `field-cell field-cell--${colValue}`;\n } else {\n cell.textContent = null;\n cell.classList = `field-cell`;\n }\n });\n });\n }\n}\n\nmodule.exports = Game;\n","export function _class_call_check(instance, Constructor) {\n if (!(instance instanceof Constructor)) throw new TypeError(\"Cannot call a class as a function\");\n}\nexport { _class_call_check as _ };\n","function _defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n\n if (\"value\" in descriptor) descriptor.writable = true;\n\n Object.defineProperty(target, descriptor.key, descriptor);\n }\n}\nexport function _create_class(Constructor, protoProps, staticProps) {\n if (protoProps) _defineProperties(Constructor.prototype, protoProps);\n if (staticProps) _defineProperties(Constructor, staticProps);\n\n return Constructor;\n}\nexport { _create_class as _ };\n","import { _array_without_holes } from \"./_array_without_holes.js\";\nimport { _iterable_to_array } from \"./_iterable_to_array.js\";\nimport { _non_iterable_spread } from \"./_non_iterable_spread.js\";\nimport { _unsupported_iterable_to_array } from \"./_unsupported_iterable_to_array.js\";\n\nexport function _to_consumable_array(arr) {\n return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();\n}\nexport { _to_consumable_array as _ };\n","import { _array_like_to_array } from \"./_array_like_to_array.js\";\n\nexport function _array_without_holes(arr) {\n if (Array.isArray(arr)) return _array_like_to_array(arr);\n}\nexport { _array_without_holes as _ };\n","export function _array_like_to_array(arr, len) {\n if (len == null || len > arr.length) len = arr.length;\n\n for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];\n\n return arr2;\n}\nexport { _array_like_to_array as _ };\n","export function _iterable_to_array(iter) {\n if (typeof Symbol !== \"undefined\" && iter[Symbol.iterator] != null || iter[\"@@iterator\"] != null) {\n return Array.from(iter);\n }\n}\nexport { _iterable_to_array as _ };\n","export function _non_iterable_spread() {\n throw new TypeError(\"Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\");\n}\nexport { _non_iterable_spread as _ };\n","import { _array_like_to_array } from \"./_array_like_to_array.js\";\n\nexport function _unsupported_iterable_to_array(o, minLen) {\n if (!o) return;\n if (typeof o === \"string\") return _array_like_to_array(o, minLen);\n\n var n = Object.prototype.toString.call(o).slice(8, -1);\n\n if (n === \"Object\" && o.constructor) n = o.constructor.name;\n if (n === \"Map\" || n === \"Set\") return Array.from(n);\n if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);\n}\nexport { _unsupported_iterable_to_array as _ };\n"],"names":["$4fc75ccb937ab1df$var$_defineProperties","target","props","i","length","descriptor","enumerable","configurable","writable","Object","defineProperty","key","$c3b10a83b523f372$export$79e617b1955a2616","arr","len","arr2","Array","$227c6742e0ff6f82$export$1b5e630bc3aea29f","isArray","iter","Symbol","iterator","from","o","minLen","n","prototype","toString","call","slice","constructor","name","test","TypeError","$197cd56b15c33885$var$game","protoProps","staticProps","Game","initialState","arguments","getNewBoard","instance","Constructor","state","copyState","prevState","status","score","isWin","console","log","value","gameStatus","getStatus","setPrevState","col","movedCol","moveLine","addCellIfMoved","updateStatus","reverse","rowIndex","row","getRow","movedRow","changeRow","cellNumber","reduce","a","b","map","line","newStatus","addRandomCell","setStatus","fill","emptyCells","getEmptyCells","anyIndex","Math","floor","random","anyPosition","colIndex","push","isMoved","getPrevState","lineArr","getOutZeroes","filter","elem","newLine","curr","next","newCell","splice","updateScore","rowToPlace","r","c","prevCell","currCell","nextCell","bottomCell","emptyCell","areCellsEqual","isLose","cells","forEach","colValue","cell","textContent","classList","concat","$197cd56b15c33885$var$gameKeys","$197cd56b15c33885$var$button","document","querySelector","$197cd56b15c33885$var$score","$197cd56b15c33885$var$messageStart","$197cd56b15c33885$var$messageLose","$197cd56b15c33885$var$messageWin","$197cd56b15c33885$var$cells","querySelectorAll","$197cd56b15c33885$var$defineMessage","remove","contains","add","addEventListener","start","toggle","restart","drawBoard","keeydown","includes","$197cd56b15c33885$var$defineMove","keydown","moveLeft","moveRight","moveUp","moveDown","getScore"],"version":3,"file":"index.40606d0b.js.map"} \ No newline at end of file diff --git a/index.6910ad39.css b/index.6910ad39.css new file mode 100644 index 000000000..3cd0f3b4d --- /dev/null +++ b/index.6910ad39.css @@ -0,0 +1,2 @@ +body{background:#fbf8ef;-ms-flex-pack:center;justify-content:center;-ms-flex-align:center;align-items:center;min-height:100vh;margin:0;font-family:sans-serif;font-size:24px;font-weight:900;display:-ms-flexbox;display:flex}.field-cell{color:#776e65;box-sizing:border-box;text-align:center;vertical-align:center;-webkit-user-select:none;-ms-user-select:none;user-select:none;background:#d6cdc4;border-radius:5px;width:75px;height:75px}.field-cell--2{background:#eee4da}.field-cell--4{background:#ede0c8}.field-cell--8{color:#f9f6f2;background:#f2b179}.field-cell--16{color:#f9f6f2;background:#f59563}.field-cell--32{color:#f9f6f2;background:#f67c5f}.field-cell--64{color:#f9f6f2;background:#f65e3b}.field-cell--128{color:#f9f6f2;background:#edcf72}.field-cell--256{color:#f9f6f2;background:#edcc61}.field-cell--512{color:#f9f6f2;background:#edc850}.field-cell--1024{color:#f9f6f2;background:#edc53f}.field-cell--2048{color:#f9f6f2;background:#edc22e}.game-field{border-spacing:10px;background:#bbada0;border-radius:5px}.game-header{box-sizing:border-box;-ms-flex-pack:justify;justify-content:space-between;width:100%;margin-bottom:24px;padding:10px;display:-ms-flexbox;display:flex}h1{color:#f9f6f2;box-sizing:border-box;background:#edc22e;border-radius:5px;-ms-flex-pack:center;justify-content:center;-ms-flex-align:center;align-items:center;width:75px;height:75px;margin:0;font-size:24px;display:-ms-flexbox;display:flex}.info{color:#776e65;box-sizing:border-box;background:#d6cdc4;border-radius:5px;-ms-flex-direction:column;flex-direction:column;-ms-flex-pack:center;justify-content:center;-ms-flex-align:center;align-items:center;width:75px;height:75px;margin:0 8px 0 0;font-size:16px;display:-ms-flexbox;display:flex}.controls{display:-ms-flexbox;display:flex}.button{cursor:pointer;color:#f9f6f2;border:none;border-radius:5px;width:75px;height:75px;font-family:sans-serif;font-size:16px;font-weight:700;transition:background .25s}.start{background:#1dae28;font-size:20px}.start:hover{background:#179921}.restart{background:#f1b2b2}.restart:hover{background:#f87474}.message{box-sizing:border-box;color:#776e65;text-align:center;background:#d6cdc4;border-radius:5px;width:100%;padding:10px;font-size:20px}.hidden{display:none}.container{-ms-flex-direction:column;flex-direction:column;-ms-flex-align:center;align-items:center;width:350px;display:-ms-flexbox;display:flex}.message-win{color:#f9f6f2;background:#edc22e}.message-container{width:100%;height:150px} +/*# sourceMappingURL=index.6910ad39.css.map */ diff --git a/index.6910ad39.css.map b/index.6910ad39.css.map new file mode 100644 index 000000000..747fdd5ba --- /dev/null +++ b/index.6910ad39.css.map @@ -0,0 +1 @@ +{"mappings":"ACAA,8NAYA,mNAWE,kCAIA,kCAIA,gDAKA,iDAKA,iDAKA,iDAKA,kDAKA,kDAKA,kDAKA,mDAKA,mDAMF,qEAMA,mKASA,iPAcA,4SAeA,2CAIA,2KAcA,yCAIE,gCAKF,4BAGE,kCAKF,2IAWA,qBAIA,iJAOA,8CAKA","sources":["index.6910ad39.css","src/styles/main.scss"],"sourcesContent":["body {\n background: #fbf8ef;\n -ms-flex-pack: center;\n justify-content: center;\n -ms-flex-align: center;\n align-items: center;\n min-height: 100vh;\n margin: 0;\n font-family: sans-serif;\n font-size: 24px;\n font-weight: 900;\n display: -ms-flexbox;\n display: flex;\n}\n\n.field-cell {\n color: #776e65;\n box-sizing: border-box;\n text-align: center;\n vertical-align: center;\n -webkit-user-select: none;\n -ms-user-select: none;\n user-select: none;\n background: #d6cdc4;\n border-radius: 5px;\n width: 75px;\n height: 75px;\n}\n\n.field-cell--2 {\n background: #eee4da;\n}\n\n.field-cell--4 {\n background: #ede0c8;\n}\n\n.field-cell--8 {\n color: #f9f6f2;\n background: #f2b179;\n}\n\n.field-cell--16 {\n color: #f9f6f2;\n background: #f59563;\n}\n\n.field-cell--32 {\n color: #f9f6f2;\n background: #f67c5f;\n}\n\n.field-cell--64 {\n color: #f9f6f2;\n background: #f65e3b;\n}\n\n.field-cell--128 {\n color: #f9f6f2;\n background: #edcf72;\n}\n\n.field-cell--256 {\n color: #f9f6f2;\n background: #edcc61;\n}\n\n.field-cell--512 {\n color: #f9f6f2;\n background: #edc850;\n}\n\n.field-cell--1024 {\n color: #f9f6f2;\n background: #edc53f;\n}\n\n.field-cell--2048 {\n color: #f9f6f2;\n background: #edc22e;\n}\n\n.game-field {\n border-spacing: 10px;\n background: #bbada0;\n border-radius: 5px;\n}\n\n.game-header {\n box-sizing: border-box;\n -ms-flex-pack: justify;\n justify-content: space-between;\n width: 100%;\n margin-bottom: 24px;\n padding: 10px;\n display: -ms-flexbox;\n display: flex;\n}\n\nh1 {\n color: #f9f6f2;\n box-sizing: border-box;\n background: #edc22e;\n border-radius: 5px;\n -ms-flex-pack: center;\n justify-content: center;\n -ms-flex-align: center;\n align-items: center;\n width: 75px;\n height: 75px;\n margin: 0;\n font-size: 24px;\n display: -ms-flexbox;\n display: flex;\n}\n\n.info {\n color: #776e65;\n box-sizing: border-box;\n background: #d6cdc4;\n border-radius: 5px;\n -ms-flex-direction: column;\n flex-direction: column;\n -ms-flex-pack: center;\n justify-content: center;\n -ms-flex-align: center;\n align-items: center;\n width: 75px;\n height: 75px;\n margin: 0 8px 0 0;\n font-size: 16px;\n display: -ms-flexbox;\n display: flex;\n}\n\n.controls {\n display: -ms-flexbox;\n display: flex;\n}\n\n.button {\n cursor: pointer;\n color: #f9f6f2;\n border: none;\n border-radius: 5px;\n width: 75px;\n height: 75px;\n font-family: sans-serif;\n font-size: 16px;\n font-weight: 700;\n transition: background .25s;\n}\n\n.start {\n background: #1dae28;\n font-size: 20px;\n}\n\n.start:hover {\n background: #179921;\n}\n\n.restart {\n background: #f1b2b2;\n}\n\n.restart:hover {\n background: #f87474;\n}\n\n.message {\n box-sizing: border-box;\n color: #776e65;\n text-align: center;\n background: #d6cdc4;\n border-radius: 5px;\n width: 100%;\n padding: 10px;\n font-size: 20px;\n}\n\n.hidden {\n display: none;\n}\n\n.container {\n -ms-flex-direction: column;\n flex-direction: column;\n -ms-flex-align: center;\n align-items: center;\n width: 350px;\n display: -ms-flexbox;\n display: flex;\n}\n\n.message-win {\n color: #f9f6f2;\n background: #edc22e;\n}\n\n.message-container {\n width: 100%;\n height: 150px;\n}\n\n/*# sourceMappingURL=index.6910ad39.css.map */\n","body {\n margin: 0;\n display: flex;\n align-items: center;\n justify-content: center;\n min-height: 100vh;\n background: #fbf8ef;\n font-family: sans-serif;\n font-size: 24px;\n font-weight: 900;\n}\n\n.field-cell {\n background: #d6cdc4;\n width: 75px;\n height: 75px;\n border-radius: 5px;\n color: #776e65;\n box-sizing: border-box;\n text-align: center;\n vertical-align: center;\n user-select: none;\n\n &--2 {\n background: #eee4da;\n }\n\n &--4 {\n background: #ede0c8;\n }\n\n &--8 {\n background: #f2b179;\n color: #f9f6f2;\n }\n\n &--16 {\n background: #f59563;\n color: #f9f6f2;\n }\n\n &--32 {\n background: #f67c5f;\n color: #f9f6f2;\n }\n\n &--64 {\n background: #f65e3b;\n color: #f9f6f2;\n }\n\n &--128 {\n background: #edcf72;\n color: #f9f6f2;\n }\n\n &--256 {\n background: #edcc61;\n color: #f9f6f2;\n }\n\n &--512 {\n background: #edc850;\n color: #f9f6f2;\n }\n\n &--1024 {\n background: #edc53f;\n color: #f9f6f2;\n }\n\n &--2048 {\n background: #edc22e;\n color: #f9f6f2;\n }\n}\n\n.game-field {\n background: #bbada0;\n border-spacing: 10px;\n border-radius: 5px;\n}\n\n.game-header {\n display: flex;\n width: 100%;\n justify-content: space-between;\n margin-bottom: 24px;\n padding: 10px;\n box-sizing: border-box;\n}\n\nh1 {\n background: #edc22e;\n color: #f9f6f2;\n width: 75px;\n height: 75px;\n font-size: 24px;\n border-radius: 5px;\n display: flex;\n align-items: center;\n justify-content: center;\n box-sizing: border-box;\n margin: 0;\n}\n\n.info {\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n background: #d6cdc4;\n width: 75px;\n height: 75px;\n border-radius: 5px;\n color: #776e65;\n box-sizing: border-box;\n font-size: 16px;\n margin: 0 8px 0 0;\n}\n\n.controls {\n display: flex;\n}\n\n.button {\n border: none;\n border-radius: 5px;\n cursor: pointer;\n color: #f9f6f2;\n font-family: sans-serif;\n font-weight: 700;\n font-size: 16px;\n width: 75px;\n height: 75px;\n\n transition: 0.25s ease background;\n}\n\n.start {\n background: #1dae28;\n font-size: 20px;\n\n &:hover {\n background: #179921;\n }\n}\n\n.restart {\n background: #f1b2b2;\n\n &:hover {\n background: #f87474;\n }\n}\n\n.message {\n box-sizing: border-box;\n width: 100%;\n background: #d6cdc4;\n color: #776e65;\n padding: 10px;\n text-align: center;\n border-radius: 5px;\n font-size: 20px;\n}\n\n.hidden {\n display: none;\n}\n\n.container {\n display: flex;\n flex-direction: column;\n align-items: center;\n width: 350px;\n}\n\n.message-win {\n background: #edc22e;\n color: #f9f6f2;\n}\n\n.message-container {\n width: 100%;\n height: 150px;\n}\n"],"names":[],"version":3,"file":"index.6910ad39.css.map"} \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 000000000..d8b784feb --- /dev/null +++ b/index.html @@ -0,0 +1 @@ +2048

2048

Score: 0

Press "Start" to begin game. Good luck!

\ No newline at end of file