[pyar] programa orientado a objetos

Mariano Giagante mariano.giagante en gmail.com
Lun Dic 31 01:03:53 ART 2012


Hola gente!

Este es mi primer programa en python.
Se trata de la simulacion de un combate entre 2 oponentes.
Me gustaria que lo miren y me digan si se puede hacer de una manera más
legible o correcta según el paradigma.
Gracias!

import random

class debug:
def __init__(self):
pass
 def show(self,var):
print var
a = raw_input('press')
return a

class fighter:
def __init__(self,name,dpr,ac):
self.name = name
self.hp = 100
self.dpr = dpr
self.ac = ac
print self.get_name(),'came to fight!'
 def get_name(self):
return self.name
 def print_stats(self):
"""HP es la vida, Damage el daño y Armor Class la defensa"""
print 'Stats:'
print 'Name:',self.name
print 'HP:',self.hp
print 'Damage:',self.dpr
print 'Armor Class:',self.ac,'\n'

def attack(self,target):
print self.name,'is attacking',target.get_name(),'!'
attack_roll = random.randint(1,101)
success = (attack_roll > target.get_ac())
return target.__defend(success,self.dpr,amount_of_players)
 def __perish(self,amount_of_players):
print self.name,'has perished'
amount_of_players -= 1
return amount_of_players
# Es necesario hacer dispose del objeto fighter?
 def __defend(self,success,damage,amount_of_players):
if success:
self.hp -= damage
print self.name,'took',damage,'damage'
if self.hp <= 0:
return self.__perish(amount_of_players)
else:
return amount_of_players
else:
print 'Missed!'
return amount_of_players
 def get_ac(self):
return self.ac

debbie = debug()

amount_of_players = 2
jugador1 = fighter('Mariano',25,50)
jugador1.print_stats()
jugador2 = fighter('Cristian',25,50)
jugador2.print_stats()
raw_input()

resume = True
while resume:
resume = (jugador1.attack(jugador2) > 1)
raw_input()
if resume:
resume = (jugador2.attack(jugador1) > 1)
raw_input()
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.python.org.ar/pipermail/pyar/attachments/20121231/c7afb9f4/attachment.html>


More information about the pyar mailing list