/*********************************************************************************** puzzle.js puzzle class holds the following puzzle information: -width - of puzzle -height - of puzzle -coordinate of top left of puzzle on canvas -puzzle dimensions (rows, cols, and number of pieces) -puzzle image -width/height of piece -tolerance - allowance for snapping pieces into place -drawPriority of pieces -clicked - index of clicked piece (or -1 if none) -connectedPieces - pieces connected to currently clicked piece -offsetX & offsetY - difference btwn where click is taking place from top left of piece -drag - boolean indicating whether using drag/drop or click/release -backgroundColor - light or dark background -edgeOnly - boolean indicating whether puzzle is currently showing all pieces or only edge pieces. -ghostImage - boolean for whether translucent puzzle image is shown -fullscreen - boolean for whether puzzle is in fullscreen mode ***********************************************************************************/ class Puzzle { constructor(width, height, x, y, numRows, numCols, image) { this.width = width; this.height = height; this.x = x; this.y = y; this.numRows = numRows; this.numCols = numCols; this.numPieces = numRows * numCols; this.image = image; this.pieces = []; this.connectedPieces = []; this.pieceW = this.width / this.numCols; this.pieceH = this.height / this.numRows; // keeps track of current status this.clicked = -1; this.tolerance = 20; this.offsetX = 0; this.offsetY = 0; this.drag = true; this.drawPriority = []; // start with priority in order of indeces for (let i = 0; i < this.numPieces; i++) { this.drawPriority[i] = i; } // booleans for button elements of app this.backgroundColor = "dark"; this.ghostImage = false; this.edgeOnly = false; this.fullscreen = false; } get fullscreen() { return this._fullscreen; } set fullscreen(fullscreen) { this._fullscreen = fullscreen; } get edgeOnly() { return this._edgeOnly; } set edgeOnly(edgeOnly) { this._edgeOnly = edgeOnly; } get ghostImage() { return this._ghostImage; } set ghostImage(ghostImage) { this._ghostImage = ghostImage; } get backgroundColor() { return this._backgroundColor; } set backgroundColor(backgroundColor) { this._backgroundColor = backgroundColor; } get pieces() { return this._pieces; } set pieces(pieces) { this._pieces = pieces; } get connectedPieces() { return this._connectedPieces; } set connectedPieces(connectedPieces) { this._connectedPieces = connectedPieces; } get offsetX() { return this._offsetX; } set offsetX(x) { this._offsetX = x; } get offsetY() { return this._offsetY; } set offsetY(y) { this._offsetY = y; } get drag() { return this._drag; } set drag(val) { this._drag = val; } get width() { return this._width; } set width(w) { this._width = w; } get height() { return this._height; } set height(h) { this._height = h; } get numPieces() { return this._numPieces; } set numPieces(num) { this._numPieces = num; } get numCols() { return this._numCols; } set numCols(num) { this._numCols = num; } get numRows() { return this._numRows; } set numRows(num) { this._numRows = num; } get x() { return this._x; } set x(x) { this._x = x; } get y() { return this._y; } set y(y) { this._y = y; } get image() { return this._image; } set image(img) { this._image = img; } get clicked() { return this._clicked; } set clicked(val) { this._clicked = val; } get tolerance() { return this._tolerance; } set tolerance(val) { this._tolerance = val; } get drawPriority() { return this._drawPriority; } set drawPriority(val) { this._drawPriority = val; } get pieceW() { return this._pieceW; } set pieceW(val) { this._pieceW = val; } get pieceH() { return this._pieceH; } set pieceH(val) { this._pieceH = val; } /*********************************************************************** complete - checks if puzzle is completed Returns: boolean value ************************************************************************/ complete() { console.log("Entering - complete"); for (let i = 0; i < this.numPieces; i++) { if (this.pieces[i].correct == 0) { return false; } } return true; }; }