-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
210 lines (186 loc) · 9.16 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>J2Team Puzzle | ManualsRepo</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.15/tailwind.min.css"
crossorigin="anonymous" referrerpolicy="no-referrer" />
<style>
#game-board {
width: 300px;
height: 300px;
position: relative;
}
.tile {
border: 1px solid white;
height: 100px;
width: 100px;
font-size: 30px;
position: absolute;
transition: top 0.2s linear, left 0.2s linear;
background: url(https://bert0ne.github.io/Sliding-Puzzle-Game-Javascript/image.png);
color: transparent;
}
.tile:last-of-type {
background: none;
border: none;
}
</style>
</head>
<body>
<h1>J2Team</h1>
<div class="min-h-screen bg-gray-100 py-6 flex flex-col justify-center sm:py-12">
<div class="relative py-3 sm:max-w-xl sm:mx-auto">
<div
class="absolute inset-0 bg-gradient-to-r from-cyan-400 to-sky-500 shadow-lg transform -skew-y-6 sm:skew-y-0 sm:-rotate-6 sm:rounded-3xl">
</div>
<div class="relative px-4 py-10 bg-white shadow-lg sm:rounded-3xl sm:p-20">
<div class="max-w-md mx-auto">
<div>
<img src="https://i.imgur.com/gcLslvc.png" class="h-7 sm:h-8 inline" />
<span class="font-bold text-2xl">J2Team</span>
</div>
<div class="divide-y divide-gray-200">
<div class="py-8 text-base leading-6 space-y-4 text-gray-700 sm:text-lg sm:leading-7">
<p>An advanced online playground for Tailwind CSS, including support for things like:</p>
<section class="flex relative">
<div id="game-board">
<div class="tile">1</div>
<div class="tile">2</div>
<div class="tile">3</div>
<div class="tile">4</div>
<div class="tile">5</div>
<div class="tile">6</div>
<div class="tile">7</div>
<div class="tile">8</div>
<div class="tile"></div>
</div>
</section>
<ul class="list-disc space-y-2">
<li class="flex items-start">
<span class="h-6 flex items-center sm:h-7">
<svg class="flex-shrink-0 h-5 w-5 text-cyan-500" viewBox="0 0 20 20"
fill="currentColor">
<path fill-rule="evenodd"
d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z"
clip-rule="evenodd" />
</svg>
</span>
<p class="ml-2">
Customizing your
<code class="text-sm font-bold text-gray-900">tailwind.config.js</code> file
</p>
</li>
<li class="flex items-start">
<span class="h-6 flex items-center sm:h-7">
<svg class="flex-shrink-0 h-5 w-5 text-cyan-500" viewBox="0 0 20 20"
fill="currentColor">
<path fill-rule="evenodd"
d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z"
clip-rule="evenodd" />
</svg>
</span>
<p class="ml-2">
Extracting classes with
<code class="text-sm font-bold text-gray-900">@apply</code>
</p>
</li>
<li class="flex items-start">
<span class="h-6 flex items-center sm:h-7">
<svg class="flex-shrink-0 h-5 w-5 text-cyan-500" viewBox="0 0 20 20"
fill="currentColor">
<path fill-rule="evenodd"
d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z"
clip-rule="evenodd" />
</svg>
</span>
<p class="ml-2">Code completion with instant preview</p>
</li>
</ul>
<p>Perfect for learning how the framework works, prototyping a new idea, or creating a demo
to share online.</p>
</div>
<div class="pt-6 text-base leading-6 font-bold sm:text-lg sm:leading-7">
<p>Want to dig deeper into Tailwind?</p>
<p>
<a href="https://tailwindcss.com/docs" class="text-cyan-600 hover:text-cyan-700"> Read
the docs → </a>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
const gameTiles = document.querySelectorAll(".tile");
const gameBoard = document.querySelector("#game-board");
const gameState = [
[gameTiles[0], gameTiles[1], gameTiles[2]],
[gameTiles[3], gameTiles[4], gameTiles[5]],
[gameTiles[6], gameTiles[7], gameTiles[8]],
];
var helper = {
shuffle: (box, columns) => {
for (var i = columns.length; i >= 0; i--) {
box.appendChild(columns[Math.random() * i | 0]);
}
}
}
function render(gameBoard, gameState) {
var columns = [];
gameState.forEach((row, rowIndex) => {
row.forEach((column, columnIndex) => {
column.style.top = `${rowIndex * 100}px`;
column.style.left = `${columnIndex * 100}px`;
column.style[`background-position-y`] = `-${rowIndex * 100}px`;
column.style[`background-position-x`] = `-${columnIndex * 100}px`;
columns.push(column);
});
});
helper.shuffle(gameBoard, columns);
}
function moveElement(element1, element2) {
const tempTop = element1.style.top;
const tempLeft = element1.style.left;
element1.style.top = element2.style.top;
element1.style.left = element2.style.left;
element2.style.top = tempTop;
element2.style.left = tempLeft;
}
render(gameBoard, gameState);
gameBoard.addEventListener("click", (event) => {
const target = event.target;
let x, y;
gameState.forEach((row, rowIndex) => {
row.forEach((column, columnIndex) => {
if (column === target) {
x = rowIndex;
y = columnIndex;
}
});
});
let emptyX, emptyY;
gameState.forEach((row, rowIndex) => {
row.forEach((column, columnIndex) => {
if (column.innerText === "") {
emptyX = rowIndex;
emptyY = columnIndex;
}
});
});
if (
(y === emptyY && (x + 1 === emptyX || x - 1 === emptyX)) ||
(x === emptyX && (y + 1 === emptyY || y - 1 === emptyY))
) {
moveElement(gameState[x][y], gameState[emptyX][emptyY]);
const temp = gameState[x][y];
gameState[x][y] = gameState[emptyX][emptyY];
gameState[emptyX][emptyY] = temp;
}
});
</script>
</body>
</html>