Skip to content

Commit

Permalink
First production release.
Browse files Browse the repository at this point in the history
  • Loading branch information
Catz1301 committed Sep 16, 2023
1 parent 860fe91 commit b41cacf
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 68 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ if (isEditing) {
+ the modal buttons will be of a separate class. this will allow for no event handling.
+ the modal will have a function that will be called when clicked. it will check to see if click was in the bounds of the modal buttons. this will return to the modal the result of the button.
+ the modal buttons will have a function that will have a function called inBounds. this will check to see if the mouse is in the bounds of the button. this will return a boolean.
+ depending on the button returning true, the modal will set the status of the button. This can return to an async function that will do something with the result. maybe.
+ depending on the button returning true, the modal will set the status of the button. This can return to an async function that will do something with the result. maybe.
+ there should also be a button column at the right side of the screen. It will house the buttons for the editor. This will house the buttons for feedback and editing (share, save). It will allow us to add buttons easily in the future.
31 changes: 13 additions & 18 deletions Square.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Square {
this.holding = false;
this.lastSuccessfulPosX = x;
this.lastSuccessfulPosY = y;
this.side = Square.side;
}

static side = {
Expand Down Expand Up @@ -204,11 +205,21 @@ class Square {
rotateSquare(editing = false) {
if (this.lockRotation == false || editing == true) {
// shift all connectors to the right, and move the last connector to the first position.
var lastConnector = this.connectors[this.connectors.length - 1];
let lastConnector = this.connectors[this.connectors.length - 1];
for (var i = this.connectors.length - 1; i > 0; i--) {
this.connectors[i] = this.connectors[i - 1];
}
this.connectors[0] = lastConnector;
let lastSide = this.side[this.side.length - 1];
for (var i = this.side.length - 1; i > 0; i--) {
this.side[i] = this.side[i - 1];
}
this.side[0] = lastSide;
let lastSolvedSide = this.solvedSides[this.solvedSides.length - 1];
for (var i = this.solvedSides.length - 1; i > 0; i--) {
this.solvedSides[i] = this.solvedSides[i - 1];
}
this.solvedSides[0] = lastSolvedSide;
}

}
Expand Down Expand Up @@ -299,21 +310,7 @@ class Square {
if (squareAtReleasePos == undefined) {
emptySquare = true;
}
/* if (squareAtReleasePos.length != 0) {
for (let i = 0; i < squareAtReleasePos.length; i++) {
if (squareAtReleasePos[i].id == this.id) {
if (squareAtReleasePos.length == 1) // must be this square only, therefore is an empty square we're over
emptySquare = true;
doDebug ? console.log("%cthe square at " + x + ", " + y + " is the same as the square being released", "color: green; background-color: cobalt") : undefined;
continue;
} else {
doDebug ? console.log("%c%b", "color: orange", checkBoardForSquare(x, y)) : undefined;
// emptySquare = true;
}
}
} else {
emptySquare = true;
} */

if (emptySquare == true) {
this.x = floor((this.x + (gridCellSize / 2)) / gridCellSize) * gridCellSize;
this.y = floor((this.y + (gridCellSize / 2)) / gridCellSize) * gridCellSize;
Expand All @@ -330,8 +327,6 @@ class Square {
} else {
this.x = this.lastSuccessfulPosX;
this.y = this.lastSuccessfulPosY;
// this.gridX = floor(this.x / gridCellSize);
// this.gridY = floor(this.y / gridCellSize); // Remove after more successful testing
return {oldGridX, oldGridY, gridX: this.gridX, gridY: this.gridY, newSquare: undefined};
}
}
Expand Down
132 changes: 87 additions & 45 deletions board.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ function createEmptyBoard(width, height) {
* @param {Square[][]} board The board to draw
*/
function drawBoard(board) {
for (var x = 0; x < board.length; x++) {
for (var y = 0; y < board[x].length; y++) {
for (let x = 0; x < board.length; ++x) {
for (let y = 0; y < board[x].length; ++y) {
if (board[x][y] != undefined) {
// if (holdingSquare == undefined) {
// board[x][y].drawSquare();
Expand All @@ -70,9 +70,11 @@ function drawBoard(board) {
board[x][y].drawSquare(); // eventually only draw squares that are not being held, then draw the held square on top of the others.
if (doDebug) {
stroke(0);
strokeWeight(3);
fill(255, 0, 255);
circle(x * gridCellSize + (gridCellSize/2), y * gridCellSize + (gridCellSize/2), gridCellSize);
// strokeWeight(3);
fill(255);
textAlign(CENTER);
textSize(16);
text(board[x][y].id, board[x][y].x + gridCellSize / 2, board[x][y].y + 8 + gridCellSize / 2);
}
}
}
Expand All @@ -95,7 +97,18 @@ function checkBoardForSquare(mx, my, squareId) {
* @name square
* @type {Square}
*/
let square = undefined;
let squares = [];
let gridX = floor(mx / gridCellSize);
let gridY = floor(my / gridCellSize);
if (board[gridX][gridY] != undefined) {
if (board[gridX][gridY].id == squareId) {
return undefined;
} else {
return board[gridX][gridY];
}
} else {
return undefined;
}
for (var x = 0; x < board.length; x++) {
for(var y = 0; y < board[x].length; y++) {
if (board[x][y] == undefined) {
Expand All @@ -109,16 +122,16 @@ function checkBoardForSquare(mx, my, squareId) {
if (board[x][y].check(mx, my) && board[x][y].id != squareId) {
doDebug ? console.debug({status: "Square found, returning", squareAt}) : undefined;
squareFound = true;
square = board[x][y];
return square;
squares[squares.length] = board[x][y];
return squares;
}
else
continue;
}
};
};
doDebug ? console.debug("%c%o", "color: white, background-color: green, font-size: 16px;", square) : undefined;
return square;
doDebug ? console.debug("%c%o", "color: white, background-color: green, font-size: 16px;", squares) : undefined;
return squares;
}

/**
Expand Down Expand Up @@ -220,91 +233,119 @@ function attemptSolve() {
if (board[x][y] != null) {
board[x][y].color = color(255, 255, 0);
if (x == 0) {
board[x][y].solvedSides[Square.side.LEFT] = true;
board[x][y].solvedSides[board[x][y].side.LEFT] = true;
}
if (x == gridWidth - 1) {
board[x][y].solvedSides[Square.side.RIGHT] = true;
board[x][y].solvedSides[board[x][y].side.RIGHT] = true;
}
if (y == 0) {
board[x][y].solvedSides[Square.side.TOP] = true;
board[x][y].solvedSides[board[x][y].side.TOP] = true;
}
if (y == gridHeight - 1) {
board[x][y].solvedSides[Square.side.BOTTOM] = true;
board[x][y].solvedSides[board[x][y].side.BOTTOM] = true;
}
if (x != 0) {
if (board[x][y] != undefined && board[x - 1][y] != undefined) {
doDebug ? console.debug({status: "ConnectorTest", "Square": board[x][y], x,y, "Square Left Connectors": board[x][y].connectors[Square.side.LEFT], "Left Square Right Connector": board[x - 1][y].connectors[Square.side.RIGHT]}) : undefined;
if (board[x][y].connectors[Square.side.LEFT] == board[x - 1][y].connectors[Square.side.RIGHT]) {
board[x][y].solvedSides[Square.side.LEFT] = true;
board[x - 1][y].solvedSides[Square.side.RIGHT] = true;
doDebug ? console.debug({status: "ConnectorTest", "Square": board[x][y], x,y, "Square Left Connectors": board[x][y].connectors[board[x][y].side.LEFT], "Left Square Right Connector": board[x - 1][y].connectors[board[x][y].side.RIGHT]}) : undefined;
if (board[x][y].connectors[board[x][y].side.LEFT] == board[x - 1][y].connectors[board[x][y].side.RIGHT]) {
board[x][y].solvedSides[board[x][y].side.LEFT] = true;
board[x - 1][y].solvedSides[board[x][y].side.RIGHT] = true;
} else {
board[x][y].solvedSides[Square.side.LEFT] = false;
board[x - 1][y].solvedSides[Square.side.RIGHT] = false;
board[x][y].solvedSides[board[x][y].side.LEFT] = false;
board[x - 1][y].solvedSides[board[x][y].side.RIGHT] = false;
}
} else {
if (board[x][y] != undefined) {
board[x][y].solvedSides[board[x][y].side.LEFT] = false;
}
if (board[x - 1][y] != undefined) {
board[x - 1][y].solvedSides[board[x][y].side.RIGHT] = false;
}
}
}
if (x != gridWidth - 1) {
if (board[x][y] != undefined && board[x + 1][y] != undefined) {
doDebug ? console.debug({status: "ConnectorTest", "Square": board[x][y], x,y, "Square Right Connectors": board[x][y].connectors[Square.side.RIGHT], "Right Square Left Connector": board[x + 1][y].connectors[Square.side.LEFT]}) : undefined;
if (board[x][y].connectors[Square.side.RIGHT] == board[x + 1][y].connectors[Square.side.LEFT]) {
board[x][y].solvedSides[Square.side.RIGHT] = true;
board[x + 1][y].solvedSides[Square.side.LEFT] = true;
doDebug ? console.debug({status: "ConnectorTest", "Square": board[x][y], x,y, "Square Right Connectors": board[x][y].connectors[board[x][y].side.RIGHT], "Right Square Left Connector": board[x + 1][y].connectors[board[x][y].side.LEFT]}) : undefined;
if (board[x][y].connectors[board[x][y].side.RIGHT] == board[x + 1][y].connectors[board[x][y].side.LEFT]) {
board[x][y].solvedSides[board[x][y].side.RIGHT] = true;
board[x + 1][y].solvedSides[board[x][y].side.LEFT] = true;
} else {
board[x][y].solvedSides[Square.side.RIGHT] = false;
board[x + 1][y].solvedSides[Square.side.LEFT] = false;
board[x][y].solvedSides[board[x][y].side.RIGHT] = false;
board[x + 1][y].solvedSides[board[x][y].side.LEFT] = false;
}
} else {
if (board[x][y] != undefined) {
board[x][y].solvedSides[board[x][y].side.RIGHT] = false;
}
if (board[x + 1][y] != undefined) {
board[x + 1][y].solvedSides[board[x][y].side.LEFT] = false;
}
}
}
if (y != 0) {
if (board[x][y] != undefined && board[x][y - 1] != undefined) {
doDebug ? console.debug({status: "ConnectorTest", "Square": board[x][y], x,y, "Square Top Connectors": board[x][y].connectors[Square.side.TOP], "Top Square Bottom Connector": board[x][y - 1].connectors[Square.side.BOTTOM]}) : undefined;
if (board[x][y].connectors[Square.side.TOP] == board[x][y - 1].connectors[Square.side.BOTTOM]) {
board[x][y].solvedSides[Square.side.TOP] = true;
board[x][y - 1].solvedSides[Square.side.BOTTOM] = true;
doDebug ? console.debug({status: "ConnectorTest", "Square": board[x][y], x,y, "Square Top Connectors": board[x][y].connectors[board[x][y].side.TOP], "Top Square Bottom Connector": board[x][y - 1].connectors[board[x][y].side.BOTTOM]}) : undefined;
if (board[x][y].connectors[board[x][y].side.TOP] == board[x][y - 1].connectors[board[x][y].side.BOTTOM]) {
board[x][y].solvedSides[board[x][y].side.TOP] = true;
board[x][y - 1].solvedSides[board[x][y].side.BOTTOM] = true;
} else {
board[x][y].solvedSides[Square.side.TOP] = false;
board[x][y - 1].solvedSides[Square.side.BOTTOM] = false;
board[x][y].solvedSides[board[x][y].side.TOP] = false;
board[x][y - 1].solvedSides[board[x][y].side.BOTTOM] = false;
}
} else {
if (board[x][y] != undefined) {
board[x][y].solvedSides[board[x][y].side.TOP] = false;
}
if (board[x][y - 1] != undefined) {
board[x][y - 1].solvedSides[board[x][y].side.BOTTOM] = false;
}
}
}
if (y != gridHeight - 1) {
if (board[x][y] != undefined && board[x][y + 1] != undefined) {
doDebug ? console.debug({status: "ConnectorTest", "Square": board[x][y], x,y, "Square Bottom Connectors": board[x][y].connectors[Square.side.BOTTOM], "Bottom Square Top Connector": board[x][y + 1].connectors[Square.side.TOP]}) : undefined;
if (board[x][y].connectors[Square.side.BOTTOM] == board[x][y + 1].connectors[Square.side.TOP]) {
board[x][y].solvedSides[Square.side.BOTTOM] = true;
board[x][y + 1].solvedSides[Square.side.TOP] = true;
doDebug ? console.debug({status: "ConnectorTest", "Square": board[x][y], x,y, "Square Bottom Connectors": board[x][y].connectors[board[x][y].side.BOTTOM], "Bottom Square Top Connector": board[x][y + 1].connectors[board[x][y].side.TOP]}) : undefined;
if (board[x][y].connectors[board[x][y].side.BOTTOM] == board[x][y + 1].connectors[board[x][y].side.TOP]) {
board[x][y].solvedSides[board[x][y].side.BOTTOM] = true;
board[x][y + 1].solvedSides[board[x][y].side.TOP] = true;
} else {
board[x][y].solvedSides[Square.side.BOTTOM] = false;
board[x][y + 1].solvedSides[Square.side.TOP] = false;
board[x][y].solvedSides[board[x][y].side.BOTTOM] = false;
board[x][y + 1].solvedSides[board[x][y].side.TOP] = false;
}
} else {
if (board[x][y] != undefined) {
board[x][y].solvedSides[board[x][y].side.BOTTOM] = false;
}
if (board[x][y + 1] != undefined) {
board[x][y + 1].solvedSides[board[x][y].side.TOP] = false;
}
}
}
}
if (board[x][y] != undefined) {
if (board[x][y].connectors[0] == 0) {
board[x][y].solvedSides[Square.side.TOP] = true;
board[x][y].solvedSides[board[x][y].side.TOP] = true;
}
if (board[x][y].connectors[1] == 0) {
board[x][y].solvedSides[Square.side.RIGHT] = true;
board[x][y].solvedSides[board[x][y].side.RIGHT] = true;
}
if (board[x][y].connectors[2] == 0) {
board[x][y].solvedSides[Square.side.BOTTOM] = true;
board[x][y].solvedSides[board[x][y].side.BOTTOM] = true;
}
if (board[x][y].connectors[3] == 0) {
board[x][y].solvedSides[Square.side.LEFT] = true;
board[x][y].solvedSides[board[x][y].side.LEFT] = true;
}
}
// todo: Check out Montclair, CA. It looks beautiful.
let squareSolved = false;
if (board[x][y] != undefined) {
squareSolved = (board[x][y].solvedSides[Square.side.LEFT] && board[x][y].solvedSides[Square.side.RIGHT] && board[x][y].solvedSides[Square.side.TOP] && board[x][y].solvedSides[Square.side.BOTTOM]);
console.log("Square at " + x + ", " + y + " is solved: " + squareSolved)
squareSolved = (board[x][y].solvedSides[board[x][y].side.LEFT] && board[x][y].solvedSides[board[x][y].side.RIGHT] && board[x][y].solvedSides[board[x][y].side.TOP] && board[x][y].solvedSides[board[x][y].side.BOTTOM]);
doDebug ? console.log("Square at " + x + ", " + y + " is solved: " + squareSolved) : undefined;
}
if (squareSolved == false && board[x][y] != undefined) {
allSquaresSolved = false;
}
if (board[x][y] != undefined) {
if (board[x][y].solvedSides[Square.side.LEFT] == true && board[x][y].solvedSides[Square.side.RIGHT] == true && board[x][y].solvedSides[Square.side.TOP] == true && board[x][y].solvedSides[Square.side.BOTTOM] == true) {
if (board[x][y].solvedSides[board[x][y].side.LEFT] == true && board[x][y].solvedSides[board[x][y].side.RIGHT] == true && board[x][y].solvedSides[board[x][y].side.TOP] == true && board[x][y].solvedSides[board[x][y].side.BOTTOM] == true) {
board[x][y].color = color(255, 255, 0);
}
}
Expand All @@ -322,6 +363,7 @@ function attemptSolve() {
level++;
boardSet = false;
isFullScreen = false;
storeItem("level", level);
}
}, 1000);
};
Expand Down
1 change: 0 additions & 1 deletion editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ function readFile(inputFile) {
headerReader.read().then(function processData({done, value}) {
if (done) {
let headerData = byteDataToHexStr(headerDataRead[0]);
console.log(headerData);
doDebug ? console.debug({status: "Header read", headerDataRead, "header data": headerData}) : undefined;
if (headerData == "420690") {
console.log("File is a valid blox file.");
Expand Down
13 changes: 12 additions & 1 deletion events.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function mouseReleased() {
// holdingSquare.holding = false;
doDebug ? console.debug({"Code Location": "mouseReleased", status: "holdingSquare holding status reset", holdingSquare}) : undefined;
holdingSquareRelease = holdingSquare.release(mouseX, mouseY);
console.log(holdingSquareRelease)
doDebug ? console.log(holdingSquareRelease) : undefined;
// board[holdingSquareRelease.gridX][holdingSquareRelease.gridY] = board[holdingSquareRelease.oldGridX][holdingSquareRelease.oldGridY];
// board[holdingSquareRelease.oldGridX][holdingSquareRelease.oldGridY] = undefined;
holdingSquare = holdingSquareRelease.newSquare;
Expand Down Expand Up @@ -252,6 +252,17 @@ function keyTyped() {
if (key === 'r' || key === 'R') {
shuffleBoard();
}
if (key === '`') {
let confirmReset = confirm("Are you sure you want to reset all your progress? This will put you at level 0.");
if (confirmReset) {
level = -1;
clearBoard();
boardSet = false;
solved = false;
squareId = 0;
storeItem("level", 0);
}
}
}

/**
Expand Down
26 changes: 24 additions & 2 deletions sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ function draw() {
gridCellSize = floor(height / gridHeight);
gridSizesSet = true;
}
let savedLevel = getItem("level");
if (savedLevel != null) {
level = savedLevel;
} else {
storeItem("level", 0);
}
if (level != -1) {
if (level < boards.length) {
if (boardSet == false) {
Expand All @@ -92,16 +98,32 @@ function draw() {
}
}
}
if (boardSet == false) {
if (level < boards.length) {
setBoard(boards[level]);
boardSet = true;
} else {
alert("You have completed all the levels. Thank you for playing! Feel free to load in a blox file and play some custom levels. Or make your own levels and share them with your friends!");
}
}


if (boardSet == false) {
board = createBoard(gridWidth, gridHeight);
boardSet = true;
}
// console.log(board);
// checkForAnomolies(); // not needed now.
drawBoard(board);
if (doDebug) {
// draw the mouse x and y coordinates in the top left corner.
fill(255);
textSize(16);
text("Mouse X: " + mouseX + "\nMouse Y: " + mouseY, 10, 20);
}
if (enableFeedback)
drawFeedbackButton();
}
if (enableFeedback)
drawFeedbackButton();
}

// check the board to see if there is a square at the mouse position. If there is, return it. If not, return undefined.
Expand Down

0 comments on commit b41cacf

Please sign in to comment.