IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Python Discussion :

how to create weapon


Sujet :

Python

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    ETUDIANT
    Inscrit en
    Septembre 2017
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : ETUDIANT
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Septembre 2017
    Messages : 17
    Par défaut how to create weapon
    hi, i have to create a " weapon " with damage, dps, range etc.. and this would change if the weapon got gem(s)


    here is my code:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    class Weapon(object):
        def __init__(self, speed, dmg_min, dmg_max, wrange):
            return
     
     
     
    class Sword(Weapon):
        def __init__(self, name='sword', speed=1, dmg_min=1, dmg_max=1, wrange=1, gems=[], gems_nb=0):
                super(Sword, self).__init__(speed, dmg_min, dmg_max, wrange)
                self.gems = gems
                self.gems_nb = gems_nb
                self.name = name
     
     
     
        def infos(self):
            print "Name = {}".format(self.name)
            print "Damage range = {}".format()
            print "Dps = {}".format()
            print "Nb gems = {}".format()
            print "Golden gem: {}".format(1)
     
     
    class Gem(object):
        def __init__(self):
            return
     
    excalibur = Sword('Excalibur', 10, 50, 120, 4)
    gold_gem = Gem("Golden gem", 100)
    excalibur.add_gem(gold_gem)
     
    excalibur.infos()
    the output should be :

    Name = Excalibur
    Dammage range = 50-120
    Dps = 1850
    Nb gems = 1
    Golden gem:
       +100 dmg, +0 speed, +0 range.

    Thanks for help

  2. #2
    Membre expérimenté Avatar de cervo
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2012
    Messages
    220
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2012
    Messages : 220
    Par défaut

    Hi buddy ! It would be great ifyour post was in french, many other could help. for now i dont understand your problem... because all you want is on your code

  3. #3
    Membre averti
    Homme Profil pro
    ETUDIANT
    Inscrit en
    Septembre 2017
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : ETUDIANT
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Septembre 2017
    Messages : 17
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    class Weapon(object):
        def __init__(self, name, speed, dmg_min, dmg_max, wrange):
            self.name = name
            self.speed = speed
            self.dmg_min = dmg_min
            self.dmg_max = dmg_max
            self.wrange = wrange
     
     
        def infos(self):
            print "Name = {}".format(self.name)
            print "Damage range = {}".format(self.wrange)
            print "Dps = {}".format((self.dmg_min + self.dmg_max) / 2 * self.speed)
            print "Nb gems = {}".format(self.gems_nb)
            print "Golden gem: {}".format(0)
     
     
    class Sword(Weapon):
        def __init__(self, name='sword', speed=None, dmg_min=None, dmg_max=None, wrange=None, gems=[], gems_nb=1):
                super(Sword, self).__init__(name, speed, dmg_min, dmg_max, wrange)
                self.gems = gems
                self.gems_nb = gems_nb
     
     
    class Gem(object):
        def __init__(self, name, gems):
            return
     
     
     
    excalibur = Sword('Excalibur', 10, 50, 120, "50-120")
    gold_gem = Gem("Golden gem", 100)
    excalibur.infos()
    # excalibur.add_gem(gold_gem)
    here is my new code
    it works well but my " excalibur " has one gem so dmg_min and dmg_max should be 150 / 220 instead of 50/120 ( one gem = +100 damage)
    any idea how to set that ?

  4. #4
    Membre prolifique
    Avatar de Sve@r
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Février 2006
    Messages
    12 831
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Février 2006
    Messages : 12 831
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par hayee Voir le message
    it works well but my " excalibur " has one gem so dmg_min and dmg_max should be 150 / 220 instead of 50/120 ( one gem = +100 damage)
    any idea how to set that ?
    Write a methode "chance_gem" in Weapon class
    Code python : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    class Weapon(object):
        def __init__(self, name, speed, dmg_min, dmg_max, wrange):
            self.name = name
            self.speed = speed
            self.dmg_min = dmg_min
            self.dmg_max = dmg_max
            self.wrange = wrange
     
     
        def infos(self):
            print "Name = {}".format(self.name)
            print "Damage range = {}".format(self.wrange)
            print "Dps = {}".format((self.dmg_min + self.dmg_max) / 2 * self.speed)
            print "Nb gems = {}".format(self.gems_nb)
            print "Golden gem: {}".format(0)
     
        def chance_gem(self, value):
            if random.choice(False, True): self.dmg_max+= value
     
     
    excalibur = Sword('Excalibur', 10, 50, 120, "50-120")
    excalibur.chance_gem(100)
    excalibur.infos()
    Mon Tutoriel sur la programmation «Python»
    Mon Tutoriel sur la programmation «Shell»
    Sinon il y en a pleins d'autres. N'oubliez pas non plus les différentes faq disponibles sur ce site
    Et on poste ses codes entre balises [code] et [/code]

  5. #5
    Membre averti
    Homme Profil pro
    ETUDIANT
    Inscrit en
    Septembre 2017
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : ETUDIANT
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Septembre 2017
    Messages : 17
    Par défaut
    thanks for your answer!
    now i have this error:

    File "ex03.py", line 38, in <module>
    excalibur.chance_gem(100)
    File "ex03", line 18, in chance_gem
    if random.choice(False, True):
    NameError: global name 'random' is not defined

  6. #6
    Membre expérimenté Avatar de cervo
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2012
    Messages
    220
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2012
    Messages : 220
    Par défaut

    buddy, you have to import library (module ) before using it.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    import random
     
    .... (post your code here)

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo