Python Projects for Beginners a ten-Week Bootcamp Approach to Python Programming



Download 2,61 Mb.
bet120/200
Sana20.06.2022
Hajmi2,61 Mb.
#681748
1   ...   116   117   118   119   120   121   122   123   ...   200
Bog'liq
Python Projects for Beginners A Ten Week Bootcamp Approach to Python

Final Design


As with all previous Friday projects, we need to create a final design that we can follow. This week is a little different, as we need to design our classes first as well. This will help us figure out what attributes and methods our classes need to have before we even begin programming. Sticking to this blueprint will improve the programming process. First, let’s think about what classes we need. In Blackjack, you have specific game rules, game actions, and the deck itself. Then we also need to consider that there is a player and a dealer playing the game. It seems that we need to create two classes, one for the game itself and one for the two players. You could argue that you need a separate class for the dealer and player; however, we are keeping this game design a bit simpler. Let’s think about what the Game class needs first:

  • Game Attributes

deck – holds all 52 cards to be used within the game suites – used to create deck, tuple of all four suits values – used to create deck, tuple of all card values

  • Game Methods

makeDeck – creates new 52-card deck when called pullCard – pops random card from deck and returns it
The Game class is mainly going to keep track of the deck that we’re playing with. We could certainly put all methods associated with the game inside of this class as well; however, I’d like to keep the classes simple for you to understand. If you’d like to refactor the game afterward, feel free to do so. Methods like checkWinner, checkBust, handleTurn, etc., could all be part of the Game class. For this lesson, we’re not going to worry about adding these methods to Game. Knowing what the Game class is going to handle is going to help us understand what our Player class needs. Let’s go ahead and plan out the attributes and methods for this class now:

  • Player Attributes hand – stores cards within player’s hand

name – string variable that stores name of the player or dealer

  • Player Methods

calcHand – returns the calculated total of points in hand showHand – prints out player’s hand in a nicely formatted statement addCard – takes in a card and adds it to the player’s hand
As we can see, the Player class will be keeping track of each player’s hand and any methods associated with altering the hand. Generally, you always want to put methods that alter an attribute within the same class that the attribute is stored. Now that we have a good idea of the attributes and methods needed for each class, we’ll follow this guideline to program the game.

Download 2,61 Mb.

Do'stlaringiz bilan baham:
1   ...   116   117   118   119   120   121   122   123   ...   200




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish