final corrections before submission

This commit is contained in:
Edoardo Vergerio
2026-09-06 17:42:44 +02:00
parent 268fda0a6b
commit f046d06e21
15 changed files with 487 additions and 248 deletions
+13 -34
View File
@@ -19,11 +19,8 @@ class Pokemon:
raise ValueError(f"{move} is not an available move.")
else:
self.moves_dict[move] = copy.deepcopy(gd.available_moves[move])
print(gd.available_moves[move]['PP'])
print("TYPE", type(gd.available_moves[move]))
self.curr_hp = self.baseStats['hp']
def _get_baseStats(self):
return self.baseStats
@@ -49,6 +46,7 @@ class Pokemon:
self.moves_dict[move] = gd.available_moves[move]
def _useMove(self, move, opponent):
win_flag = False
if move['PP'] > 0:
if random.random() < move['accuracy']:
if move['category'] == 'physical':
@@ -64,29 +62,32 @@ class Pokemon:
modifier = stability * effect * critical * luck
damage = math.floor((( 2 * self.level + 10) / 250 * (attack / defense) * move['power'] + 2) * modifier)
opponent.curr_hp -= damage
if opponent.curr_hp < 0:
if opponent.curr_hp < 0 or opponent.curr_hp == 0:
opponent.curr_hp = 0
win_flag = True
print(f"{opponent.name} has fainted!")
print(f"{self.name} used {move['name']} and dealt {damage} damage to {opponent.name}!")
print("CPU's Pokemon current HP: ", opponent.curr_hp)
move['PP'] = move['PP'] - 1
else:
print(f"{self.name}'s attack missed!")
move['PP'] = move['PP'] - 1
else:
print(f"{self.name} has no PP left for {move['name']}!")
pass
return win_flag
def useMove(self, move_name, opponent):
if move_name not in self.moves_dict:
raise ValueError(f"{self.name} does not know the move {move_name}.")
raise ValueError(f"{self.name} does not know the move {move_name}.")
else:
self._useMove(self.moves_dict[move_name], opponent)
return self._useMove(self.moves_dict[move_name], opponent)
def print_move(self,move):
print(f"Move: {self.moves_dict[move]['name']}")
print(f"Type: {self.moves_dict[move]['type']}")
print(f"Category: {self.moves_dict[move]['category']}")
#print(f"Type: {self.moves_dict[move]['type']}")
#print(f"Category: {self.moves_dict[move]['category']}")
print(f"Power: {self.moves_dict[move]['power']}")
print(f"Accuracy: {self.moves_dict[move]['accuracy']}")
#print(f"Accuracy: {self.moves_dict[move]['accuracy']}")
print(f"PP: {self.moves_dict[move]['PP']}")
def get_moves(self):
@@ -111,7 +112,7 @@ class Pokemon:
class Trainer:
def __init__(self, name, starter_name, items = {"potions": 0, "pokeball": 0}, is_CPU = False):
def __init__(self, name, starter_name, items = {}, is_CPU = False):
self.name = name
if is_CPU:
if starter_name not in gd.available_wild_pokemons:
@@ -171,28 +172,6 @@ class Trainer:
except ValueError as e:
raise e
def print_items(self):
print(f"1) Potions: {self.items['potions']}")
print(f"2) Pokeballs: {self.items['pokeball']}")
def use_item(self, item_name):
if item_name not in self.items:
raise ValueError(f"{item_name} is not an available item.")
else:
if self.items[item_name] > 0:
self.items[item_name] -= 1 #use the item
print(f"Used {item_name}. Remaining: {self.items[item_name]}")
if item_name == "potions":
self.active_pokemon.curr_hp += 20
if self.active_pokemon.curr_hp > self.active_pokemon.baseStats['hp']:
self.active_pokemon.curr_hp = self.active_pokemon.baseStats['hp']
print(f"{self.active_pokemon.name} has been healed by 20 HP!")
return False
elif item_name == "pokeball":
return True
else:
raise ValueError(f"You have no {item_name} left.")
def update_pokemon_list(self, pokemon):
pass
@@ -203,7 +182,7 @@ class Trainer:
print(f"Pokemon List: {[pok.name for pok in self.pokemon_list]}")
print("Active Pokemon info:")
self.active_pokemon.print_pokemon_info()
print("Detailed info of Pokemons in your list:")
print("Detailed info of Pokemons in the list:")
print("-"*30)
for pokemon in self.pokemon_list:
pokemon.print_pokemon_info()