-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
247 lines (246 loc) · 10.7 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<!DOCTYPE html>
<html>
<head>
<title>Puzzle Game</title>
<link rel="shortcut icon" href="icon.jpg" type="image/x-icon">
<meta content="#000000" name="theme-color" charset="UTF-8">
<meta name="description" content="A simple implementation of the classic mini-game Sliding Puzzle, using HTML5 DOM document elements and without using Canvas or third party libraries.">
<meta name="keywords" content="Puzzle, js, Open Source, HTML5, Sliding, web, base">
<meta name="author" content="Ankit Kumar">
<style>
body {
height: 100vh;
padding: 0;
display: grid;
align-content: center;
justify-content: center;background-color:#000000;
}
*{
font-family:Arial;
font-size:12px;
border-collapse:collapse;
border:none;
margin:0;
padding:0;
border-spacing:0px;
-webkit-touch-callout:none;
-webkit-user-select:none;
-khtml-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
user-select:none;
outline:none;
}
.input_text{
border:0;
font-family:Arial;
font-size:12px;
-webkit-appearance:none;
border-bottom:1px solid #c4cebb;
background-color:transparent;
cursor:text;
height:28px;
width:100%;
-webkit-touch-callout:text;-webkit-user-select:text;-khtml-user-select:text;-moz-user-select:text;-ms-user-select:text;user-select:text;
}
.button{border-radius:8px;width:100%;height:32px;background-color:#c4cebb;display:grid;align-content: center;justify-content: center;cursor:pointer;}
.button:hover{background-color:#dfebd5;}
.switch {
position:relative;
display:inline-block;
width:50px;
height:24px;
}
.switch input{opacity:0;width:0;height:0;}
.slider{
position:absolute;
cursor:pointer;
top:0;
left:0;
right:0;
bottom:0;
background-color:#c4cebb;
transition:.2s;
border-radius:12px;
}
.slider:before{
position:absolute;
content:"";
height:18px;
width:18px;
left:3px;
bottom:3px;
background-color:#fff;
transition:.2s;
border-radius:12px;
}
input:checked+.slider{background-color:#dfebd5;}
input:checked+.slider:before{transform:translateX(26px);}
</style>
</head>
<body>
<div id='fifteen'></div> <!--element "fifteen" in which the game will take place-->
<div style='position:fixed;top:0;left:0;box-shadow:0px 2px 24px rgba(110,95,165,0.25);border-radius:0 0 16px 0;background-color:#fff;width:196px;'>
<div style="display:none;position:fixed;"><img id="x" src=""/><a id="dwonload"></a><input id="img_file" type="file" accept="image/png,image/gif,image/jpeg,image/webp"/></div>
<div style="overflow:auto;width:180px;max-height:100vh;height:100%;padding:8px;">
<table style="border-collapse:collapse;" border="1">
<tbody>
<tr>
<td style="height:48px;" colspan="2"><div class="button" onclick="img_file.click();">Upload img file</div></td>
</tr>
<tr>
<td style="width:68px;height:34px;padding-right:8px;" align="right">Difficulty</td>
<td><input onchange="setup.puzzle_fifteen.diff=this.value;fifteen_update();" value="300" class="input_text" type="text"></td>
</tr>
<tr>
<td style="height:34px;padding-right:8px;" align="right">Width</td>
<td><input id="width" onchange="setup.puzzle_fifteen.size[0]=parseInt(this.value);fifteen_update();" value="1024" class="input_text" type="text"></td>
</tr>
<tr>
<td style="height:34px;padding-right:8px;" align="right">Height</td>
<td><input id="height" onchange="setup.puzzle_fifteen.size[1]=parseInt(this.value);fifteen_update();" value="1281" class="input_text" type="text"></td>
</tr>
<tr>
<td style="height:34px;padding-right:8px;" align="right">Image fill</td>
<td align="center"><label class="switch">
<input type="checkbox" onchange="setup.puzzle_fifteen.art.ratio=this.checked;fifteen_update();">
<span class="slider round"></span>
</label></td>
</tr>
<tr>
<td style="height:34px;padding-right:8px;" align="right">Grid width</td>
<td><input id="grid_width" onchange="setup.puzzle_fifteen.grid[0]=parseInt(this.value);fifteen_update();" value="3" class="input_text" type="text"></td>
</tr>
<tr>
<td style="height:34px;padding-right:8px;" align="right">Grid height</td>
<td><input id="grid_height" onchange="setup.puzzle_fifteen.grid[1]=parseInt(this.value);fifteen_update();" value="4" class="input_text" type="text"></td>
</tr>
<tr>
<td style="height:34px;padding-right:8px;" align="right">Move time</td>
<td ><input onchange="setup.puzzle_fifteen.time=this.value;fifteen_update();" value="0.4" class="input_text" type="text"></td>
</tr>
<tr>
<td style="height:34px;padding-right:8px;" align="right">Numbers</td>
<td align="center"><label class="switch">
<input type="checkbox" onchange="setup.puzzle_fifteen.number=this.checked;fifteen_update();">
<span class="slider round"></span>
</label></td>
</tr>
<tr>
<td style="height:34px;padding-right:8px;" align="right">Puzzle fill</td>
<td align="center"><label class="switch">
<input type="checkbox" onchange="setup.puzzle_fifteen.fill=this.checked;if(!this.checked){window.removeEventListener('resize',fifteen_resize,true);f.style.transform='scale(1)'};fifteen_update();" checked>
<span class="slider round"></span>
</label></td>
</tr>
<tr>
<td style="height:34px;padding-right:8px;" align="right">Style blocks</td>
<td><input id="slot_style" onchange="setup.puzzle_fifteen.style=this.value;fifteen_update();" class="input_text" type="text"></td>
</tr>
<tr>
<td style="height:48px;" colspan="2"><div class="button" onclick="fifteen_update();">Refresh</div></td>
</tr>
<tr>
<td style="height:48px;" colspan="2" align="center"><a href='https://github.com/Xnkit69' target='_blank'><svg xmlns='http://www.w3.org/2000/svg' width='auto' height='38px' viewBox='0 0 256 256'><path d='M128,0C57,0 0,57 0,128c0,57 37,104 88,121 6,1 9,-3 9,-6 0,-3-0,-13-0,-24C64,225 56,212 53,204 52,201 45,189 40,186c-4,-2-11,-8-0,-8 10,-0 17,9 20,13 12,19 30,14 37,11 1,-8 4,-14 8,-17-28,-3-58,-14-58,-63 0,-14 5,-25 13,-34-1,-3-6,-16 1,-34 0,0 11,-3 35,13 10,-3 21,-4 32,-4 11,0 22,1 32,4 24,-17 35,-13 35,-13 7,18 3,31 1,34 8,9 13,20 13,34 0,49-30,60-58,63 5,4 9,12 9,24 0,17-0,31-0,35 0,3 2,7 9,6C219,232 256,184 256,128 256,57 199,0 128,0Z' fill='#000' /></svg></a></td>
</tr>
</tbody>
</table>
</div>
</div>
<script>
var setup={
puzzle_fifteen:{
diff:300, // number of movements of the slots for shuffling pictures
size:[512,640], // element size "fifteen" in pixels only
grid:[3,4], // the number of squares in the height and width of the picture
fill:true, // Stretching the area with the game to fit the element is recommended for fullscreen
number:false, // Slot sequence number
art:{
url:"x.jpg", // path to the picture (you can use any format of supported browsers, gif-animation of svg)
ratio:false // enlarge the picture in height or width
},
// optional elements
keyBoard:true, // Control using the keys on the keyboard
gamePad:true, // Control using the joystick on the Gamepad
time:0.1, // block move animation time
style:"background-color:#c4cebb;display:grid;justify-items:center;align-items:center;font-family:Arial;color:#fff;border-radius:12px;font-size:32px;" // style for puzzle square
}
}
slot_style.value=setup.puzzle_fifteen.style;
var img_file=document.getElementById('img_file'),img=document.getElementById("art"),file;
img_file.addEventListener('change',loadFiles);
function loadFiles(e){
file=img_file.files[0];
adden_file();
}
function adden_file(){
setup.puzzle_fifteen.art.url=window.URL.createObjectURL(file)
img.src=setup.puzzle_fifteen.art.url;
img.onload=function(){setup.puzzle_fifteen.size=[img.width,img.height];auto_grid();auto_style();fifteen_update();}
}
function auto_grid(){
var s=setup.puzzle_fifteen
if(s.size[1]<s.size[0]){s.grid=[Math.round(s.size[0]/(s.size[1]/4))-1,3]}
else{s.grid=[3,Math.round(s.size[1]/(s.size[0]/4))-1]}
grid_width.value=s.grid[0];
grid_height.value=s.grid[1];
width.value=s.size[0];
height.value=s.size[1];
}
function auto_style(){
var s=setup.puzzle_fifteen,v,i;
if(s.size[1]<s.size[0]){v=Math.round((s.size[0]/s.grid[0])/16)}
else{v=Math.round((s.size[1]/s.grid[1])/16)}
d=s.style.split(";");
for(i=0;i<d.length;i++){
if(d[i].includes("border-radius")){s.style=s.style.replace(d[i],"border-radius:"+Math.round(v*1.5)+"px")}
else if(d[i].includes("font-size")){s.style=s.style.replace(d[i],"font-size:"+(v*3)+"px")}
}slot_style.value=s.style;
}
function fifteen_update(){
f.innerHTML="";
ceation_slots();
}
function fifteen_build(){
var reader=new FileReader();
if(file){reader.readAsDataURL(file);}else{alert('Please upload a file with a picture')}
reader.onload=function(){setup.puzzle_fifteen.art.url=reader.result;gen_file();}
reader.onerror=function(error){alert('Error: '+error);}
function gen_file(){
var url="fifteen_puzzle.js";
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function(){
if(this.readyState==4&&this.status==200){
var html="data:text/json;charset=utf-8,"+encodeURIComponent("<!DOCTYPE html>\n<html>\n<head>\n<style>\n body{height:97vh;padding:0;display:grid;align-content:center;justify-content:center;}\n</style>\n</head>\n<body>\n<div id='fifteen'></div>\n<script>\n"+this.responseText.replace("setup.puzzle_fifteen",JSON.stringify(setup.puzzle_fifteen,null,'\t'))+"\n<\/script>\n<\/body>\n<\/html>");
var a=document.getElementById('dwonload');
a.setAttribute("href", html );
a.setAttribute("download","index.html");
a.click();
}
};
xmlhttp.open("GET",url,true);
xmlhttp.send();
xmlhttp.onerror=function(){if(this.status==0){alert('runetime not loaded');}}
}
}
var drop = {
init:function(){
if (window.File&&window.FileReader&&window.FileList&&window.Blob) {
window.addEventListener("dragover",function(e){
e.preventDefault();
e.stopPropagation();
});
window.addEventListener("drop",function(e){
e.preventDefault();
e.stopPropagation();
file=e.dataTransfer.files[0];
adden_file();
});
}
},
};
window.addEventListener("DOMContentLoaded", drop.init);
</script>
<script src="fifteen_puzzle.js"></script> <!--path to file engine-->
</body>
</html>