[Tutor] Dictionnaries in object

bob gailer bgailer at gmail.com
Thu Feb 24 22:59:08 CET 2011


Always reply-all so a copy goes to the list.

On 2/24/2011 2:20 PM, Christopher Brookes wrote:
> Oh yes, did'nt think about it. I love this solution Ty :) !
>
> BTW i add Character class, how can i add to it ONE power ?

Sorry I don't understand.
>
> class Character():
>     """ Classe du personnage, ses movements, attaques, geston de 
> l'expérience et du niveau"""
>     def 
> __init__(self,name,description,type,strenght,intelligence,agility,health,level):
> self.name <http://self.name> = name
>         self.description = description
>         self.type = type
>         self.strenght = strenght
>         self.intelligence = intelligence
>         self.agility = agility
>         self.health = health
>         self.level = level
>
>     def hit(self,target):
>         """ Calcule la puissance du coup et réduit la vie de la cible"""
>         target.health -=self.strenght  // care about it is  - =
>         print (self.name <http://self.name>, "hit",target.name 
> <http://target.name>, "for", self.strenght, "damage")
>
>
>
>
> Sorry, object is very new for me...
>
>
> 2011/2/24 bob gailer <bgailer at gmail.com <mailto:bgailer at gmail.com>>
>
>     On 2/24/2011 1:58 PM, Christopher Brookes wrote:
>
>         Hi,
>
>         I want to create some powers in my fight program.
>         I want to know if dictionnaries is the best solution to do it.
>
>         For now its look like this :
>
>
>         //French name and description, don't care about it ;)
>
>         power1= {}
>         power1['Name'] = 'Flammes infernales'
>         power1['Description'] = 'Embrase lenemi et le feu bruler'
>
>         power2= {}
>         power2['Name'] = 'Froid devorant'
>         power2['Description'] = 'Gele lenemi sur place'
>
>         powerAll= [power1,power2]
>
>         but if i want to create like 20 powers, it will be long no ?
>         is there any solution shorter (and better ?)
>
>     1 - define a Power class and create instances
>
>     class Power:
>      def __init__(self, name, desc):
>     self.name <http://self.name> = name
>        self.desc = desc
>
>     powerAll = [
>      Power('Flammes infernales' , 'Embrase lenemi et le feu bruler'),
>      Power('Froid devorant', 'Gele lenemi sur place')]
>
>     -- 
>     Bob Gailer
>     919-636-4239
>     Chapel Hill NC
>
>
>
>
> -- 
> Brookes Christopher.


-- 
Bob Gailer
919-636-4239
Chapel Hill NC

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110224/9a40dd2b/attachment.html>


More information about the Tutor mailing list