2121
2222# Creazione degli sprite
2323harry_sprite = Actor ("harry" , (200 , 320 ))
24- voldy_sprite = Actor ("voldemort" , (600 , 150 ))
24+ voldy_sprite = Actor ("voldemort" , (600 , 100 ))
25+
26+ # Variabile per memorizzare chi ha vinto
27+ vincitore = None
2528
2629# --- Caricamento Dati ---
2730incantesimi_df = pl .read_csv (
@@ -61,7 +64,8 @@ def reset_gioco():
6164 messaggio , \
6265 descrizione , \
6366 attesa_input , \
64- gioco_attivo
67+ gioco_attivo , \
68+ vincitore
6569 punti_vita = {"Harry" : 100 , "Voldemort" : 100 }
6670 visualizzazione .Harry = 100
6771 visualizzazione .Voldemort = 100
@@ -71,12 +75,15 @@ def reset_gioco():
7175 gioco_attivo = True
7276 # Ripristina opacità
7377 harry_sprite .opacity = 255
78+ harry_sprite .pos = (200 , 320 )
7479 voldy_sprite .opacity = 255
80+ voldy_sprite .pos = (600 , 100 )
81+ vincitore = None
7582
7683
7784def esegui_mossa (nome_attaccante , nome_difensore , df_incantesimi , indice_incantesimo ):
7885 """Gestisce il calcolo dei danni, le cure e gli aggiornamenti grafici di una mossa."""
79- global messaggio , descrizione , gioco_attivo
86+ global messaggio , descrizione , gioco_attivo , vincitore
8087
8188 # Estrazione dati dal DataFrame
8289 danno = float (df_incantesimi [indice_incantesimo , "damage" ])
@@ -122,17 +129,7 @@ def esegui_mossa(nome_attaccante, nome_difensore, df_incantesimi, indice_incante
122129 # Controllo condizione di vittoria
123130 if punti_vita [nome_difensore ] <= 0 :
124131 gioco_attivo = False
125- messaggio = f"{ nome_difensore .upper ()} è esausto!"
126- descrizione = "Premi SPAZIO per ricominciare."
127-
128-
129- # Gestione Input e Turni
130-
131-
132- def on_key_down (key ):
133- """Rileva la pressione dei tasti, usato qui per il riavvio."""
134- if not gioco_attivo and key == keys .SPACE :
135- reset_gioco ()
132+ vincitore = nome_attaccante
136133
137134
138135def fase_voldemort ():
@@ -142,7 +139,7 @@ def fase_voldemort():
142139 return
143140
144141 opzioni = ottieni_opzioni ("Voldemort" )
145- indice = random .randint (1 , len (opzioni )) - 1
142+ indice = random .randint (0 , len (opzioni ) - 1 )
146143 esegui_mossa ("Voldemort" , "Harry" , opzioni , indice )
147144
148145 # Se Harry è ancora vivo, torna il suo turno dopo 3 secondi
@@ -177,34 +174,71 @@ def on_mouse_down(pos):
177174 clock .schedule_unique (fase_voldemort , 3.0 )
178175
179176
177+ def on_key_down (key ):
178+ """Gestisce il riavvio con SPAZIO."""
179+ if not gioco_attivo and key == keys .SPACE :
180+ reset_gioco ()
181+
182+
180183# Funzioni di Disegno
181184
182185
183186def draw ():
184187 """Disegna l'interfaccia di gioco ogni frame."""
185188 screen .clear ()
186189 # Disegno ambiente (Cielo e Prato)
187- screen .draw .filled_rect (Rect ((0 , 0 ), (800 , 400 )), (200 , 230 , 255 ))
188- screen .draw .filled_rect (Rect ((0 , 400 ), (800 , 200 )), (120 , 180 , 120 ))
190+ if gioco_attivo :
191+ screen .draw .filled_rect (Rect ((0 , 0 ), (800 , 400 )), (200 , 230 , 255 ))
192+ screen .draw .filled_rect (Rect ((0 , 400 ), (800 , 200 )), (120 , 180 , 120 ))
193+
194+ # Disegno personaggi
195+ voldy_sprite .draw ()
196+ harry_sprite .draw ()
189197
190- # Disegno personaggi
191- voldy_sprite . draw ( )
192- harry_sprite . draw ( )
198+ # Disegno barre della vita
199+ disegna_barra_stato ( "VOLDEMORT" , visualizzazione . Voldemort , 50 , 50 )
200+ disegna_barra_stato ( "HARRY" , visualizzazione . Harry , 450 , 250 )
193201
194- # Disegno barre della vita
195- disegna_barra_stato ( "VOLDEMORT" , visualizzazione . Voldemort , 50 , 50 )
196- disegna_barra_stato ( "HARRY" , visualizzazione . Harry , 450 , 250 )
202+ # Box dei Dialoghi / Menu (rettangolo scuro in basso)
203+ screen . draw . filled_rect ( Rect (( 10 , 410 ), ( 780 , 180 )), ( 50 , 50 , 60 ) )
204+ screen . draw . rect ( Rect (( 10 , 410 ), ( 780 , 180 )), "white" )
197205
198- # Box dei Dialoghi / Menu (rettangolo scuro in basso)
199- screen .draw .filled_rect (Rect ((10 , 410 ), (780 , 180 )), (50 , 50 , 60 ))
200- screen .draw .rect (Rect ((10 , 410 ), (780 , 180 )), "white" )
206+ if attesa_input :
207+ disegna_menu ()
208+ else :
209+ screen .draw .text (messaggio , (40 , 450 ), fontsize = 40 )
210+ screen .draw .text (descrizione , (40 , 510 ), fontsize = 30 , color = "lightgray" )
201211
202- # Mostra il menu se è il turno del giocatore, altrimenti mostra i messaggi log
203- if attesa_input and gioco_attivo :
204- disegna_menu_mosse ()
205212 else :
206- screen .draw .text (messaggio , (40 , 450 ), fontsize = 40 , color = "white" )
207- screen .draw .text (descrizione , (40 , 510 ), fontsize = 30 , color = "lightgray" )
213+ # Schermata Finale: qualcuno ha vinto
214+ if vincitore == "Harry" :
215+ screen .blit ("vittoria" , (0 , 0 ))
216+ screen .draw .text (
217+ "HARRY HA VINTO!" ,
218+ center = (WIDTH / 2 , 100 ),
219+ fontsize = 70 ,
220+ color = "white" ,
221+ shadow = (2 , 2 ),
222+ )
223+ harry_sprite .pos = (WIDTH / 2 , HEIGHT / 2 )
224+ harry_sprite .draw ()
225+ else :
226+ screen .blit ("sconfitta" , (0 , 0 ))
227+ screen .draw .text (
228+ "IL MALE HA PREVALSO..." ,
229+ center = (WIDTH / 2 , 100 ),
230+ fontsize = 60 ,
231+ color = "red" ,
232+ )
233+ voldy_sprite .pos = (WIDTH / 2 , HEIGHT / 2 )
234+ voldy_sprite .draw ()
235+
236+ screen .draw .text (
237+ "Premi SPAZIO per un nuovo duello" ,
238+ center = (WIDTH / 2 , HEIGHT - 50 ),
239+ fontsize = 40 ,
240+ color = "white" ,
241+ )
208242
209243
210244def disegna_barra_stato (nome , valore , x , y ):
@@ -224,7 +258,7 @@ def disegna_barra_stato(nome, valore, x, y):
224258 screen .draw .filled_rect (Rect ((x + 101 , y + 46 ), (larghezza_barra , 13 )), colore )
225259
226260
227- def disegna_menu_mosse ():
261+ def disegna_menu ():
228262 """Disegna le 4 opzioni di incantesimo cliccabili per Harry."""
229263 opzioni = ottieni_opzioni ("Harry" )[:4 ]
230264 for i in range (len (opzioni )):
@@ -235,5 +269,4 @@ def disegna_menu_mosse():
235269 )
236270
237271
238- # Avvio del gioco
239272pgzrun .go ()
0 commit comments