我有一個描述棋子的類。我爲董事會的所有類型的片斷,例如典當,皇后,敏銳等等... 我在麻煩班級中遇到麻煩我想轉換爲女王或其他有類的對象(當典當轉到第8行時然後轉換爲另一個)我該怎麼做?我可以動態地將一個類的實例轉換爲另一個類的實例嗎?
class Pawn:
def __init__(self ,x ,y):
self.x = x
self.y = y
def move(self ,unit=1):
if self.y ==7 :
self.y += 1
what = raw_input("queen/rook/knight/bishop/(Q,R,K,B)?")
# There is most be changed that may be convert to:
# Queen ,knight ,bishop ,rook
if self.y != 2 and unit == 2:
print ("not accesible!!")
elif self.y ==2 and unit == 2:
self.y += 2
elif unit == 1:
self.y += 1
else:
print("can`t move over there")