Author Dusty Phillips Reviewers



Download 2,95 Mb.
Pdf ko'rish
bet25/183
Sana20.07.2022
Hajmi2,95 Mb.
#831085
1   ...   21   22   23   24   25   26   27   28   ...   183
Bog'liq
python3-oop

[
 15 
]
For example, there are 32 chess pieces in our chess set, but there are only six different 
types of pieces (pawns, rooks, bishops, knights, king, and queen), each of which 
behaves differently when it is moved. All of these classes of piece have properties
such as color and the chess set they are part of, but they also have unique shapes 
when drawn on the chess board, and make different moves. Let's see how the six 
types of pieces can inherit from a 
Piece
class:
+chess_set: ChessSet
+color
+shape
+move(board)
+move(board)
+move(board)
+move(board)
+move(board)
+move(board)
+shape
+shape
+shape
+shape
+shape
Rook
Bishop
Piece
Pawn
Queen
King
Knight
The hollow arrows indicate that the individual classes of pieces inherit from the 
Piece
class. All the subtypes automatically have a 
chess_set
and 
color
attribute inherited 
from the base class. Each piece provides a different shape property (to be drawn on the 
screen when rendering the board), and a different 
move
method to move the piece to a 
new position on the board at each turn.
We actually know that all subclasses of the 
Piece
class need to have a 
move
method; 
otherwise, when the board tries to move the piece, it will get confused. It is possible 
that we would want to create a new version of the game of chess that has one 
additional piece (the wizard). Our current design allows us to design this piece 
without giving it a 
move
method. The board would then choke when it asked the 
piece to move itself.
We can implement this by creating a dummy move method on the 

Download 2,95 Mb.

Do'stlaringiz bilan baham:
1   ...   21   22   23   24   25   26   27   28   ...   183




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