forked from bunkat/wordfind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·137 lines (130 loc) · 4.62 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Word Find</title>
<link rel="stylesheet" type="text/css" href="wordfind.css">
</head>
<body>
<h1>WordFind.js by BunKat & Lucas-C</h1>
<div id="main" role="main">
<div id="puzzle"></div>
<textarea id="words">
Hope
Faith
Charity
Love
Patience
Temperance
Humility
Prayer
Repentance
</textarea>
<button id="copy">Copy Puzzle</button>
<fieldset id="controls">
<label for="allowed-missing-words">Allowed missing words :
<input id="allowed-missing-words" type="number" min="0" max="5" step="1" value="2">
</label>
<label for="max-grid-growth">Max grid growth :
<input id="max-grid-growth" type="number" min="0" max="5" step="1" value="3">
</label>
<label for="extra-letters">Extra letters :
<select id="extra-letters">
<option value="secret-word">form a secret word</option>
<option value="none">none, allow blanks</option>
<option value="secret-word-plus-blanks">form a secret word but allow for extra blanks</option>
<option value="random" selected>random</option>
</select>
</label>
<label for="secret-word">Secret word :
<input id="secret-word">
</label>
<button id="create-grid">Create grid</button>
<p id="result-message"></p>
<button id="solve">Solve Puzzle</button>
</fieldset>
</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="wordfind.js"></script>
<script type="text/javascript" src="wordfindgame.js"></script>
<script>
/* Example words setup */
[
/*'adorable',
'comique',
'curieuse',
'drole',
'engagee',
'enjouee',
'fidele',
'futee',
'radieuse',
'sensible',
'sincere',*/
'complice',
'creative',
'elegante',
'farceuse',
'joviale',
'motivee',
'ordonnee',
'prudente',
'sexy',
'tendre',
].map(word => WordFindGame.insertWordBefore($('#add-word').parent(), word));
// $('#secret-word').val('LAETITIA');
/* Init */
function recreate() {
$('#result-message').removeClass();
var fillBlanks, game;
if ($('#extra-letters').val() === 'none') {
fillBlanks = false;
} else if ($('#extra-letters').val().startsWith('secret-word')) {
fillBlanks = $('#secret-word').val();
}
try {
game = new WordFindGame('#puzzle', {
allowedMissingWords: +$('#allowed-missing-words').val(),
maxGridGrowth: +$('#max-grid-growth').val(),
fillBlanks: fillBlanks,
allowExtraBlanks: ['none', 'secret-word-plus-blanks'].includes($('#extra-letters').val()),
maxAttempts: 100,
});
} catch (error) {
$('#result-message').text(`😞 ${error}, try to specify less ones`).css({color: 'red'});
return;
}
wordfind.print(game);
if (window.game) {
var emptySquaresCount = WordFindGame.emptySquaresCount();
$('#result-message').text(`😃 ${emptySquaresCount ? 'but there are empty squares' : ''}`).css({color: ''});
}
window.game = game;
}
recreate();
/* Event listeners */
$('#extra-letters').change((evt) => $('#secret-word').prop('disabled', !evt.target.value.startsWith('secret-word')));
$('#add-word').click( () => WordFindGame.insertWordBefore($('#add-word').parent()));
$('#create-grid').click(recreate);
$('#solve').click(() => game.solve());
$('#copy').click(() => {
const rawPuzzle = $('#puzzle').text();
const side = Math.sqrt(rawPuzzle.length);
let puzzle = "";
for(let i = 0; i < rawPuzzle.length; i++) {
if (i % side === 0) {
puzzle += "\n";
}
puzzle += ' ';
puzzle += rawPuzzle[i].toUpperCase();
}
console.log(side);
console.log(puzzle);
// copy(puzzle);
navigator.clipboard.writeText(puzzle);
});
</script>
</body>
</html>