Created
August 30, 2012 17:00
-
-
Save everblut/3533301 to your computer and use it in GitHub Desktop.
Chars.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2 | |
################################################################################################################# | |
# TODO # | |
# tecnicas dict(k:tupla)? (tecnica(costo,funcion) diccionario que saca tupla # | |
# Validaciones .:. # | |
# Necesita Indicadores reales y temporales, cuando el hp este bajo el limite. # | |
# Ejemplo: Vida max = 100, after damage = 80, use potion = efect !> 100 # | |
# # | |
################################################################################################################# | |
# # | |
# Stats: HP,MP,ATK,DEF,EXP,TECNICAS,NOMBRE # | |
# Nombres: vida,magia,ataque,defensa,experiencia,tecnicas,nombre # | |
# Se maneja por metodos getXXX() y setXXX() # | |
# # | |
################################################################################################################# | |
class Char(object): | |
def __init__(self,*status): | |
self.setVida(status[0]) | |
self.setMagia( status[1]) | |
self.setAtaque(status[2]) | |
self.setDefensa(status[3]) | |
self.setExperiencia(status[4]) | |
self.setTecnicas(status[5]) | |
self.setNombre(status[6]) | |
##Set Methods## | |
def setVida(self,vida): | |
self.__vida = vida | |
def setMagia(self,magia): | |
self.__magia = magia | |
def setAtaque(self,ataque): | |
self.__ataque = ataque | |
def setDefensa(self,defensa): | |
self.__defensa = defensa | |
def setExperiencia(self,experiencia): | |
self.__experiencia = experiencia | |
def setTecnicas(self,tecnicas): | |
self.__tecnicas = tecnicas | |
def setNombre(self,nombre): | |
self.__nombre = nombre | |
##Get Methods## | |
def getVida(self): | |
return self.__vida | |
def getMagia(self): | |
return self.__magia | |
def getAtaque(self): | |
return self.__ataque | |
def getDefensa(self): | |
return self.__defensa | |
def getExperiencia(self): | |
return self.__experiencia | |
def getTecnicas(self): | |
return self.__tecnicas | |
def getNombre(self): | |
return self.__nombre | |
##Property method ( encapsulacion) ## | |
vida = property(getVida,setVida) | |
magia = property(getMagia,setMagia) | |
ataque = property(getAtaque,setAtaque) | |
defensa = property(getDefensa,setDefensa) | |
experiencia = property(getExperiencia,setExperiencia) | |
tecnicas = property(getTecnicas,setTecnicas) | |
nombre = property(getNombre,setNombre) | |
def ataca(self): | |
print 'Se utiliza el ataque ATK= ', self.ataque | |
def usaTecnica(self,tecnica): | |
if (self.getMagia()-self.tecnicas[tecnica][0]) >= 0: | |
self.setMagia(self.getMagia()-self.tecnicas[tecnica][0]) | |
print 'se ha utilizado una tecnica: ',tecnica,' MP = ', self.magia | |
else: | |
print 'No se ha podido utilizar la tecnica: ',tecnica,' Magia insuficiente: '\ | |
,self.magia,' Requerida: ',self.tecnicas[tecnica][0] | |
def defiende(self): | |
print 'se ha defendido DEF = ',self.defensa | |
def recuperaVida(self): | |
self.setVida(self.getVida()+1) | |
print "recupera HP = ", self.vida | |
def recuperaMagia(self): | |
self.setMagia(self.getMagia()+1) | |
print "recupera MP = ", self.magia | |
class hilo(threading.Thread): | |
def __init__(self,dood): | |
threading.Thread.__init__(self) | |
self.dood = dood | |
def run(self): | |
for i in range(10): | |
self.dood.ataca() | |
self.dood.usaTecnica('skill') | |
self.dood.defiende() | |
self.dood.recuperaVida() | |
self.dood.recuperaMagia() | |
print "Nombre: ",self.dood.getNombre() | |
print '*'*30 | |
def main(): | |
uno = Char(400,300,10,10,0,{'skill':(20,lambda a="skill1": a)},"dood2") | |
dos = Char(100,100,20,20,0,{'skill':(20,lambda a="skill": a)},"dood") | |
char1 = hilo(uno) | |
char2 = hilo(dos) | |
char1.start() | |
char2.start() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment