added some animation sketches to 5/10

This commit is contained in:
Oystein Kristoffer Tveit 2020-09-28 18:27:57 +02:00
parent ea53ad397b
commit e88553337e

View File

@ -49,7 +49,7 @@ class CardHandler:
self.cards = cards
self.printSeparator = printSep
self.aceValue = aceValue
def addCard(self, card):
self.cards.append(card)
@ -94,7 +94,7 @@ class CardHandler:
isRoomForExtraCard = terminalWidth % extendedCardWidth >= cardWidth
cardsPerLine = terminalWidth // extendedCardWidth + (1 if isRoomForExtraCard else 0)
self.printCards(cardsPerLine)
@ -117,25 +117,71 @@ class CardHandler:
}
return sum([values[card.num] for card in self.cards])
def animator(self):
while True:
frame = 1
yield frame
#
# ┌─────────┐
# │? │
# │ │
# │ │
# │ ? │
# │ │
# │ │
# │ ?│
# └─────────┘
#
#
# ┌────────┐
# │? │
# │ │
# │ │
# │ ? │
# │ │
# │ │
# │ ?│
# └────────┘
#
#
# ┌───────┐
# │? │
# │ │
# │ │
# │ ? │
# │ │
# │ │
# │ ?│
# └───────┘
#
class Blackjack:
def __init__(self):
self.handler = CardHandler([])
self.emptyHandler = CardHandler([emptyCard(), emptyCard()])
self.dealerHandler = CardHandler([])
self.reset()
def generateNewCard(self):
cardTypes = range(1,14)
cardColors = ['spade', 'heart', 'diamond', 'club']
return Card(random.choice(cardTypes), random.choice(cardColors))
def generateNewCards(self):
self.dealerCards = [ self.generateNewCard() for _ in range(2) ]
self.dealerHandler.cards = [ self.generateNewCard() for _ in range(2) ]
self.handler.cards = [ self.generateNewCard() for _ in range(2) ]
def determineAceValue(self):
if self.dealerHandler.cardSum <= 9:
self.handler.aceValue = 13
def reset(self):
self.generateNewCards()
self.determineAceValue()
def printCards(self):
self.handler.safePrintCards()
@ -152,7 +198,6 @@ class Blackjack:
input('Continue?')
self.handler.addCard(self.generateNewCard())
def loop(self):
while True:
self.update()
@ -160,4 +205,4 @@ class Blackjack:
if __name__ == "__main__":
game = Blackjack()
game.loop()
game.loop()