Projet 1 groupe 38
unknown
python
4 years ago
4.3 kB
11
Indexable
import gaming_tools as gt
import random
def create_player (player):
"""Create a new player
Parameters:
----------
player: (str)
Raises :
----------
ValueError: if the player exists
Notes :
----------
A new player has been created with an amount of 225 coins
"""
def display_player_profile(player):
"""Display player's profile
Parameters
-----------
player: player nickname
Returns
----------
result: player's profile is displayed with his money and a creature if he have one
Raises
---------
ValueError: if the player doesn't exists
"""
def display_creature_profile(creature):
"""Display creature's profile
Parameters
-------------
creature: creature name
Returns
-------------
result: creature profile is displayed with his hp, variety, strenght and name
Raises
-------------
ValueError: if the creature doesn't exist
"""
def capture_creature(player):
"""Get a creature by capturing it
Parameters
-----------
player: player name (str)
Return:
-----------
capture: the player either captures or not the creature (and gets its statistics if he does) (str)
Raises
-----------
ValueError: if the player doesn't exist
ValueError: if the player already has a creature
ValueError: if the player doesn't have enough credits
"""
def buy_creature(player, amount):
"""Get a creature by buying it
Parameters
-------------
player: player nickname (str)
amount: amount of money (int)
Return
-------------
result: the player get a creature and see his statistic (str)
Raises
-------------
ValueError: if the player doesn't exist
ValueError: if the player have already a creature
ValueError: if the player doesn't have enough money
"""
if gt.player_exists(player) == True:
if gt.has_creature(player) == False:
money = gt.get_player_money(player)
if money >= amount:
creature_name = gt.get_random_creature_name()
creature_variety = gt.get_random_creature_variety()
creature_life = random.randint(1, amount)
creature_strength = random.randint(1, amount)
gt.set_creature(player, creature_name, creature_variety, creature_strength, creature_life)
gt.set_player_money(player, money - amount)
print("Name :", creature_name,"\nVariety :", creature_variety, "\nStrength :", creature_strength, "\nLife :", creature_life)
else:
print("You don't have enough money !")
else:
print("You already have a creature.")
else:
print("The player doesn't exist.")
def sell(player, creature):
"""Sell his creature
Parameters
-------------
player: player nickname
creatur: creature name
Return
-------------
result: the player get an amount of money for selling his creature (int)
Raises
-------------
ValueError: if the player doesn't exist
ValueError: if the player don't have the creature
"""
if gt.player_exists(player) == False:
print("a")
def evolve_creature(player, creature):
"""Evolve his creature
Parameters
-----------
player: player name (str)
creature: creature name (str)
Return:
-----------
evolution: the player has its creature's strength and life upgraded or not
Raises
-----------
ValueError: if the player doesn't exist
ValueError: if the creature doesn't exist
ValueError: if strength is strictly negative
ValueError: if the player doesn't have enough credits
"""
def fight(player1, player2):
"""Battle between two players
Parameters
---------------
player1: player one (str)
player2: player two (str)
Return
---------------
result: the winner of the fight and the gain (str / int)
Raises
---------------
ValueError: if player1 or player2 doesn't have a creature
"""Editor is loading...