onnix
March 23rd, 2009, 11:14 AM
Greetings
Here is a module for card game that i have been working on, it returns an __str__ error of None type, need some help:
# Modulo Cartas
class Carta(object):
""" Um baralho """
NUMERO = ["A", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "J", "Q", "K"]
NAIPE = ["e","p","c","o"]
def __init__(self, numero, naipe):
self.numero = numero
self.naipe = naipe
def __str__(self):
rep = ""
rep += self.numero + self.naipe
return rep
class Baralho(object):
"""Um conjunto de 52 cartas."""
def __init__(self):
self.baralho = []
def populate(self):
for num in Carta.NUMERO:
for naip in Carta.NAIPE:
self.baralho.append(Carta(num,naip))
def __str__(self):
if self.baralho:
rep = ""
for carta in self.baralho:
rep += str(carta)
else:
rep += "vazio"
def baralhar(self):
import random
random.shuffle(self.baralho)
def dar_carta(self, outra_mao, carta, x_dar = 1):
for i in x_dar:
outra_mao.append(carta)
def reunir_cartas(self):
for num in Carta.NUMERO:
for naip in Carta.NAIPE:
self.baralho += [num,naip]
random.shuffle(self.baralho)
class Mao(Baralho):
def __init__(self):
self.mao = []
def __str__(self):
if self.mao:
rep = ""
for carta in self.mao:
rep += str(carta)
else:
rep += "<Sem cartas em mao...>"
# Teste de modulo
carta1 = Carta("A","p")
print carta1
baralho1 = Baralho()
baralho1.populate()
print baralho1
Here is a module for card game that i have been working on, it returns an __str__ error of None type, need some help:
# Modulo Cartas
class Carta(object):
""" Um baralho """
NUMERO = ["A", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "J", "Q", "K"]
NAIPE = ["e","p","c","o"]
def __init__(self, numero, naipe):
self.numero = numero
self.naipe = naipe
def __str__(self):
rep = ""
rep += self.numero + self.naipe
return rep
class Baralho(object):
"""Um conjunto de 52 cartas."""
def __init__(self):
self.baralho = []
def populate(self):
for num in Carta.NUMERO:
for naip in Carta.NAIPE:
self.baralho.append(Carta(num,naip))
def __str__(self):
if self.baralho:
rep = ""
for carta in self.baralho:
rep += str(carta)
else:
rep += "vazio"
def baralhar(self):
import random
random.shuffle(self.baralho)
def dar_carta(self, outra_mao, carta, x_dar = 1):
for i in x_dar:
outra_mao.append(carta)
def reunir_cartas(self):
for num in Carta.NUMERO:
for naip in Carta.NAIPE:
self.baralho += [num,naip]
random.shuffle(self.baralho)
class Mao(Baralho):
def __init__(self):
self.mao = []
def __str__(self):
if self.mao:
rep = ""
for carta in self.mao:
rep += str(carta)
else:
rep += "<Sem cartas em mao...>"
# Teste de modulo
carta1 = Carta("A","p")
print carta1
baralho1 = Baralho()
baralho1.populate()
print baralho1