2
我想模擬國際象棋遊戲。 爲此,我想製作一個抽象類,Piece
,它以玩家和位置爲參數。從這一點,我想擴大到其他類別,如Pawn
:將參數傳遞給特質
trait Piece(player: Int, pos: Pos) = {
def spaces(destination: Pos): List[Pos]
}
case class Pawn extends Piece = {
//some other code
}
不過,我覺得我不能將參數傳遞給一個特質,這樣trait Piece(player: Int, pos: Pos)
。
那麼我怎麼能有一個抽象類Piece
有字段?
使用抽象類,而不是一個特質 – Samar