3 ms·
If you look through the later items in the series, it seems to get more complex than this. In particular, a character can use either 0 or 1 weapons at a particu
by schoen 9y ago
If you look through the later items in the series, it seems to get more complex than this. In particular, a character can use either 0 or 1 weapons at a particular moment, and either class can also use the Dagger weapon. It's not that each character inherently only has, and uses, the only weapon appropriate to that character -- this would make things quite a bit simpler.
- bushin 9y agoWell, maybe someday Dotty will be a mainstream language... trait Weapon class Sword extends Weapon class Staff extends Weapon class Dagger extends Weapon trait Player { type T <: Weapon } class Wizard extends Player { type T = Dagger | Staff var weapon: T = null } class Warrior extends Player { type T = Dagger | Sword var weapon: T = new Sword }
- icebraining 9y agoclass Wizard extends Player { type T = Dagger | Staff var weapon: T = null } The billion-dollar mistake in a new language? What a waste.
- boubiyeah 9y agoYeah that freaking blows. They keep it for compatibility with java. It's not idiomatic code though, you would use an Option.
- icebraining 9y agoPython already is a mainstream language: class Weapon: pass class Sword(Weapon): pass class Staff(Weapon): pass class Dagger(Weapon): pass class Player: weapon: Weapon class Wizard(Player): weapon: Optional[Union[Dagger, Staff]] = None class Warrior(Player): weapon: Optional[Union[Dagger, Sword]] = Sword()