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<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
6 |
+
<title>Gioco dell'Impiccato</title>
|
7 |
+
<style>
|
8 |
+
* {
|
9 |
+
box-sizing: border-box;
|
10 |
+
touch-action: manipulation;
|
11 |
+
}
|
12 |
+
body {
|
13 |
+
font-family: 'Arial', sans-serif;
|
14 |
+
text-align: center;
|
15 |
+
margin: 0;
|
16 |
+
padding: 15px;
|
17 |
+
background-color: #f5f5f5;
|
18 |
+
line-height: 1.6;
|
19 |
+
}
|
20 |
+
h1 {
|
21 |
+
color: #333;
|
22 |
+
font-size: 1.5rem;
|
23 |
+
margin-bottom: 20px;
|
24 |
+
}
|
25 |
+
#game-container {
|
26 |
+
background-color: #fff;
|
27 |
+
padding: 20px;
|
28 |
+
border-radius: 10px;
|
29 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
30 |
+
max-width: 100%;
|
31 |
+
width: 100%;
|
32 |
+
margin: 0 auto;
|
33 |
+
}
|
34 |
+
#word-display {
|
35 |
+
font-size: 1.8rem;
|
36 |
+
margin-bottom: 20px;
|
37 |
+
font-weight: bold;
|
38 |
+
letter-spacing: 5px;
|
39 |
+
}
|
40 |
+
#word-entry, #guess-input-container {
|
41 |
+
display: flex;
|
42 |
+
flex-direction: column;
|
43 |
+
align-items: center;
|
44 |
+
gap: 10px;
|
45 |
+
margin-bottom: 20px;
|
46 |
+
}
|
47 |
+
#word-input, #guess-input {
|
48 |
+
width: 100%;
|
49 |
+
padding: 10px;
|
50 |
+
font-size: 16px;
|
51 |
+
border: 1px solid #ddd;
|
52 |
+
border-radius: 5px;
|
53 |
+
text-align: center;
|
54 |
+
}
|
55 |
+
#submit-word-btn, #submit-btn, #reset-btn {
|
56 |
+
width: 100%;
|
57 |
+
padding: 12px;
|
58 |
+
font-size: 16px;
|
59 |
+
cursor: pointer;
|
60 |
+
background-color: #4caf50;
|
61 |
+
color: #fff;
|
62 |
+
border: none;
|
63 |
+
border-radius: 5px;
|
64 |
+
transition: background-color 0.3s;
|
65 |
+
text-transform: uppercase;
|
66 |
+
font-weight: bold;
|
67 |
+
}
|
68 |
+
#submit-word-btn:active, #submit-btn:active, #reset-btn:active {
|
69 |
+
background-color: #45a049;
|
70 |
+
}
|
71 |
+
#result {
|
72 |
+
font-size: 1rem;
|
73 |
+
margin-top: 15px;
|
74 |
+
color: #e74c3c;
|
75 |
+
font-weight: bold;
|
76 |
+
}
|
77 |
+
label {
|
78 |
+
margin-bottom: 10px;
|
79 |
+
font-weight: bold;
|
80 |
+
}
|
81 |
+
@media (max-height: 600px) {
|
82 |
+
body {
|
83 |
+
padding: 10px;
|
84 |
+
}
|
85 |
+
h1 {
|
86 |
+
font-size: 1.2rem;
|
87 |
+
margin-bottom: 10px;
|
88 |
+
}
|
89 |
+
#game-container {
|
90 |
+
padding: 15px;
|
91 |
+
}
|
92 |
+
}
|
93 |
+
</style>
|
94 |
+
</head>
|
95 |
+
<body>
|
96 |
+
<h1>Benvenuto al Gioco dell'Impiccato!</h1>
|
97 |
+
|
98 |
+
<span id="myMessage" style="font-size: medium; white-space: pre;">Questo gioco lo potrai giocare solo in locale con un tuo amico e familiare</span>
|
99 |
+
|
100 |
+
<div id="game-container">
|
101 |
+
<div id="word-entry">
|
102 |
+
<label for="word-input">Inserisci una parola:</label>
|
103 |
+
<input type="password" id="word-input" autocomplete="off" autocorrect="off" autocapitalize="none" spellcheck="false">
|
104 |
+
<button id="submit-word-btn" onclick="startGame()">Inizia il gioco</button>
|
105 |
+
</div>
|
106 |
+
|
107 |
+
<div id="word-display"></div>
|
108 |
+
|
109 |
+
<div id="guess-input-container">
|
110 |
+
<label for="guess-input">Inserisci una lettera o la risposta completa:</label>
|
111 |
+
<input type="text" id="guess-input" autocomplete="off" autocorrect="off" autocapitalize="none" spellcheck="false">
|
112 |
+
<button id="submit-btn" onclick="checkGuess()">Indovina</button>
|
113 |
+
</div>
|
114 |
+
|
115 |
+
<div id="result"></div>
|
116 |
+
|
117 |
+
<button id="reset-btn" onclick="resetGame()">Ricomincia</button>
|
118 |
+
</div>
|
119 |
+
|
120 |
+
<div id="cast-section" style="margin-top: 20px;">
|
121 |
+
<button onclick="generateCastLink()">Genera Link per Visualizzare il Gioco</button>
|
122 |
+
<p id="cast-link"></p>
|
123 |
+
</div>
|
124 |
+
|
125 |
+
<script>
|
126 |
+
document.getElementById('word-input').addEventListener('keyup', function(event) {
|
127 |
+
if (event.key === 'Enter') {
|
128 |
+
startGame();
|
129 |
+
}
|
130 |
+
});
|
131 |
+
|
132 |
+
document.getElementById('guess-input').addEventListener('keyup', function(event) {
|
133 |
+
if (event.key === 'Enter') {
|
134 |
+
checkGuess();
|
135 |
+
}
|
136 |
+
});
|
137 |
+
|
138 |
+
var parolaDaIndovinare = '';
|
139 |
+
var lettereIndovinate = [];
|
140 |
+
var tentativiRimasti = 6;
|
141 |
+
|
142 |
+
function startGame() {
|
143 |
+
parolaDaIndovinare = document.getElementById('word-input').value.toUpperCase();
|
144 |
+
|
145 |
+
if (/^[a-zA-Z]+$/.test(parolaDaIndovinare) && parolaDaIndovinare.length > 0) {
|
146 |
+
lettereIndovinate = new Array(parolaDaIndovinare.length).fill('_');
|
147 |
+
displayWord();
|
148 |
+
document.getElementById('word-entry').style.display = 'none';
|
149 |
+
} else {
|
150 |
+
alert('Inserisci una parola valida (almeno un carattere).');
|
151 |
+
}
|
152 |
+
}
|
153 |
+
|
154 |
+
function displayWord() {
|
155 |
+
document.getElementById('word-display').innerHTML = lettereIndovinate.join(' ');
|
156 |
+
}
|
157 |
+
|
158 |
+
function checkGuess() {
|
159 |
+
var inputElement = document.getElementById('guess-input');
|
160 |
+
var guess = inputElement.value.toUpperCase();
|
161 |
+
|
162 |
+
inputElement.value = '';
|
163 |
+
|
164 |
+
if (guess.length > 1) {
|
165 |
+
if (guess === parolaDaIndovinare) {
|
166 |
+
lettereIndovinate = parolaDaIndovinare.split('');
|
167 |
+
displayWord();
|
168 |
+
document.getElementById('result').textContent = 'Complimenti! Hai indovinato la parola!';
|
169 |
+
disableGuessing();
|
170 |
+
} else {
|
171 |
+
tentativiRimasti -= 2;
|
172 |
+
updateGameStatus();
|
173 |
+
}
|
174 |
+
} else {
|
175 |
+
var letteraTrovata = false;
|
176 |
+
|
177 |
+
for (var i = 0; i < parolaDaIndovinare.length; i++) {
|
178 |
+
if (parolaDaIndovinare[i] === guess) {
|
179 |
+
lettereIndovinate[i] = guess;
|
180 |
+
letteraTrovata = true;
|
181 |
+
}
|
182 |
+
}
|
183 |
+
|
184 |
+
displayWord();
|
185 |
+
|
186 |
+
if (!letteraTrovata) {
|
187 |
+
tentativiRimasti--;
|
188 |
+
}
|
189 |
+
|
190 |
+
updateGameStatus();
|
191 |
+
}
|
192 |
+
}
|
193 |
+
|
194 |
+
function updateGameStatus() {
|
195 |
+
document.getElementById('result').textContent = tentativiRimasti > 0 ?
|
196 |
+
'Tentativi rimasti: ' + tentativiRimasti :
|
197 |
+
'Mi dispiace, hai esaurito i tentativi. La parola era: ' + parolaDaIndovinare;
|
198 |
+
|
199 |
+
if (lettereIndovinate.join('') === parolaDaIndovinare || tentativiRimasti <= 0) {
|
200 |
+
disableGuessing();
|
201 |
+
}
|
202 |
+
}
|
203 |
+
|
204 |
+
function disableGuessing() {
|
205 |
+
document.getElementById('guess-input').disabled = true;
|
206 |
+
document.getElementById('submit-btn').disabled = true;
|
207 |
+
}
|
208 |
+
|
209 |
+
function resetGame() {
|
210 |
+
parolaDaIndovinare = '';
|
211 |
+
lettereIndovinate = [];
|
212 |
+
tentativiRimasti = 6;
|
213 |
+
|
214 |
+
document.getElementById('word-entry').style.display = 'block';
|
215 |
+
document.getElementById('word-input').value = '';
|
216 |
+
document.getElementById('guess-input').disabled = false;
|
217 |
+
document.getElementById('submit-btn').disabled = false;
|
218 |
+
document.getElementById('word-display').innerHTML = '';
|
219 |
+
document.getElementById('result').textContent = '';
|
220 |
+
}
|
221 |
+
|
222 |
+
// Funzione per generare un link che può essere usato in una rete locale
|
223 |
+
function generateCastLink() {
|
224 |
+
var ipAddress = window.location.hostname; // Ottieni l'IP locale
|
225 |
+
var port = 8080; // Puoi cambiarlo con una porta disponibile
|
226 |
+
|
227 |
+
var link = 'http://' + ipAddress + ':' + port + '/index.html'; // Aggiungi il percorso del gioco
|
228 |
+
document.getElementById('cast-link').textContent = 'Link per visualizzare il gioco: ' + link;
|
229 |
+
}
|
230 |
+
</script>
|
231 |
+
</body>
|
232 |
+
</html>
|