-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
index.html
executable file
·253 lines (253 loc) · 13.3 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
248
249
250
251
252
253
<!DOCTYPE html>
<html>
<head>
<title>Fifteen puzzle maker</title>
<link rel="shortcut icon" href="icon.jpg" type="image/x-icon">
<meta content="#c4cebb" name="theme-color" charset="UTF-8">
<meta name="description" content="A simple implementation of the classic mini-game Fifteen Sliding Puzzle, using HTML5 DOM document elements and without using Canvas or third party libraries.">
<meta name="keywords" content="15Puzzle, js, Open Source, HTML5, Sliding, web, base">
<meta name="author" content="Kirill Live">
<style>
body {
height: 100vh;
padding: 0;
display: grid;
align-content: center;
justify-content: center;background-color:#dfebd5;
}
*{
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="art" 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();">Load 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"><div class="button" onclick="fifteen_build();">Create HTML game</div></td>
</tr>
<tr><td style="height:16px;" colspan="2"></td></tr>
<tr>
<td style="height:48px;" colspan="2"><a href='https://www.patreon.com/kirill_live' target='_blank'><svg height='auto' width='100%' viewBox='0 0 1000 200' xmlns='http://www.w3.org/2000/svg'><path d='M310 129V72h19c7 0 12 1 15 4 4 2 5 6 5 11 0 3 0 5-2 7-1 3-3 4-6 5a13 13 0 0110 13c0 6-2 10-6 13-3 2-8 4-14 4zm10-26v18h11l7-2c2-2 3-4 3-7 0-6-3-9-9-9zm0-7h10l7-2c2-2 2-4 2-6 0-3 0-5-2-6l-8-2h-9zm58 34c-6 0-11-2-14-6-4-4-6-9-6-15v-1l2-12c2-3 4-6 7-7 3-2 6-3 10-3 6 0 10 2 13 5 4 4 5 9 5 16v4h-27c0 3 1 6 3 8s5 3 8 3c4 0 8-2 10-5l5 5-6 6zm-1-37c-3 0-5 1-6 3-2 2-3 5-3 8h18v-1c0-3-1-5-3-7-1-2-3-3-6-3zm43 29l6-2 2-5h9l-2 7-7 6-8 2c-6 0-11-2-14-6-4-4-5-9-5-16v-1c0-6 1-12 5-15 3-4 8-6 14-6 5 0 9 1 12 4s5 7 5 12h-9l-2-6-6-3c-3 0-6 2-7 4-2 2-3 5-3 10v1c0 5 1 8 3 11 1 2 4 3 7 3zm23-15c0-4 0-8 2-11s4-6 7-7c3-2 6-3 10-3 6 0 11 2 14 5 4 4 6 9 6 15v2c0 4-1 8-3 11-1 4-3 6-6 8s-7 3-11 3c-6 0-10-2-14-6s-5-10-5-16zm9 1c0 5 1 8 3 10 2 3 4 4 7 4s6-1 8-4c2-2 2-6 2-11 0-4 0-7-2-10-2-2-5-4-8-4s-5 2-7 4c-2 3-3 6-3 11zm47-21v4c3-3 7-5 12-5 6 0 10 2 12 6 3-4 7-6 13-6 5 0 8 1 10 4 3 2 4 6 4 11v28h-10v-28l-1-6-6-1-6 1-2 5v29h-10v-28c0-5-3-7-8-7-3 0-6 1-8 4v31h-9V87zm79 43c-6 0-11-2-15-6-3-4-5-9-5-15v-1l2-12c2-3 4-6 7-7 3-2 6-3 10-3 6 0 10 2 13 5 4 4 5 9 5 16v4h-28l4 8c2 2 5 3 8 3 4 0 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 45-46-20-46-45-46 M83 161V39h23v122z' fill='#000'/></svg></a></td>
</tr>
<tr>
<td style="height:48px;" colspan="2" align="center"><a href='https://github.com/Kirilllive/Fifteen_puzzle_maker' 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:"art.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>