Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,121 +1,12 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
|
4 |
-
|
5 |
-
def __init__(self, root):
|
6 |
-
self.root = root
|
7 |
-
self.root.title("Gioco dell'Impiccato")
|
8 |
-
self.root.geometry("400x400")
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
def create_widgets(self):
|
17 |
-
self.title_label = tk.Label(self.root, text="Benvenuto al Gioco dell'Impiccato!", font=("Arial", 16))
|
18 |
-
self.title_label.pack(pady=10)
|
19 |
-
|
20 |
-
self.instruction_label = tk.Label(self.root, text="Questo gioco lo potrai giocare solo in locale con un tuo amico e familiare", font=("Arial", 10))
|
21 |
-
self.instruction_label.pack(pady=5)
|
22 |
-
|
23 |
-
self.word_entry_label = tk.Label(self.root, text="Inserisci una parola:", font=("Arial", 12))
|
24 |
-
self.word_entry_label.pack(pady=10)
|
25 |
-
|
26 |
-
self.word_input = tk.Entry(self.root, font=("Arial", 14), show="*", width=20)
|
27 |
-
self.word_input.pack(pady=10)
|
28 |
-
|
29 |
-
self.start_button = tk.Button(self.root, text="Inizia il gioco", command=self.start_game, font=("Arial", 14), width=20)
|
30 |
-
self.start_button.pack(pady=10)
|
31 |
-
|
32 |
-
self.word_display = tk.Label(self.root, text="", font=("Arial", 20, "bold"))
|
33 |
-
self.word_display.pack(pady=20)
|
34 |
-
|
35 |
-
self.guess_label = tk.Label(self.root, text="Inserisci una lettera o la risposta completa:", font=("Arial", 12))
|
36 |
-
self.guess_label.pack(pady=10)
|
37 |
-
|
38 |
-
self.guess_input = tk.Entry(self.root, font=("Arial", 14), width=20)
|
39 |
-
self.guess_input.pack(pady=10)
|
40 |
-
|
41 |
-
self.guess_button = tk.Button(self.root, text="Indovina", command=self.check_guess, font=("Arial", 14), width=20)
|
42 |
-
self.guess_button.pack(pady=10)
|
43 |
-
|
44 |
-
self.result_label = tk.Label(self.root, text="", font=("Arial", 12), fg="red")
|
45 |
-
self.result_label.pack(pady=10)
|
46 |
-
|
47 |
-
self.reset_button = tk.Button(self.root, text="Ricomincia", command=self.reset_game, font=("Arial", 14), width=20)
|
48 |
-
self.reset_button.pack(pady=10)
|
49 |
-
|
50 |
-
def start_game(self):
|
51 |
-
word = self.word_input.get().strip().upper()
|
52 |
-
if word and word.isalpha():
|
53 |
-
self.word_to_guess = word
|
54 |
-
self.guessed_letters = ["_"] * len(word)
|
55 |
-
self.remaining_attempts = 6
|
56 |
-
self.update_word_display()
|
57 |
-
self.word_input.delete(0, tk.END)
|
58 |
-
else:
|
59 |
-
messagebox.showerror("Errore", "Inserisci una parola valida (almeno un carattere).")
|
60 |
-
|
61 |
-
def update_word_display(self):
|
62 |
-
self.word_display.config(text=" ".join(self.guessed_letters))
|
63 |
-
|
64 |
-
def check_guess(self):
|
65 |
-
guess = self.guess_input.get().strip().upper()
|
66 |
-
self.guess_input.delete(0, tk.END)
|
67 |
-
|
68 |
-
if len(guess) > 1:
|
69 |
-
if guess == self.word_to_guess:
|
70 |
-
self.guessed_letters = list(self.word_to_guess)
|
71 |
-
self.update_word_display()
|
72 |
-
self.result_label.config(text="Complimenti! Hai indovinato la parola!")
|
73 |
-
self.disable_guessing()
|
74 |
-
else:
|
75 |
-
self.remaining_attempts -= 2
|
76 |
-
self.update_game_status()
|
77 |
-
else:
|
78 |
-
letter_found = False
|
79 |
-
for i in range(len(self.word_to_guess)):
|
80 |
-
if self.word_to_guess[i] == guess:
|
81 |
-
self.guessed_letters[i] = guess
|
82 |
-
letter_found = True
|
83 |
-
self.update_word_display()
|
84 |
-
|
85 |
-
if not letter_found:
|
86 |
-
self.remaining_attempts -= 1
|
87 |
-
|
88 |
-
self.update_game_status()
|
89 |
-
|
90 |
-
def update_game_status(self):
|
91 |
-
if self.remaining_attempts > 0:
|
92 |
-
self.result_label.config(text=f"Tentativi rimasti: {self.remaining_attempts}")
|
93 |
-
else:
|
94 |
-
self.result_label.config(text=f"Mi dispiace, hai esaurito i tentativi. La parola era: {self.word_to_guess}")
|
95 |
-
self.disable_guessing()
|
96 |
-
|
97 |
-
if "".join(self.guessed_letters) == self.word_to_guess:
|
98 |
-
self.result_label.config(text="Complimenti! Hai indovinato la parola!")
|
99 |
-
self.disable_guessing()
|
100 |
-
|
101 |
-
def disable_guessing(self):
|
102 |
-
self.guess_input.config(state=tk.DISABLED)
|
103 |
-
self.guess_button.config(state=tk.DISABLED)
|
104 |
-
|
105 |
-
def reset_game(self):
|
106 |
-
self.word_to_guess = ""
|
107 |
-
self.guessed_letters = []
|
108 |
-
self.remaining_attempts = 6
|
109 |
-
self.word_display.config(text="")
|
110 |
-
self.result_label.config(text="")
|
111 |
-
self.guess_input.config(state=tk.NORMAL)
|
112 |
-
self.guess_button.config(state=tk.NORMAL)
|
113 |
-
self.word_input.delete(0, tk.END)
|
114 |
-
|
115 |
-
def main():
|
116 |
-
root = tk.Tk()
|
117 |
-
game = HangmanGame(root)
|
118 |
-
root.mainloop()
|
119 |
-
|
120 |
-
if __name__ == "__main__":
|
121 |
-
main()
|
|
|
1 |
+
from flask import Flask, send_file
|
2 |
+
import os
|
3 |
|
4 |
+
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
@app.route('/')
|
7 |
+
def home():
|
8 |
+
# Servire direttamente il file index.html dalla stessa cartella
|
9 |
+
return send_file(os.path.join(os.getcwd(), 'index.html'))
|
10 |
|
11 |
+
if __name__ == '__main__':
|
12 |
+
app.run(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|