Original Post
Bit of background, I've been getting pretty into programming lately and think that I have a decent grasp on most programming concepts but have never actually put my skills to the test and made anything. I've decided that I want to make a text-only card game clone (WoW tcg) to test my skills. The game doesn't have to be completely functional, but I'd like to create a structure that would allow me to one day (if I feel like it) implement a rules system etc.
That means... cards can't just be names they need to be objects with attributes etc.
I'm pretty bad at design, but I figured that the best way to handle gameplay was to create a list for every zone (allyZone = [], deck = [], hand = [], graveyard = [] etc etc) and then interact with the cards via the different lists. If that's wrong... let me know but it's what I could think of.
Now my problem is interaction with the cards as objects in those zones, and figuring out how to design the card object in general.
[source lang="python"]class deck(object):
def __init__(self):
self.cards = []
from random import shuffle
shuffle(self.cards)
def shuffleDeck(self):
from random import shuffle
shuffle(self.cards)
def drawCard(self, hand):
d = self.cards
cardDrawn = d.pop(0)
hand.append(cardDrawn)
def viewLibrary(self):
for x in self.cards:
print x.name
def viewNumberOfCards(self, cardsToView):
for x in self.cards[:cardsToView]:
print x.name
class hand(object):
def __init__(self):
self.cards = []
def viewHand(self):
for x in self.cards:
print x.name
def playCard(self, card):
if card.type == "ally":
h = self.cards
cardToPlay = h.pop(card)
allyZone.append(cardToPlay)
class card(object):
def __init__(self, name, type):
self.name = name
self.type = type
[/source]
This barebones for sure, but you get the idea. Now obviously using a string for type in card.__init__ is a bad idea, but I'm not sure of a better way to do it and I'm not sure how I'm going to store the cardData (xml, just a python file, json i have zero clue).
Anyway my question for now is under hand.playCard(). When I try to use something like hand.playCard(hand.cards[0]) the compiler says that hand.playCard(card) needs to be an integer. I'm not sure how to get around that or what I'm supposed to use instead.
Any help would be awesome!
That means... cards can't just be names they need to be objects with attributes etc.
I'm pretty bad at design, but I figured that the best way to handle gameplay was to create a list for every zone (allyZone = [], deck = [], hand = [], graveyard = [] etc etc) and then interact with the cards via the different lists. If that's wrong... let me know but it's what I could think of.
Now my problem is interaction with the cards as objects in those zones, and figuring out how to design the card object in general.
[source lang="python"]class deck(object):
def __init__(self):
self.cards = []
from random import shuffle
shuffle(self.cards)
def shuffleDeck(self):
from random import shuffle
shuffle(self.cards)
def drawCard(self, hand):
d = self.cards
cardDrawn = d.pop(0)
hand.append(cardDrawn)
def viewLibrary(self):
for x in self.cards:
print x.name
def viewNumberOfCards(self, cardsToView):
for x in self.cards[:cardsToView]:
print x.name
class hand(object):
def __init__(self):
self.cards = []
def viewHand(self):
for x in self.cards:
print x.name
def playCard(self, card):
if card.type == "ally":
h = self.cards
cardToPlay = h.pop(card)
allyZone.append(cardToPlay)
class card(object):
def __init__(self, name, type):
self.name = name
self.type = type
[/source]
This barebones for sure, but you get the idea. Now obviously using a string for type in card.__init__ is a bad idea, but I'm not sure of a better way to do it and I'm not sure how I'm going to store the cardData (xml, just a python file, json i have zero clue).
Anyway my question for now is under hand.playCard(). When I try to use something like hand.playCard(hand.cards[0]) the compiler says that hand.playCard(card) needs to be an integer. I'm not sure how to get around that or what I'm supposed to use instead.
Any help would be awesome!