Comparing version 0.1.1 to 0.1.2
@@ -6,16 +6,16 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const board_1 = __importDefault(require("../board")); | ||
const EMPTY = board_1.default.EMPTY_SPACE; | ||
describe('2048', () => { | ||
describe('Moving the board right', () => { | ||
it('should do nothing with empty rows', () => { | ||
const board = new board_1.default(board_1.default.getEmptyBoard()); | ||
var board_1 = __importDefault(require("../board")); | ||
var EMPTY = board_1.default.EMPTY_SPACE; | ||
describe('2048', function () { | ||
describe('Moving the board right', function () { | ||
it('should do nothing with empty rows', function () { | ||
var board = new board_1.default(board_1.default.getEmptyBoard()); | ||
board.moveRight(); | ||
expect(board.getBoard()).toEqual(board_1.default.getEmptyBoard()); | ||
}); | ||
it('should move single number rows over to the edge', () => { | ||
const map = board_1.default.getEmptyBoard(); | ||
it('should move single number rows over to the edge', function () { | ||
var map = board_1.default.getEmptyBoard(); | ||
map[0][2] = 2; | ||
map[2][1] = 2; | ||
const board = new board_1.default(map); | ||
var board = new board_1.default(map); | ||
board.moveRight(); | ||
@@ -29,4 +29,4 @@ expect(board.getBoard()).toEqual([ | ||
}); | ||
it('should combine two of the same numbers together alone in a row', () => { | ||
const map = [ | ||
it('should combine two of the same numbers together alone in a row', function () { | ||
var map = [ | ||
[EMPTY, 2, 2, EMPTY], | ||
@@ -37,3 +37,3 @@ [EMPTY, EMPTY, 2, 2], | ||
]; | ||
const board = new board_1.default(map); | ||
var board = new board_1.default(map); | ||
board.moveRight(); | ||
@@ -47,4 +47,4 @@ expect(board.getBoard()).toEqual([ | ||
}); | ||
it('should combine two of the rightmost same numbers together but only two at a time', () => { | ||
const map = [ | ||
it('should combine two of the rightmost same numbers together but only two at a time', function () { | ||
var map = [ | ||
[EMPTY, 2, 2, 2], | ||
@@ -55,3 +55,3 @@ [EMPTY, EMPTY, EMPTY, EMPTY], | ||
]; | ||
const board = new board_1.default(map); | ||
var board = new board_1.default(map); | ||
board.moveRight(); | ||
@@ -65,4 +65,4 @@ expect(board.getBoard()).toEqual([ | ||
}); | ||
it('should just shift numbers if no matches', () => { | ||
const map = [ | ||
it('should just shift numbers if no matches', function () { | ||
var map = [ | ||
[4, EMPTY, 2, 4], | ||
@@ -73,3 +73,3 @@ [EMPTY, EMPTY, EMPTY, EMPTY], | ||
]; | ||
const board = new board_1.default(map); | ||
var board = new board_1.default(map); | ||
board.moveRight(); | ||
@@ -84,10 +84,10 @@ expect(board.getBoard()).toEqual([ | ||
}); | ||
describe('Moving the board left', () => { | ||
it('should do nothing with empty rows', () => { | ||
const board = new board_1.default(board_1.default.getEmptyBoard()); | ||
describe('Moving the board left', function () { | ||
it('should do nothing with empty rows', function () { | ||
var board = new board_1.default(board_1.default.getEmptyBoard()); | ||
board.moveLeft(); | ||
expect(board.getBoard()).toEqual(board_1.default.getEmptyBoard()); | ||
}); | ||
it('should move single number rows over to the edge', () => { | ||
const board = new board_1.default([ | ||
it('should move single number rows over to the edge', function () { | ||
var board = new board_1.default([ | ||
[EMPTY, 2, EMPTY, EMPTY], | ||
@@ -106,4 +106,4 @@ [EMPTY, EMPTY, EMPTY, EMPTY], | ||
}); | ||
it('should combine two of the same numbers together alone in a row', () => { | ||
const map = [ | ||
it('should combine two of the same numbers together alone in a row', function () { | ||
var map = [ | ||
[EMPTY, 2, 2, EMPTY], | ||
@@ -114,3 +114,3 @@ [EMPTY, EMPTY, 2, 2], | ||
]; | ||
const board = new board_1.default(map); | ||
var board = new board_1.default(map); | ||
board.moveLeft(); | ||
@@ -124,4 +124,4 @@ expect(board.getBoard()).toEqual([ | ||
}); | ||
it('should combine two of the leftmost same numbers together but only two at a time', () => { | ||
const map = [ | ||
it('should combine two of the leftmost same numbers together but only two at a time', function () { | ||
var map = [ | ||
[EMPTY, 2, 2, 2], | ||
@@ -132,3 +132,3 @@ [EMPTY, EMPTY, EMPTY, EMPTY], | ||
]; | ||
const board = new board_1.default(map); | ||
var board = new board_1.default(map); | ||
board.moveLeft(); | ||
@@ -142,4 +142,4 @@ expect(board.getBoard()).toEqual([ | ||
}); | ||
it('should just shift numbers if no matches', () => { | ||
const map = [ | ||
it('should just shift numbers if no matches', function () { | ||
var map = [ | ||
[4, EMPTY, 2, 4], | ||
@@ -150,3 +150,3 @@ [EMPTY, EMPTY, EMPTY, EMPTY], | ||
]; | ||
const board = new board_1.default(map); | ||
var board = new board_1.default(map); | ||
board.moveLeft(); | ||
@@ -161,10 +161,10 @@ expect(board.getBoard()).toEqual([ | ||
}); | ||
describe('Moving the board up', () => { | ||
it('should do nothing with empty rows', () => { | ||
const board = new board_1.default(board_1.default.getEmptyBoard()); | ||
describe('Moving the board up', function () { | ||
it('should do nothing with empty rows', function () { | ||
var board = new board_1.default(board_1.default.getEmptyBoard()); | ||
board.moveUp(); | ||
expect(board.getBoard()).toEqual(board_1.default.getEmptyBoard()); | ||
}); | ||
it('should move single number rows over to the edge', () => { | ||
const board = new board_1.default([ | ||
it('should move single number rows over to the edge', function () { | ||
var board = new board_1.default([ | ||
[EMPTY, 2, EMPTY, EMPTY], | ||
@@ -183,4 +183,4 @@ [EMPTY, EMPTY, EMPTY, EMPTY], | ||
}); | ||
it('should combine two of the same numbers together alone in a column', () => { | ||
const map = [ | ||
it('should combine two of the same numbers together alone in a column', function () { | ||
var map = [ | ||
[EMPTY, 2, EMPTY, 4], | ||
@@ -191,3 +191,3 @@ [EMPTY, 2, EMPTY, EMPTY], | ||
]; | ||
const board = new board_1.default(map); | ||
var board = new board_1.default(map); | ||
board.moveUp(); | ||
@@ -201,4 +201,4 @@ expect(board.getBoard()).toEqual([ | ||
}); | ||
it('should combine two of the topmost same numbers together but only two at a time', () => { | ||
const map = [ | ||
it('should combine two of the topmost same numbers together but only two at a time', function () { | ||
var map = [ | ||
[EMPTY, 2, 4, EMPTY], | ||
@@ -209,3 +209,3 @@ [EMPTY, 2, 4, EMPTY], | ||
]; | ||
const board = new board_1.default(map); | ||
var board = new board_1.default(map); | ||
board.moveUp(); | ||
@@ -219,4 +219,4 @@ expect(board.getBoard()).toEqual([ | ||
}); | ||
it('should just shift numbers if no matches', () => { | ||
const map = [ | ||
it('should just shift numbers if no matches', function () { | ||
var map = [ | ||
[EMPTY, 4, EMPTY, EMPTY], | ||
@@ -227,3 +227,3 @@ [EMPTY, EMPTY, EMPTY, 2], | ||
]; | ||
const board = new board_1.default(map); | ||
var board = new board_1.default(map); | ||
board.moveUp(); | ||
@@ -238,10 +238,10 @@ expect(board.getBoard()).toEqual([ | ||
}); | ||
describe('Moving the board down', () => { | ||
it('should do nothing with empty rows', () => { | ||
const board = new board_1.default(board_1.default.getEmptyBoard()); | ||
describe('Moving the board down', function () { | ||
it('should do nothing with empty rows', function () { | ||
var board = new board_1.default(board_1.default.getEmptyBoard()); | ||
board.moveDown(); | ||
expect(board.getBoard()).toEqual(board_1.default.getEmptyBoard()); | ||
}); | ||
it('should move single number rows over to the edge', () => { | ||
const board = new board_1.default([ | ||
it('should move single number rows over to the edge', function () { | ||
var board = new board_1.default([ | ||
[EMPTY, 2, EMPTY, EMPTY], | ||
@@ -260,4 +260,4 @@ [EMPTY, EMPTY, EMPTY, EMPTY], | ||
}); | ||
it('should combine two of the same numbers together alone in a column', () => { | ||
const map = [ | ||
it('should combine two of the same numbers together alone in a column', function () { | ||
var map = [ | ||
[EMPTY, 2, EMPTY, 4], | ||
@@ -268,3 +268,3 @@ [EMPTY, 2, EMPTY, EMPTY], | ||
]; | ||
const board = new board_1.default(map); | ||
var board = new board_1.default(map); | ||
board.moveDown(); | ||
@@ -278,4 +278,4 @@ expect(board.getBoard()).toEqual([ | ||
}); | ||
it('should combine two of the bottommost same numbers together but only two at a time', () => { | ||
const map = [ | ||
it('should combine two of the bottommost same numbers together but only two at a time', function () { | ||
var map = [ | ||
[EMPTY, 2, 4, EMPTY], | ||
@@ -286,3 +286,3 @@ [EMPTY, 2, 4, EMPTY], | ||
]; | ||
const board = new board_1.default(map); | ||
var board = new board_1.default(map); | ||
board.moveDown(); | ||
@@ -296,4 +296,4 @@ expect(board.getBoard()).toEqual([ | ||
}); | ||
it('should just shift numbers if no matches', () => { | ||
const map = [ | ||
it('should just shift numbers if no matches', function () { | ||
var map = [ | ||
[EMPTY, 4, EMPTY, EMPTY], | ||
@@ -304,3 +304,3 @@ [EMPTY, EMPTY, EMPTY, 2], | ||
]; | ||
const board = new board_1.default(map); | ||
var board = new board_1.default(map); | ||
board.moveDown(); | ||
@@ -315,5 +315,5 @@ expect(board.getBoard()).toEqual([ | ||
}); | ||
describe('canMove', () => { | ||
it('should return true, many empty spaces', () => { | ||
const board = new board_1.default([ | ||
describe('canMove', function () { | ||
it('should return true, many empty spaces', function () { | ||
var board = new board_1.default([ | ||
[EMPTY, EMPTY, EMPTY, EMPTY], | ||
@@ -326,4 +326,4 @@ [EMPTY, EMPTY, 4, EMPTY], | ||
}); | ||
it('should return true, all spaces full but similar number is to the left or right', () => { | ||
const board = new board_1.default([ | ||
it('should return true, all spaces full but similar number is to the left or right', function () { | ||
var board = new board_1.default([ | ||
[2, 4, 8, 16], | ||
@@ -336,4 +336,4 @@ [4, 2, 4, 2], | ||
}); | ||
it('should return true, all spaces full but similar number is above or below', () => { | ||
const board = new board_1.default([ | ||
it('should return true, all spaces full but similar number is above or below', function () { | ||
var board = new board_1.default([ | ||
[2, 4, 8, 16], | ||
@@ -346,4 +346,4 @@ [4, 32, 4, 2], | ||
}); | ||
it('should return false, no similar numbers or empty spaces', () => { | ||
const board = new board_1.default([ | ||
it('should return false, no similar numbers or empty spaces', function () { | ||
var board = new board_1.default([ | ||
[2, 4, 8, 16], | ||
@@ -350,0 +350,0 @@ [4, 16, 4, 2], |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const util_1 = require("../util"); | ||
describe('Utilities', () => { | ||
describe('rotate 2d array left', () => { | ||
it('Should rotate a 2d array left', () => { | ||
var util_1 = require("../util"); | ||
describe('Utilities', function () { | ||
describe('rotate 2d array left', function () { | ||
it('Should rotate a 2d array left', function () { | ||
expect(util_1.rotateLeft([ | ||
@@ -20,4 +20,4 @@ [1, 2, 3, 4], | ||
}); | ||
describe('rotate 2d array right', () => { | ||
it('Should rotate a 2d array right', () => { | ||
describe('rotate 2d array right', function () { | ||
it('Should rotate a 2d array right', function () { | ||
expect(util_1.rotateRight([ | ||
@@ -24,0 +24,0 @@ [1, 2, 3, 4], |
@@ -25,9 +25,9 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const react_1 = __importStar(require("react")); | ||
const ink_1 = require("ink"); | ||
const board_1 = __importDefault(require("./board")); | ||
const game_1 = __importDefault(require("./game")); | ||
const game = new game_1.default(); | ||
var react_1 = __importStar(require("react")); | ||
var ink_1 = require("ink"); | ||
var board_1 = __importDefault(require("./board")); | ||
var game_1 = __importDefault(require("./game")); | ||
var game = new game_1.default(); | ||
game.reset(); | ||
const COLOR_MAP = { | ||
var COLOR_MAP = { | ||
2: 'cyan', | ||
@@ -47,4 +47,4 @@ 4: 'cyanBright', | ||
function App() { | ||
const [map, setMap] = react_1.useState(game.board.getBoard()); | ||
ink_1.useInput((input, key) => { | ||
var _a = react_1.useState(game.board.getBoard()), map = _a[0], setMap = _a[1]; | ||
ink_1.useInput(function (input, key) { | ||
if (input === 'q') { | ||
@@ -75,11 +75,12 @@ return process.exit(0); | ||
'Use arrow keys to move board', | ||
] }, item => react_1.default.createElement(ink_1.Text, { key: item }, item)), | ||
react_1.default.createElement(ink_1.Box, { marginTop: 2, flexDirection: 'column', alignItems: 'stretch' }, map.map((row, y) => (react_1.default.createElement(ink_1.Box, { key: y, flexDirection: 'row', alignItems: 'stretch' }, row.map((col, x) => (react_1.default.createElement(ink_1.Box, { key: x, width: 12, height: 6, borderColor: 'white', borderStyle: 'classic', display: 'flex', justifyContent: 'center', alignItems: 'center' }, (() => { | ||
] }, function (item) { return react_1.default.createElement(ink_1.Text, { key: item }, item); }), | ||
react_1.default.createElement(ink_1.Box, { marginTop: 2, flexDirection: 'column', alignItems: 'stretch' }, map.map(function (row, y) { return (react_1.default.createElement(ink_1.Box, { key: y, flexDirection: 'row', alignItems: 'stretch' }, row.map(function (col, x) { return (react_1.default.createElement(ink_1.Box, { key: x, width: 12, height: 6, borderColor: 'white', borderStyle: 'classic', display: 'flex', justifyContent: 'center', alignItems: 'center' }, (function () { | ||
var _a; | ||
if (col === board_1.default.EMPTY_SPACE) { | ||
return react_1.default.createElement(ink_1.Text, null, "-"); | ||
} | ||
return react_1.default.createElement(ink_1.Text, { color: COLOR_MAP[col] ?? 'white' }, col); | ||
})()))))))))); | ||
return react_1.default.createElement(ink_1.Text, { color: (_a = COLOR_MAP[col]) !== null && _a !== void 0 ? _a : 'white' }, col); | ||
})())); }))); })))); | ||
} | ||
exports.default = App; | ||
//# sourceMappingURL=app.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const util_1 = require("./util"); | ||
var util_1 = require("./util"); | ||
// inclusive | ||
@@ -8,8 +8,8 @@ function randomInteger(min, max) { | ||
} | ||
class Board { | ||
constructor(initialBoard) { | ||
this.board = initialBoard ?? Board.getEmptyBoard(); | ||
var Board = /** @class */ (function () { | ||
function Board(initialBoard) { | ||
this.board = initialBoard !== null && initialBoard !== void 0 ? initialBoard : Board.getEmptyBoard(); | ||
} | ||
static getEmptyBoard() { | ||
const { EMPTY_SPACE: EMPTY } = Board; | ||
Board.getEmptyBoard = function () { | ||
var EMPTY = Board.EMPTY_SPACE; | ||
return [ | ||
@@ -21,16 +21,16 @@ [EMPTY, EMPTY, EMPTY, EMPTY], | ||
]; | ||
} | ||
static getInitialBoard() { | ||
}; | ||
Board.getInitialBoard = function () { | ||
// todo ensure coords dont overlap | ||
const x1 = randomInteger(0, 3); | ||
const y1 = randomInteger(0, 3); | ||
const x2 = randomInteger(0, 3); | ||
const y2 = randomInteger(0, 3); | ||
const board = Board.getEmptyBoard(); | ||
var x1 = randomInteger(0, 3); | ||
var y1 = randomInteger(0, 3); | ||
var x2 = randomInteger(0, 3); | ||
var y2 = randomInteger(0, 3); | ||
var board = Board.getEmptyBoard(); | ||
board[y1][x1] = Math.random() > 0.75 ? 4 : 2; | ||
board[y2][x2] = Math.random() > 0.75 ? 4 : 2; | ||
return board; | ||
} | ||
moveUp() { | ||
let newBoard = util_1.rotateLeft(this.board); | ||
}; | ||
Board.prototype.moveUp = function () { | ||
var newBoard = util_1.rotateLeft(this.board); | ||
newBoard = this.shiftLeft(newBoard); | ||
@@ -40,5 +40,5 @@ newBoard = util_1.rotateRight(newBoard); | ||
return this; | ||
} | ||
moveDown() { | ||
let newBoard = util_1.rotateLeft(this.board); | ||
}; | ||
Board.prototype.moveDown = function () { | ||
var newBoard = util_1.rotateLeft(this.board); | ||
newBoard = this.shiftRight(newBoard); | ||
@@ -48,16 +48,17 @@ newBoard = util_1.rotateRight(newBoard); | ||
return this; | ||
} | ||
moveLeft() { | ||
}; | ||
Board.prototype.moveLeft = function () { | ||
this.board = this.shiftLeft(this.board); | ||
return this; | ||
} | ||
moveRight() { | ||
}; | ||
Board.prototype.moveRight = function () { | ||
this.board = this.shiftRight(this.board); | ||
return this; | ||
} | ||
canMove() { | ||
}; | ||
Board.prototype.canMove = function () { | ||
var _a, _b, _c, _d; | ||
// check if any spaces null | ||
for (let y = 0; y < this.board.length; y++) { | ||
const row = this.board[y]; | ||
for (let x = 0; x < row.length; x++) { | ||
for (var y = 0; y < this.board.length; y++) { | ||
var row = this.board[y]; | ||
for (var x = 0; x < row.length; x++) { | ||
if (row[x] === Board.EMPTY_SPACE) { | ||
@@ -69,11 +70,11 @@ return true; | ||
// check if any direction has same number | ||
for (let y = 0; y < this.board.length; y++) { | ||
const row = this.board[y]; | ||
for (let x = 0; x < row.length; x++) { | ||
const cell = row[x]; | ||
const surroundingCells = [ | ||
row?.[x + 1], | ||
row?.[x - 1], | ||
this.board?.[y - 1]?.[x], | ||
this.board?.[y + 1]?.[x], | ||
for (var y = 0; y < this.board.length; y++) { | ||
var row = this.board[y]; | ||
for (var x = 0; x < row.length; x++) { | ||
var cell = row[x]; | ||
var surroundingCells = [ | ||
row === null || row === void 0 ? void 0 : row[x + 1], | ||
row === null || row === void 0 ? void 0 : row[x - 1], | ||
(_b = (_a = this.board) === null || _a === void 0 ? void 0 : _a[y - 1]) === null || _b === void 0 ? void 0 : _b[x], | ||
(_d = (_c = this.board) === null || _c === void 0 ? void 0 : _c[y + 1]) === null || _d === void 0 ? void 0 : _d[x], | ||
]; | ||
@@ -86,10 +87,10 @@ if (surroundingCells.includes(cell)) { | ||
return false; | ||
} | ||
getBoard() { | ||
}; | ||
Board.prototype.getBoard = function () { | ||
return this.board; | ||
} | ||
spawnNumber() { | ||
const emptySpaces = []; | ||
for (let y = 0; y < this.board.length; y++) { | ||
for (let x = 0; x < this.board[y].length; x++) { | ||
}; | ||
Board.prototype.spawnNumber = function () { | ||
var emptySpaces = []; | ||
for (var y = 0; y < this.board.length; y++) { | ||
for (var x = 0; x < this.board[y].length; x++) { | ||
if (this.board[y][x] === Board.EMPTY_SPACE) { | ||
@@ -103,16 +104,16 @@ emptySpaces.push([y, x]); | ||
} | ||
const [newY, newX] = emptySpaces[Math.floor(Math.random() * emptySpaces.length)]; | ||
const numberToSpawn = Math.random() > 0.75 ? 4 : 2; | ||
var _a = emptySpaces[Math.floor(Math.random() * emptySpaces.length)], newY = _a[0], newX = _a[1]; | ||
var numberToSpawn = Math.random() > 0.75 ? 4 : 2; | ||
this.board[newY][newX] = numberToSpawn; | ||
return this; | ||
} | ||
shiftLeft(arr) { | ||
const newBoard = []; | ||
for (let y = 0; y < arr.length; y++) { | ||
const row = arr[y]; | ||
const nonEmpty = row.filter(cell => cell !== Board.EMPTY_SPACE); | ||
const newRow = []; | ||
for (let i = 0; i < nonEmpty.length; i++) { | ||
const currentCell = nonEmpty[i]; | ||
const nextCell = nonEmpty[i + 1]; | ||
}; | ||
Board.prototype.shiftLeft = function (arr) { | ||
var newBoard = []; | ||
for (var y = 0; y < arr.length; y++) { | ||
var row = arr[y]; | ||
var nonEmpty = row.filter(function (cell) { return cell !== Board.EMPTY_SPACE; }); | ||
var newRow = []; | ||
for (var i = 0; i < nonEmpty.length; i++) { | ||
var currentCell = nonEmpty[i]; | ||
var nextCell = nonEmpty[i + 1]; | ||
if (!currentCell) { | ||
@@ -133,3 +134,3 @@ continue; | ||
if (newRow.length !== row.length) { | ||
newRow.push(...Array.from({ length: row.length - newRow.length }).map(() => Board.EMPTY_SPACE)); | ||
newRow.push.apply(newRow, Array.from({ length: row.length - newRow.length }).map(function () { return Board.EMPTY_SPACE; })); | ||
} | ||
@@ -139,12 +140,12 @@ newBoard.push(newRow); | ||
return newBoard; | ||
} | ||
shiftRight(arr) { | ||
const newBoard = []; | ||
for (let y = 0; y < arr.length; y++) { | ||
const row = arr[y]; | ||
const nonEmpty = row.filter(cell => cell !== Board.EMPTY_SPACE); | ||
const newRow = []; | ||
for (let i = nonEmpty.length - 1; i >= 0; i--) { | ||
const currentCell = nonEmpty[i]; | ||
const prevCell = nonEmpty[i - 1]; | ||
}; | ||
Board.prototype.shiftRight = function (arr) { | ||
var newBoard = []; | ||
for (var y = 0; y < arr.length; y++) { | ||
var row = arr[y]; | ||
var nonEmpty = row.filter(function (cell) { return cell !== Board.EMPTY_SPACE; }); | ||
var newRow = []; | ||
for (var i = nonEmpty.length - 1; i >= 0; i--) { | ||
var currentCell = nonEmpty[i]; | ||
var prevCell = nonEmpty[i - 1]; | ||
if (!currentCell) { | ||
@@ -165,3 +166,3 @@ continue; | ||
if (newRow.length !== row.length) { | ||
newRow.unshift(...Array.from({ length: row.length - newRow.length }).map(() => Board.EMPTY_SPACE)); | ||
newRow.unshift.apply(newRow, Array.from({ length: row.length - newRow.length }).map(function () { return Board.EMPTY_SPACE; })); | ||
} | ||
@@ -171,6 +172,7 @@ newBoard.push(newRow); | ||
return newBoard; | ||
} | ||
} | ||
}; | ||
Board.EMPTY_SPACE = null; | ||
return Board; | ||
}()); | ||
exports.default = Board; | ||
Board.EMPTY_SPACE = null; | ||
//# sourceMappingURL=board.js.map |
@@ -7,6 +7,6 @@ #!/usr/bin/env node | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const react_1 = __importDefault(require("react")); | ||
const ink_1 = require("ink"); | ||
const app_1 = __importDefault(require("./app")); | ||
var react_1 = __importDefault(require("react")); | ||
var ink_1 = require("ink"); | ||
var app_1 = __importDefault(require("./app")); | ||
ink_1.render(react_1.default.createElement(app_1.default, null)); | ||
//# sourceMappingURL=cli.js.map |
"use strict"; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -6,25 +13,29 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const board_1 = __importDefault(require("./board")); | ||
class Game { | ||
constructor(board) { | ||
this.board = board ?? new board_1.default(); | ||
var board_1 = __importDefault(require("./board")); | ||
var Game = /** @class */ (function () { | ||
function Game(board) { | ||
this.board = board !== null && board !== void 0 ? board : new board_1.default(); | ||
} | ||
reset() { | ||
Game.prototype.reset = function () { | ||
this.board = new board_1.default(board_1.default.getInitialBoard()); | ||
return this; | ||
} | ||
moveRight() { | ||
return this.move(() => this.board.moveRight()); | ||
} | ||
moveLeft() { | ||
return this.move(() => this.board.moveLeft()); | ||
} | ||
moveUp() { | ||
return this.move(() => this.board.moveUp()); | ||
} | ||
moveDown() { | ||
return this.move(() => this.board.moveDown()); | ||
} | ||
move(move) { | ||
const oldBoard = [...this.board.getBoard()]; | ||
}; | ||
Game.prototype.moveRight = function () { | ||
var _this = this; | ||
return this.move(function () { return _this.board.moveRight(); }); | ||
}; | ||
Game.prototype.moveLeft = function () { | ||
var _this = this; | ||
return this.move(function () { return _this.board.moveLeft(); }); | ||
}; | ||
Game.prototype.moveUp = function () { | ||
var _this = this; | ||
return this.move(function () { return _this.board.moveUp(); }); | ||
}; | ||
Game.prototype.moveDown = function () { | ||
var _this = this; | ||
return this.move(function () { return _this.board.moveDown(); }); | ||
}; | ||
Game.prototype.move = function (move) { | ||
var oldBoard = __spreadArrays(this.board.getBoard()); | ||
move(); | ||
@@ -35,15 +46,15 @@ if (!this.isSameBoard(oldBoard, this.board.getBoard())) { | ||
return this; | ||
} | ||
isGameOver() { | ||
}; | ||
Game.prototype.isGameOver = function () { | ||
return !this.board.canMove(); | ||
} | ||
isSameBoard(arr1, arr2) { | ||
}; | ||
Game.prototype.isSameBoard = function (arr1, arr2) { | ||
if (arr1.length !== arr2.length) { | ||
return false; | ||
} | ||
for (let y = 0; y < arr1.length; y++) { | ||
for (var y = 0; y < arr1.length; y++) { | ||
if (arr1[y].length !== arr2[y].length) { | ||
return false; | ||
} | ||
for (let x = 0; x < arr1[y].length; x++) { | ||
for (var x = 0; x < arr1[y].length; x++) { | ||
if (arr1[y][x] !== arr2[y][x]) { | ||
@@ -55,5 +66,6 @@ return false; | ||
return true; | ||
} | ||
} | ||
}; | ||
return Game; | ||
}()); | ||
exports.default = Game; | ||
//# sourceMappingURL=game.js.map |
@@ -10,8 +10,8 @@ "use strict"; | ||
function rotateLeft(arr) { | ||
const newArr = Array.from({ length: arr.length }).map(() => []); | ||
const numRows = arr.length; | ||
for (let y = 0; y < numRows; y++) { | ||
const row = arr[y]; | ||
const numCols = row.length; | ||
for (let x = 0; x < numCols; x++) { | ||
var newArr = Array.from({ length: arr.length }).map(function () { return []; }); | ||
var numRows = arr.length; | ||
for (var y = 0; y < numRows; y++) { | ||
var row = arr[y]; | ||
var numCols = row.length; | ||
for (var x = 0; x < numCols; x++) { | ||
newArr[numRows - 1 - x][y] = arr[y][x]; | ||
@@ -29,8 +29,8 @@ } | ||
function rotateRight(arr) { | ||
const newArr = Array.from({ length: arr.length }).map(() => []); | ||
const numRows = arr.length; | ||
for (let y = 0; y < numRows; y++) { | ||
const row = arr[y]; | ||
const numCols = row.length; | ||
for (let x = 0; x < numCols; x++) { | ||
var newArr = Array.from({ length: arr.length }).map(function () { return []; }); | ||
var numRows = arr.length; | ||
for (var y = 0; y < numRows; y++) { | ||
var row = arr[y]; | ||
var numCols = row.length; | ||
for (var x = 0; x < numCols; x++) { | ||
newArr[x][numRows - 1 - y] = arr[y][x]; | ||
@@ -37,0 +37,0 @@ } |
{ | ||
"name": "2048-cli", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Play 2048 in your terminal", | ||
@@ -5,0 +5,0 @@ "main": "dist/cli.js", |
@@ -7,3 +7,3 @@ { | ||
// "incremental": true, /* Enable incremental compilation */ | ||
"target": "ESNext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ | ||
"target": "ES5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ | ||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ | ||
@@ -10,0 +10,0 @@ "lib": ["ESNext"], /* Specify library files to be included in the compilation. */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
397445
1619