Skip to content

Commit 06f137b

Browse files
committed
traduzione in italiano
1 parent 6db8fca commit 06f137b

File tree

1 file changed

+98
-94
lines changed

1 file changed

+98
-94
lines changed

game11/harry_potter.py

Lines changed: 98 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,153 +1,157 @@
11
import random
22
import polars as pl
33
import pgzrun
4+
from pgzero.actor import Actor
45
from types import SimpleNamespace
56

67
WIDTH = 800
78
HEIGHT = 600
8-
TITLE = "Wizarding Duel: The Final Battle"
9+
TITLE = "La Battaglia Finale"
910

10-
# --- State ---
11-
hp = {"Harry": 100, "Voldemort": 100}
12-
display = SimpleNamespace(Harry=100, Voldemort=100)
11+
punti_vita = {"Harry": 100, "Voldemort": 100}
12+
visualizzazione = SimpleNamespace(Harry=100, Voldemort=100)
1313

14-
# Sprites (Ensure harry.png and voldemort.png are in the 'images' folder)
1514
harry_sprite = Actor('harry', (200, 320))
1615
voldy_sprite = Actor('voldemort', (600, 150))
1716

18-
message = "A wild VOLDEMORT appeared!"
19-
sub_message = "What will HARRY do?"
20-
waiting_for_input = True
21-
game_active = True
17+
messaggio = "VOLDEMORT è apparso!"
18+
descrizione = "Cosa farà HARRY?"
19+
attesa_input = True
20+
gioco_attivo = True
2221

23-
# --- Load Data ---
24-
spells_df = pl.read_csv(r"C:\Users\alema\Desktop\pythonbiella\LearningPythonWithGames\game11\spells.csv")
22+
# --- Caricamento Dati ---
23+
incantesimi_df = pl.read_csv(r"C:\Users\alema\Desktop\pythonbiella\LearningPythonWithGames\game11\spells.csv")
2524

26-
def get_options(character):
27-
return spells_df.filter(pl.col("character") == character)
25+
def ottieni_opzioni(personaggio):
26+
return incantesimi_df.filter(pl.col("character") == personaggio)
2827

29-
# --- Visual Effects ---
30-
31-
def flash_hurt(sprite):
32-
"""Blinks the sprite and shakes it slightly."""
33-
original_x = sprite.x
34-
# Quick shake
35-
animate(sprite, duration=0.1, x=original_x + 10, tween='bounce_end')
36-
# Blink
28+
def flash_danno(sprite):
29+
"""Fa lampeggiare lo sprite e lo scuote leggermente."""
30+
x_originale = sprite.x
31+
# Scossa rapida
32+
animate(sprite, duration=0.5, x=x_originale + 10, tween='bounce_end')
33+
# Lampeggio
3734
for i in range(3):
3835
clock.schedule_unique(lambda: setattr(sprite, 'opacity', 0), i * 0.2)
3936
clock.schedule_unique(lambda: setattr(sprite, 'opacity', 255), i * 0.2 + 0.1)
40-
# Reset position
41-
clock.schedule_unique(lambda: setattr(sprite, 'x', original_x), 0.3)
37+
# Ripristina posizione
38+
clock.schedule_unique(lambda: setattr(sprite, 'x', x_originale), 0.3)
4239

43-
# --- Logic Core ---
40+
# --- Logica di Gioco ---
4441

45-
def execute_move(attacker_name, defender_name, spell_df, spell_index):
46-
global message, sub_message, game_active
42+
def esegui_mossa(nome_attaccante, nome_difensore, df_incantesimi, indice_incantesimo):
43+
global messaggio, descrizione, gioco_attivo
44+
45+
danno = float(df_incantesimi[indice_incantesimo, "damage"])
46+
precisione = float(df_incantesimi[indice_incantesimo, "precision"])
47+
nome_incantesimo = df_incantesimi[indice_incantesimo, 'spell'].upper()
48+
49+
messaggio = f"{nome_attaccante.upper()} usa {nome_incantesimo}!"
4750

48-
dmg = float(spell_df[spell_index, "damage"])
49-
precision = float(spell_df[spell_index, "precision"])
50-
message = f"{attacker_name.upper()} used {spell_df[spell_index, 'spell'].upper()}!"
51-
a = random.random()
52-
spell_successful = a < precision
53-
print(a, precision)
54-
if spell_successful:
55-
if dmg < 0: # Healing
56-
amt = abs(dmg)
57-
hp[attacker_name] = min(100, hp[attacker_name] + amt)
58-
sub_message = f"It recovered {amt} HP!"
59-
animate(display, duration=0.6, **{attacker_name: hp[attacker_name]})
60-
else: # Attacking
61-
hp[defender_name] = max(0, hp[defender_name] - dmg)
62-
sub_message = f"It dealt {dmg} damage!"
63-
# Visual hurt effect
64-
target_sprite = voldy_sprite if defender_name == "Voldemort" else harry_sprite
65-
flash_hurt(target_sprite)
66-
animate(display, duration=0.6, **{defender_name: hp[defender_name]})
51+
probabilita = random.random()
52+
successo = probabilita < precisione
53+
54+
if successo:
55+
if danno < 0: # Cura
56+
quantita = abs(danno)
57+
punti_vita[nome_attaccante] = min(100, punti_vita[nome_attaccante] + quantita)
58+
descrizione = f"Ha recuperato {quantita} PV!"
59+
animate(visualizzazione, duration=0.6, **{nome_attaccante: punti_vita[nome_attaccante]})
60+
else: # Attacco
61+
punti_vita[nome_difensore] = max(0, punti_vita[nome_difensore] - danno)
62+
descrizione = f"Ha inflitto {danno} danni!"
63+
# Effetto visivo danno
64+
target_sprite = voldy_sprite if nome_difensore == "Voldemort" else harry_sprite
65+
flash_danno(target_sprite)
66+
animate(visualizzazione, duration=0.6, **{nome_difensore: punti_vita[nome_difensore]})
6767
else:
68-
sub_message = f"The spell did not work!"
68+
descrizione = f"L'incantesimo è fallito!"
6969

70-
if hp[defender_name] <= 0:
71-
game_active = False
72-
message = f"{defender_name.upper()} fainted!"
73-
sub_message = "The duel is over."
70+
if punti_vita[nome_difensore] <= 0:
71+
gioco_attivo = False
72+
messaggio = f"{nome_difensore.upper()} è esausto!"
73+
descrizione = "Il duello è terminato."
7474

75-
# --- Turn Handlers ---
75+
# --- Gestione Turni ---
7676

77-
def voldemort_phase():
78-
"""Voldemort picks a random spell and casts it."""
79-
global message, sub_message
80-
if not game_active: return
77+
def fase_voldemort():
78+
"""Voldemort sceglie un incantesimo casuale e lo lancia."""
79+
global messaggio, descrizione
80+
if not gioco_attivo: return
8181

82-
options = get_options("Voldemort")
83-
spell_index = random.randint(1, len(options)) - 1
84-
execute_move("Voldemort", "Harry", options, spell_index)
82+
opzioni = ottieni_opzioni("Voldemort")
83+
indice = random.randint(1, len(opzioni)) - 1
84+
esegui_mossa("Voldemort", "Harry", opzioni, indice)
8585

86-
# After Voldemort moves, wait 2 seconds then let Harry play
87-
if game_active:
88-
clock.schedule_unique(ready_harry, 2.0)
86+
# Dopo la mossa di Voldemort, aspetta 2 secondi e passa a Harry
87+
if gioco_attivo:
88+
clock.schedule_unique(prepara_harry, 2.0)
8989

90-
def ready_harry():
91-
"""Resets the UI so Harry can choose a spell."""
92-
global message, sub_message, waiting_for_input
93-
message = "What will HARRY do?"
94-
sub_message = "Select a spell..."
95-
waiting_for_input = True
90+
def prepara_harry():
91+
"""Ripristina l'interfaccia per il turno di Harry."""
92+
global messaggio, descrizione, attesa_input
93+
messaggio = "Cosa farà HARRY?"
94+
descrizione = "Scegli un incantesimo..."
95+
attesa_input = True
9696

9797
def on_mouse_down(pos):
98-
global waiting_for_input
98+
global attesa_input
9999

100-
if game_active and waiting_for_input:
101-
options = get_options("Harry")[:4]
102-
for i in range(len(options)):
100+
if gioco_attivo and attesa_input:
101+
opzioni = ottieni_opzioni("Harry")[:4]
102+
for i in range(len(opzioni)):
103103
x = 40 + (i % 2) * 380
104104
y = 440 + (i // 2) * 60
105105
if Rect((x, y), (350, 50)).collidepoint(pos):
106-
# Harry's action
107-
waiting_for_input = False
108-
execute_move("Harry", "Voldemort", options, i)
106+
# Azione di Harry
107+
attesa_input = False
108+
esegui_mossa("Harry", "Voldemort", opzioni, i)
109109

110-
# If Voldemort is still alive, he takes his turn in 2 seconds
111-
if game_active:
112-
clock.schedule_unique(voldemort_phase, 2.0)
110+
# Se Voldemort è ancora vivo, tocca a lui tra 2 secondi
111+
if gioco_attivo:
112+
clock.schedule_unique(fase_voldemort, 2.0)
113113

114-
# --- Draw Functions ---
114+
# --- Funzioni di Disegno ---
115115

116116
def draw():
117117
screen.clear()
118+
# Sfondo Cielo e Prato
118119
screen.draw.filled_rect(Rect((0, 0), (800, 400)), (200, 230, 255))
119120
screen.draw.filled_rect(Rect((0, 400), (800, 200)), (120, 180, 120))
120121

121122
voldy_sprite.draw()
122123
harry_sprite.draw()
123124

124-
draw_status_box("VOLDEMORT", display.Voldemort, 50, 50)
125-
draw_status_box("HARRY", display.Harry, 450, 250)
125+
disegna_barra_stato("VOLDEMORT", visualizzazione.Voldemort, 50, 50)
126+
disegna_barra_stato("HARRY", visualizzazione.Harry, 450, 250)
126127

127-
# Dialogue Box
128+
# Box dei Dialoghi
128129
screen.draw.filled_rect(Rect((10, 410), (780, 180)), (50, 50, 60))
129130
screen.draw.rect(Rect((10, 410), (780, 180)), "white")
130131

131-
if waiting_for_input and game_active:
132-
draw_move_menu()
132+
if attesa_input and gioco_attivo:
133+
disegna_menu_mosse()
133134
else:
134-
screen.draw.text(message, (40, 450), fontsize=40, color="white")
135-
screen.draw.text(sub_message, (40, 510), fontsize=30, color="lightgray")
135+
screen.draw.text(messaggio, (40, 450), fontsize=40, color="white")
136+
screen.draw.text(descrizione, (40, 510), fontsize=30, color="lightgray")
136137

137-
def draw_status_box(name, val, x, y):
138+
def disegna_barra_stato(nome, valore, x, y):
138139
screen.draw.filled_rect(Rect((x, y), (300, 80)), "white")
139140
screen.draw.rect(Rect((x, y), (300, 80)), "black")
140-
screen.draw.text(name, (x+20, y+15), color="black", fontsize=30)
141+
screen.draw.text(nome, (x+20, y+15), color="black", fontsize=30)
141142
screen.draw.rect(Rect((x+100, y+45), (160, 15)), "black")
142-
bw = (val / 100) * 158
143-
c = "green" if val > 50 else "orange" if val > 20 else "red"
144-
if bw > 0: screen.draw.filled_rect(Rect((x+101, y+46), (bw, 13)), c)
143+
144+
larghezza_barra = (valore / 100) * 158
145+
colore = "green" if valore > 50 else "orange" if valore > 20 else "red"
146+
147+
if larghezza_barra > 0:
148+
screen.draw.filled_rect(Rect((x+101, y+46), (larghezza_barra, 13)), colore)
145149

146-
def draw_move_menu():
147-
opts = get_options("Harry")[:4]
148-
for i in range(len(opts)):
150+
def disegna_menu_mosse():
151+
opzioni = ottieni_opzioni("Harry")[:4]
152+
for i in range(len(opzioni)):
149153
x, y = 40 + (i%2)*380, 440 + (i//2)*60
150154
screen.draw.rect(Rect((x, y), (350, 50)), "white")
151-
screen.draw.text(f"> {opts[i, 'spell'].upper()}", (x+20, y+15), fontsize=30)
155+
screen.draw.text(f"> {opzioni[i, 'spell'].upper()}", (x+20, y+15), fontsize=30)
152156

153157
pgzrun.go()

0 commit comments

Comments
 (0)