進入閉嘴實作階段
封裝內部資料,實作操作方法,尚未完成外部呼叫介面
from card import Deck,HandCards
from controller import select, choose, selectR, chooseR
class PlayerStat:
def __init__(self, hp, shell=None, deck=Deck()):
self.hp = hp
self.shell = shell
self.deck = deck
self.hands = HandCards()
self.discard = None
def hurt(self, val):
self.hp -= val
def heal(self, val):
self.hp += val
def shield(self, val):
self.shell = val
def disperse(self, val):
if self.shell:
self.shell = None if val > self.shell else self.shell-val
def seal(self):
self.hasCover = True
self.cover = "seal"
def defense(self):
self.hasCover = True
self.cover = "defense"
def refelect(self):
self.hasCover = True
self.cover = "refelect"
def empty_fort(self):
self.hasCover = True
self.cover = "empty_fort"
def dizzy(self):
self.dizzyToken = 2
# action
def deal(self):
idxSet, zid = selectR(self.hand)
selC = self.hand.pickup(idxSet) # Note: pick to match, pickup to deal
def draw(self, n=2):
if len(self.hand) + n > 5: # note: ensure 1 <= n <= 5 - len(self.hand)
n = 5 - len(self.hand)
drawC = self.deck.drawn(n)
self.hand.join(drawC)
def drawD(self, n=2):
if len(self.hand) + n > 6: # note: ensure 1 <= n <= 6 - len(self.hand)
n = 6 - len(self.hand)
drawC = HandCards(self.deck.drawn(n + 1))
idxSet = {chooseR(drawC)}
self.discard = drawC.pickup(idxSet)
self.hand.join(drawC)
def pickup(self,idxSet):
return self.hands.pickup(idxSet)
def addCards(self, crds):
self.deck.join(crds)
def showHands(self):
return self.hands