public static Treasure CreateRandomTreasure() { Treasure treasure = null; treasure_type ty = GetRandomType(); switch (ty) { case treasure_type.AddNode: treasure = new AddNodeTreasure(); break; case treasure_type.SpeedUp: treasure = new SpeedUpTreasure(); break; case treasure_type.SpeedDown: treasure = new SpeedDownTreasure(); break; default: break; } return(treasure); }
//寶物的建構子,須由子類別用 :base() 呼叫,不然不會執行,沒有找到怎麼「強制」繼承者呼叫,但暫時不理會 //這裡設為public沒有關係,因為整個Treasure是abstract(看上面第七行程式碼),不能被用來直接建立實體 public Treasure() { node = GetRandomNode(); type = treasure_type.AddNode; }