from model.Players import Player, Warrior from model.weapon import Weapon knife = Weapon('knife', 6) player1 = Player('Ben', 20, 3) player2 = Player('Rene', 15, 4) warrior = Warrior('Dark warrior', 30, 4) warrior.damage(4) print('warrior vie ', warrior.get_health(), 'armure ', warrior.get_points_armor()) print(player1.get_pseudo(), ' attacks ', player2.get_pseudo()) player1.attack_player(player2) print(player1.get_pseudo(), ' || ', player1.get_health(), ' points de vie') print(player2.get_pseudo(), ' || ', player2.get_health(), ' points de vie') print(player2.get_pseudo(), 'recupere', knife.get_name()) player2.set_weapon(knife) print(player2.get_pseudo(), ' || ', player2.set_weapon(knife)) print(player2.get_pseudo(), ' attacks ', player1.get_pseudo()) player2.attack_player(player1) print(player1.get_pseudo(), ' || ', player1.get_health(), ' points de vie') print(player2.get_pseudo(), ' || ', player2.get_health(), ' points de vie') # print(player1.get_pseudo()) # player1.damage(3) # print('Vous possedez désormais ', player1.get_health(), ' points de vie') # to check if the parent class is Player if issubclass(Warrior, Player):
def get_enemy_weapon_list() -> Tuple[List[Weapon], Dict[str, int]]: """深海棲艦の装備の一覧を取得する Returns ------- weapon_list[index] = 装備情報 weapon_url_dict[装備URL] = 装備ID """ # URLを読み取り、HTMLをパースする response = requests.get(ENEMY_WEAPON_DATA_URL) dom: lxml.html.HtmlElement = lxml.html.fromstring(response.text) # テーブルの各行を読み取り、装備データとしてweapon_dictに代入する weapon_list: List[Weapon] = [Weapon( id=0, name='', type=WeaponType.NONE, attack=0, torpedo=0, bomber=0, anti_air=0, anti_sub=0)] weapon_url_dict: Dict[str, int] = {} for tr_tag in dom.cssselect('table.wikitable tr'): # テーブルなので列毎にバラせる tr_tag: lxml.html.HtmlElement = tr_tag td_tag_list: List[lxml.html.HtmlElement] = tr_tag.cssselect('td') if len(td_tag_list) < 6: continue # 装備IDを読み取る weapon_id = int(td_tag_list[0].text) # 装備名を読み取る weapon_name = read_weapon_name(td_tag_list[2]) # 装備URLを読み取る weapon_url = td_tag_list[2].cssselect('a')[0].get('href', '') weapon_url_dict[weapon_url] = weapon_id # 装備種を読み取る raw_weapon_type = td_tag_list[3].text.strip() weapon_type = WEAPON_TYPE_DICT.get(raw_weapon_type, WeaponType.NONE) # 他のパラメーターを読み取る parameters = read_weapon_parameters(td_tag_list[4]) weapon_attack = parameters.get('Firepower', 0) weapon_torpedo = parameters.get('Torpedo', 0) weapon_bomber = parameters.get('Bombing', 0) weapon_antiair = parameters.get('AA', 0) weapon_anti_sub = parameters.get('ASW', 0) # 装備情報を作成し、代入する weapon = Weapon( id=weapon_id, name=weapon_name, type=weapon_type, attack=weapon_attack, torpedo=weapon_torpedo, bomber=weapon_bomber, anti_air=weapon_antiair, anti_sub=weapon_anti_sub) weapon_list.append(weapon) return weapon_list, weapon_url_dict
from model.player import Player,Warrior from model.weapon import Weapon # from model.batiment import Batiment,Immeuble,Magasin,Banque knife = Weapon("knife",4) player = Player(input("choisissez le nom du protagoniste: "),int(input("entrez ses points de vie: ")),int(input("entrez ses poin d'attaque (qui seront ajouté de +4 car le héro est equipé d'une arme): "))) player.set_weapon(knife) warrior = Warrior(input("choisissez le nom de l'antagoniste (qui sera invulnérable pendant les trois premier tour grace à son armure): "),int(input("entrez ses points de vie: ")),int(input("entrez ses poin d'attaque: "))) #------------------------------------------------------------------------------- i=1 while player.get_pv() > 0 and warrior.get_pv() > 0: print("_______________________________________________________________________") print("tour", i,":\n") i+=1 player.attack_player(warrior) print(player.get_pseudo(),"attaque",warrior.get_pseudo()) print("\nJoueur {} / pv: {} / attack: {} + {}".format(player.get_pseudo(),player.get_pv(),player.get_attack(),player.weapon.get_damage_amount() if player.has_weapon() else 0)) print("Joueur {} / pv: {} / attack: {} + {} / armor: {}".format(warrior.get_pseudo(),warrior.get_pv(),warrior.get_attack(),warrior.weapon.get_damage_amount() if warrior.has_weapon() else 0,warrior.get_armor_point())) #------------------------------------------------------------------------------- if player.get_pv() <= 0 or warrior.get_pv() <= 0: if player.get_pv() <= 0 : print('\n',warrior.get_pseudo(),"a gagné") elif warrior.get_pv() <= 0: print('\n',player.get_pseudo(),"a gagné") break print("_______________________________________________________________________")
from model.player import Player from model.weapon import Weapon knife = Weapon("Couteau", 3) # POur un objet, on crée une classe dans laquelle on ajoute des attributs # Un constructeur pour initialiser les caractéristique de chaque objet (__init__(self):) # Il faut des méthodes pour bien mouliner nos fonctions dans cette classe player1 = Player("Sekou", 20, 3) player1.damage(3) print("vous possedez désormais", player1.get_health(), "Point de vie") print("Pseudo:", player1.get_pseudo()) print("health: ", player1.get_health()) print("Attack: ", player1.get_attack()) #print("Bienvenue au joueur", player1.pseudo) player2 = Player("Aissata", 20, 5) #print("Bienvenue au joueur", player2.pseudo) player1.attack_player(player2) print(player1.get_pseudo(), "attaque", player2.get_pseudo()) print("Bienvenue au joueur", player1.get_pseudo(), "/ point de vie:", player1.get_health(), "/ Attack:", player1.get_attack()) print("Bienvenue au joueur", player2.get_pseudo(), "/ point de vie:", player2.get_health(), "/ Attack:", player2.get_attack()) #Corrigé TP from model.player import Player from model.weapon import Weapon
elif my_weapon == "Couteau": print( "Vous avez obtenu le Couteau, vos dégats seront augmentés de 3 points ! " ) break else: my_weapon = input( "VOUS DEVEZ CHOISIR ENTRE L'ARC OU LE COUTEAU !\n-> ") yes() from model.player import Player from model.weapon import Weapon knife = Weapon("Couteau", 3) bow = Weapon("Arc", 8) player1 = Player("Mansour", 20, 3, Player.set_weapon("")) player2 = Player("Bob", 100, 15, Player.set_weapon("")) player1.attack_player(player2) print(player1.get_pseudo(), "attaque", player2.get_pseudo()) print(player2.get_pseudo(), "vient de subir", player1.get_attack_value(), "dégats !", "\n#################################") player2.attack_player(player1) print(player2.get_pseudo(), "attaque", player1.get_pseudo()) print(player1.get_pseudo(), "vient de subir", player2.get_attack_value(), "dégats !", "\n#################################")
from model.player import Player from model.weapon import Weapon knife = Weapon("Couteau", 3) bow = Weapon("Arc", 8) player1 = Player("Mansour", 20, 3, Weapon.set_weapon()) player2 = Player("Bob", 100, 15, Weapon.set_weapon()) player1.attack_player(player2) print(player1.get_pseudo(), "attaque", player2.get_pseudo()) print(player2.get_pseudo(), "vient de subir", player1.get_attack_value(), "dégats !", "\n#################################") player2.attack_player(player1) print(player2.get_pseudo(), "attaque", player1.get_pseudo()) print(player1.get_pseudo(), "vient de subir", player2.get_attack_value(), "dégats !", "\n#################################") if player1.get_health() <= 0 : print("Vous êtes mort !", "\n#################################") else : print("Il reste à", player1.get_pseudo(), player1.get_health(), "PV", "\n#################################") if player2.get_health() <= 0 : print("Vous êtes mort !", "\n#################################") else : print("Il reste à", player2.get_pseudo(), player2.get_health(), "PV", "\n#################################")