final corrections before submission
This commit is contained in:
+13
-34
@@ -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()
|
||||
|
||||
+17
-18
@@ -1,8 +1,5 @@
|
||||
import random
|
||||
import math
|
||||
|
||||
import game_data as gd
|
||||
|
||||
from core import Trainer
|
||||
|
||||
def Main():
|
||||
@@ -19,11 +16,11 @@ def Main():
|
||||
print(e)
|
||||
print("Please try again...")
|
||||
continue
|
||||
trainer.print_trainer_info()
|
||||
#trainer.print_trainer_info()
|
||||
|
||||
cpu_trainer = Trainer(name="CPU", starter_name=random.choice(gd.available_starter_names))
|
||||
cpu_trainer = Trainer(name="CPU", starter_name=random.choice(gd.available_wild_pokemon_names), is_CPU=True)
|
||||
print(f"CPU has chosen {cpu_trainer.get_active_pokemon().name} as their starter Pokemon!")
|
||||
cpu_trainer.print_trainer_info()
|
||||
#cpu_trainer.print_trainer_info()
|
||||
continue_playing = True
|
||||
while continue_playing:
|
||||
selected_pokemon_combat_flag = False
|
||||
@@ -42,7 +39,6 @@ def Main():
|
||||
print(f"Choose a move for {player_pokemon.name} to use against {cpu_trainer.get_active_pokemon().name}:\n", player_pokemon.get_moves())
|
||||
player_move_name = input("Choose:")
|
||||
try:
|
||||
#print the move selected by the player
|
||||
print("Your selected move: ")
|
||||
player_pokemon.checkout_move(player_move_name)
|
||||
selected_combat_move_flag = True
|
||||
@@ -50,21 +46,24 @@ def Main():
|
||||
print(e)
|
||||
print("Please try again...")
|
||||
|
||||
#make a combat
|
||||
#combat
|
||||
print('='*30)
|
||||
print("BATTLE RESULTS:")
|
||||
print("Your move:")
|
||||
player_pokemon.useMove(player_move_name, cpu_trainer.get_active_pokemon())
|
||||
player_pokemon.checkout_move(player_move_name)
|
||||
print('-'*30)
|
||||
print("CPU's pokemon")
|
||||
cpu_trainer.get_active_pokemon().print_pokemon_info()
|
||||
print('='*30)
|
||||
|
||||
print("Continue playing? (yes/no)")
|
||||
response = input().strip().lower()
|
||||
if response != "yes":
|
||||
opponent_fainted = player_pokemon.useMove(player_move_name, cpu_trainer.get_active_pokemon())
|
||||
#player_pokemon.checkout_move(player_move_name)
|
||||
#print('-'*30)
|
||||
#print("CPU's pokemon")
|
||||
#cpu_trainer.get_active_pokemon().print_pokemon_info()
|
||||
#print('='*30)
|
||||
if opponent_fainted:
|
||||
print("You won the battle!")
|
||||
continue_playing = False
|
||||
else:
|
||||
print("Continue playing? (yes/no)")
|
||||
response = input().strip().lower()
|
||||
if response != "yes":
|
||||
continue_playing = False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user