Skip to content

Commit

Permalink
done basic staff šŸ” - v1
Browse files Browse the repository at this point in the history
  • Loading branch information
khyrulAlam committed Apr 20, 2019
1 parent 471a76e commit 7366f5c
Show file tree
Hide file tree
Showing 17 changed files with 209 additions and 20,264 deletions.
78 changes: 64 additions & 14 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ let __puzzle = document.querySelector(".puzzle");
const possLetter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
let __resultState = [];
let __stateFlatten = [];
let __rowSize = 3;
let __columnSize = 3;
let __rowSize = 0;
let __columnSize = 0;

// create puzzle array
const randomPuzzle = () => {
__resultState = [];
__stateFlatten = [];
for (i = 0; i < __rowSize; i++) {
__resultState[i] = [];
for (j = 0; j < __columnSize; j++) {
Expand Down Expand Up @@ -55,12 +57,18 @@ const randomBgColor = () => {
const createDom = () => {
let __count = 1;
let shuffleResult = _.shuffle(__stateFlatten);

__puzzle.style.width = 120 * __columnSize + "px";
__puzzle.style.height = 100 * __rowSize + "px";

_.forEach(__resultState, (arrRow, rowKey) => {
_.forEach(arrRow, (arrCol, colKey) => {
let state = shuffleResult[__count - 1];
let element = document.createElement("div");
element.classList.add("plz");
element.style.backgroundColor = randomBgColor();
element.style.top = 100 * rowKey + "px";
element.style.left = 120 * colKey + "px";
element.setAttribute("rowCol", rowKey + "-" + colKey);
element.setAttribute("initial", state);
element.innerHTML = _.indexOf(__stateFlatten, state) + 1 + " šŸ‰";
Expand Down Expand Up @@ -115,41 +123,49 @@ const moveTo = (where, who) => {
case "left":
el.style.left =
el.getBoundingClientRect().left +
el.getBoundingClientRect().width +
el.getBoundingClientRect().width -
__puzzle.getBoundingClientRect().left +
"px";
__pointer.style.left =
__pointer.getBoundingClientRect().left -
__pointer.getBoundingClientRect().width +
__pointer.getBoundingClientRect().width -
__puzzle.getBoundingClientRect().left +
"px";
break;
case "right":
el.style.left =
el.getBoundingClientRect().left -
el.getBoundingClientRect().width +
el.getBoundingClientRect().width -
__puzzle.getBoundingClientRect().left +
"px";
__pointer.style.left =
__pointer.getBoundingClientRect().left +
__pointer.getBoundingClientRect().width +
__pointer.getBoundingClientRect().width -
__puzzle.getBoundingClientRect().left +
"px";
break;
case "top":
el.style.top =
el.getBoundingClientRect().top +
el.getBoundingClientRect().height +
el.getBoundingClientRect().height -
__puzzle.getBoundingClientRect().top +
"px";
__pointer.style.top =
__pointer.getBoundingClientRect().top -
__pointer.getBoundingClientRect().height +
__pointer.getBoundingClientRect().height -
__puzzle.getBoundingClientRect().top +
"px";
break;
case "bottom":
el.style.top =
el.getBoundingClientRect().top -
el.getBoundingClientRect().height +
el.getBoundingClientRect().height -
__puzzle.getBoundingClientRect().top +
"px";
__pointer.style.top =
__pointer.getBoundingClientRect().top +
__pointer.getBoundingClientRect().height +
__pointer.getBoundingClientRect().height -
__puzzle.getBoundingClientRect().top +
"px";
break;
}
Expand Down Expand Up @@ -215,14 +231,15 @@ const setDirectionAttr = (attr, moveMark) => {
const isRandomG = () => {
if (_.isEqual(_.flatten(__resultState), _.uniq(_.flatten(__resultState)))) {
__stateFlatten = _.flattenDeep(__resultState);
// console.log("result šŸ”„ ", __resultState);
// console.log("result šŸ•µļøā€ā™€ļø ", __stateFlatten);
console.log("šŸ”„ ", __resultState);
console.log("šŸ•µļøā€ā™€ļø ", __stateFlatten);
createDom();
} else {
randomPuzzle();
}
};

// šŸŽ£
const isGameOver = () => {
let whatIsGameStatus = [];
for (i = 0; i < __rowSize; i++) {
Expand All @@ -237,12 +254,45 @@ const isGameOver = () => {
setTimeout(() => {
let isPlayAgain = confirm("You Made it !! šŸ˜ƒ . want to play again?");
if (isPlayAgain) {
__puzzle.innerHTML = "";
randomPuzzle();
} else {
return null;
}
}, 300);
}
// console.log(whatIsGameStatus);
};
randomPuzzle();

// šŸŽ²
const __puzzleGame = (row, col) => {
__rowSize = Number(row);
__columnSize = Number(col);
__puzzle.innerHTML = "";
randomPuzzle();
};
const onLoadGameStart = () => {
__puzzleGame(3, 3);
};
onLoadGameStart();

let btnALl = document.querySelectorAll(".control button");
btnALl.forEach(btn => {
btn.addEventListener("click", e => {
btnALl.forEach(btn => btn.classList.remove("active"));
e.target.classList.add("active");
switch (e.target.innerText.toLowerCase()) {
case "easy":
__puzzleGame(3, 3);
break;
case "medium":
__puzzleGame(3, 4);
break;
case "hard":
__puzzleGame(4, 4);
break;
case "harder":
__puzzleGame(4, 5);
break;
}
});
});
72 changes: 33 additions & 39 deletions assets/css/style.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,41 @@
@import url('https://fonts.googleapis.com/css?family=Ubuntu');
body {
margin: 0 auto;
width: 100vw;
height: 100vh;
font-family: 'Ubuntu', sans-serif;
}
.wrapper{
display: flex;
justify-content: center;
align-items: center;
align-content: center;
flex-direction: row;
height: 100%;
}
.control{
width: 20%;
margin-left: 30px;
}
.control button{
width: 160px;
padding: 15px 30px;
margin-bottom: 15px;
border: none;
border-radius: 3px;
background: #ff7f50cc;
color: #fff;
font-family: 'Ubuntu', sans-serif;
cursor: pointer;
font-size: 16px;
}
.control .active{
background: #4a3a3a;
}
.puzzle {
width: 360px;
height: 300px;
position: relative;
background: #fff;
box-shadow: 2px 2px 0px 3px;
box-shadow: 0px 0px 0px 6px;
}
.plz {
width: 120px;
Expand All @@ -20,42 +49,7 @@ body {
transition: 0.3s all;
color: #fff;
}
.plz:nth-child(1) {
top: 0;
left: 0;
}
.plz:nth-child(2) {
top: 0px;
left: 120px;
}
.plz:nth-child(3) {
top: 0px;
left: 240px;
}
.plz:nth-child(4) {
top: 100px;
left: 0px;
}
.plz:nth-child(5) {
top: 100px;
left: 120px;
}
.plz:nth-child(6) {
top: 100px;
left: 240px;
}
.plz:nth-child(7) {
top: 200px;
left: 0px;
}
.plz:nth-child(8) {
top: 200px;
left: 120px;
}
.plz:nth-child(9) {
top: 200px;
left: 240px;
}

.pointer {
background: #fff;
}
Expand Down
Binary file added assets/img/jigsaw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions assets/img/jigsaw.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions dist/app.241155b5.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/app.241155b5.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 7366f5c

Please sign in to comment.